mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
The landlock fingerprint test assumes there's no version of the landlock API >3. Update the test assertion to allow for the current v4 and any future versions.
74 lines
1.5 KiB
Go
74 lines
1.5 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package fingerprint
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/nomad/ci"
|
|
"github.com/hashicorp/nomad/client/testutil"
|
|
"github.com/hashicorp/nomad/helper/testlog"
|
|
"github.com/shoenig/go-landlock"
|
|
"github.com/shoenig/test/must"
|
|
)
|
|
|
|
func TestLandlockFingerprint(t *testing.T) {
|
|
testutil.RequireLinux(t)
|
|
ci.Parallel(t)
|
|
|
|
version, err := landlock.Detect()
|
|
must.NoError(t, err)
|
|
|
|
logger := testlog.HCLogger(t)
|
|
f := NewLandlockFingerprint(logger)
|
|
|
|
var response FingerprintResponse
|
|
err = f.Fingerprint(nil, &response)
|
|
must.NoError(t, err)
|
|
|
|
result := response.Attributes[landlockKey]
|
|
switch version {
|
|
case 0:
|
|
must.Eq(t, "", result)
|
|
default:
|
|
must.Eq(t, fmt.Sprintf("v%d", version), result)
|
|
}
|
|
}
|
|
|
|
func TestLandlockFingerprint_absent(t *testing.T) {
|
|
ci.Parallel(t)
|
|
|
|
logger := testlog.HCLogger(t)
|
|
f := NewLandlockFingerprint(logger)
|
|
f.(*LandlockFingerprint).detector = func() (int, error) {
|
|
return 0, nil
|
|
}
|
|
|
|
var response FingerprintResponse
|
|
err := f.Fingerprint(nil, &response)
|
|
must.NoError(t, err)
|
|
|
|
_, exists := response.Attributes[landlockKey]
|
|
must.False(t, exists)
|
|
}
|
|
|
|
func TestLandlockFingerprint_error(t *testing.T) {
|
|
ci.Parallel(t)
|
|
|
|
logger := testlog.HCLogger(t)
|
|
f := NewLandlockFingerprint(logger)
|
|
f.(*LandlockFingerprint).detector = func() (int, error) {
|
|
return 0, errors.New("oops")
|
|
}
|
|
|
|
var response FingerprintResponse
|
|
err := f.Fingerprint(nil, &response)
|
|
must.NoError(t, err)
|
|
|
|
_, exists := response.Attributes[landlockKey]
|
|
must.False(t, exists)
|
|
}
|