mirror of
https://github.com/tailscale/tailscale.git
synced 2025-06-12 18:58:36 +00:00

Add mesh key support to derpprobe for probing derpers with verify set to true. Move MeshKey checking to central point for code reuse. Fix a bad error fmt msg. Fixes tailscale/corp#27294 Fixes tailscale/corp#25756 Signed-off-by: Mike O'Driscoll <mikeo@tailscale.com>
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package derp
|
|
|
|
import "testing"
|
|
|
|
func TestCheckMeshKey(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
input string
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "KeyOkay",
|
|
input: "f1ffafffffffffffffffffffffffffffffffffffffffffffffffff2ffffcfff6",
|
|
want: "f1ffafffffffffffffffffffffffffffffffffffffffffffffffff2ffffcfff6",
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "TrimKeyOkay",
|
|
input: " f1ffafffffffffffffffffffffffffffffffffffffffffffffffff2ffffcfff6 ",
|
|
want: "f1ffafffffffffffffffffffffffffffffffffffffffffffffffff2ffffcfff6",
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "NotAKey",
|
|
input: "zzthisisnotakey",
|
|
want: "",
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range testCases {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
k, err := CheckMeshKey(tt.input)
|
|
if err != nil && !tt.wantErr {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
if err == nil && tt.wantErr {
|
|
t.Errorf("expected error but got none")
|
|
}
|
|
if k != tt.want {
|
|
t.Errorf("got: %s doesn't match expected: %s", k, tt.want)
|
|
}
|
|
|
|
})
|
|
}
|
|
|
|
}
|