posture: add get serial support for Windows/Linux
This commit adds support for getting serial numbers from SMBIOS on Windows/Linux (and BSD) using go-smbios. Updates #5902 Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:

committed by
Kristoffer Dalby

parent
249edaa349
commit
9eedf86563
38
posture/serialnumber_notmacos_test.go
Normal file
38
posture/serialnumber_notmacos_test.go
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
// Build on Windows, Linux and *BSD
|
||||
|
||||
//go:build windows || (linux && !android) || freebsd || openbsd || dragonfly || netbsd
|
||||
|
||||
package posture
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/types/logger"
|
||||
)
|
||||
|
||||
func TestGetSerialNumberNotMac(t *testing.T) {
|
||||
// This test is intentionally skipped as it will
|
||||
// require root on Linux to get access to the serials.
|
||||
// The test case is intended for local testing.
|
||||
// Comment out skip for local testing.
|
||||
t.Skip()
|
||||
|
||||
sns, err := GetSerialNumbers(logger.Discard)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get serial number: %s", err)
|
||||
}
|
||||
|
||||
if len(sns) == 0 {
|
||||
t.Fatalf("expected at least one serial number, got %v", sns)
|
||||
}
|
||||
|
||||
if len(sns[0]) <= 0 {
|
||||
t.Errorf("expected a serial number with more than zero characters, got %s", sns[0])
|
||||
}
|
||||
|
||||
fmt.Printf("serials: %v\n", sns)
|
||||
}
|
Reference in New Issue
Block a user