mirror of
https://github.com/juanfont/headscale.git
synced 2025-01-31 14:51:23 +09:00
fixup CLI tests
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
2d4500f60f
commit
b93c0744a3
5 changed files with 72 additions and 68 deletions
|
@ -4,10 +4,10 @@ import (
|
|||
"fmt"
|
||||
|
||||
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||
"github.com/juanfont/headscale/hscontrol/types"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc/status"
|
||||
"tailscale.com/types/key"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -79,7 +79,7 @@ var createNodeCmd = &cobra.Command{
|
|||
)
|
||||
}
|
||||
|
||||
machineKey, err := cmd.Flags().GetString("key")
|
||||
registrationID, err := cmd.Flags().GetString("key")
|
||||
if err != nil {
|
||||
ErrorOutput(
|
||||
err,
|
||||
|
@ -88,8 +88,7 @@ var createNodeCmd = &cobra.Command{
|
|||
)
|
||||
}
|
||||
|
||||
var mkey key.MachinePublic
|
||||
err = mkey.UnmarshalText([]byte(machineKey))
|
||||
_, err = types.RegistrationIDFromString(registrationID)
|
||||
if err != nil {
|
||||
ErrorOutput(
|
||||
err,
|
||||
|
@ -108,7 +107,7 @@ var createNodeCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
request := &v1.DebugCreateNodeRequest{
|
||||
Key: machineKey,
|
||||
Key: registrationID,
|
||||
Name: name,
|
||||
User: user,
|
||||
Routes: routes,
|
||||
|
|
|
@ -122,7 +122,7 @@ var registerNodeCmd = &cobra.Command{
|
|||
defer cancel()
|
||||
defer conn.Close()
|
||||
|
||||
machineKey, err := cmd.Flags().GetString("key")
|
||||
registrationID, err := cmd.Flags().GetString("key")
|
||||
if err != nil {
|
||||
ErrorOutput(
|
||||
err,
|
||||
|
@ -132,7 +132,7 @@ var registerNodeCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
request := &v1.RegisterNodeRequest{
|
||||
Key: machineKey,
|
||||
Key: registrationID,
|
||||
User: user,
|
||||
}
|
||||
|
||||
|
|
|
@ -843,13 +843,12 @@ func (api headscaleV1APIServer) DebugCreateNode(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
nodeKey := key.NewNode()
|
||||
|
||||
newNode := types.RegisterNode{
|
||||
Node: types.Node{
|
||||
NodeKey: nodeKey.Public(),
|
||||
Hostname: request.GetName(),
|
||||
User: *user,
|
||||
NodeKey: key.NewNode().Public(),
|
||||
MachineKey: key.NewMachine().Public(),
|
||||
Hostname: request.GetName(),
|
||||
User: *user,
|
||||
|
||||
Expiry: &time.Time{},
|
||||
LastSeen: &time.Time{},
|
||||
|
|
|
@ -139,6 +139,14 @@ func NewRegistrationID() (RegistrationID, error) {
|
|||
return RegistrationID(rid), nil
|
||||
}
|
||||
|
||||
func MustRegistrationID() RegistrationID {
|
||||
rid, err := NewRegistrationID()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return rid
|
||||
}
|
||||
|
||||
func RegistrationIDFromString(str string) (RegistrationID, error) {
|
||||
if len(str) != RegistrationIDLength {
|
||||
return "", fmt.Errorf("registration ID must be %d characters long", RegistrationIDLength)
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||
"github.com/juanfont/headscale/hscontrol/policy"
|
||||
"github.com/juanfont/headscale/hscontrol/types"
|
||||
"github.com/juanfont/headscale/integration/hsic"
|
||||
"github.com/juanfont/headscale/integration/tsic"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -812,14 +813,14 @@ func TestNodeTagCommand(t *testing.T) {
|
|||
headscale, err := scenario.Headscale()
|
||||
assertNoErr(t, err)
|
||||
|
||||
machineKeys := []string{
|
||||
"mkey:9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe",
|
||||
"mkey:6abd00bb5fdda622db51387088c68e97e71ce58e7056aa54f592b6a8219d524c",
|
||||
regIDs := []string{
|
||||
types.MustRegistrationID().String(),
|
||||
types.MustRegistrationID().String(),
|
||||
}
|
||||
nodes := make([]*v1.Node, len(machineKeys))
|
||||
nodes := make([]*v1.Node, len(regIDs))
|
||||
assert.Nil(t, err)
|
||||
|
||||
for index, machineKey := range machineKeys {
|
||||
for index, regID := range regIDs {
|
||||
_, err := headscale.Execute(
|
||||
[]string{
|
||||
"headscale",
|
||||
|
@ -830,7 +831,7 @@ func TestNodeTagCommand(t *testing.T) {
|
|||
"--user",
|
||||
"user1",
|
||||
"--key",
|
||||
machineKey,
|
||||
regID,
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
|
@ -847,7 +848,7 @@ func TestNodeTagCommand(t *testing.T) {
|
|||
"user1",
|
||||
"register",
|
||||
"--key",
|
||||
machineKey,
|
||||
regID,
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
|
@ -857,7 +858,7 @@ func TestNodeTagCommand(t *testing.T) {
|
|||
|
||||
nodes[index] = &node
|
||||
}
|
||||
assert.Len(t, nodes, len(machineKeys))
|
||||
assert.Len(t, nodes, len(regIDs))
|
||||
|
||||
var node v1.Node
|
||||
err = executeAndUnmarshal(
|
||||
|
@ -889,7 +890,7 @@ func TestNodeTagCommand(t *testing.T) {
|
|||
assert.ErrorContains(t, err, "tag must start with the string 'tag:'")
|
||||
|
||||
// Test list all nodes after added seconds
|
||||
resultMachines := make([]*v1.Node, len(machineKeys))
|
||||
resultMachines := make([]*v1.Node, len(regIDs))
|
||||
err = executeAndUnmarshal(
|
||||
headscale,
|
||||
[]string{
|
||||
|
@ -1054,18 +1055,17 @@ func TestNodeCommand(t *testing.T) {
|
|||
headscale, err := scenario.Headscale()
|
||||
assertNoErr(t, err)
|
||||
|
||||
// Pregenerated machine keys
|
||||
machineKeys := []string{
|
||||
"mkey:9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe",
|
||||
"mkey:6abd00bb5fdda622db51387088c68e97e71ce58e7056aa54f592b6a8219d524c",
|
||||
"mkey:f08305b4ee4250b95a70f3b7504d048d75d899993c624a26d422c67af0422507",
|
||||
"mkey:8bc13285cee598acf76b1824a6f4490f7f2e3751b201e28aeb3b07fe81d5b4a1",
|
||||
"mkey:cf7b0fd05da556fdc3bab365787b506fd82d64a70745db70e00e86c1b1c03084",
|
||||
regIDs := []string{
|
||||
types.MustRegistrationID().String(),
|
||||
types.MustRegistrationID().String(),
|
||||
types.MustRegistrationID().String(),
|
||||
types.MustRegistrationID().String(),
|
||||
types.MustRegistrationID().String(),
|
||||
}
|
||||
nodes := make([]*v1.Node, len(machineKeys))
|
||||
nodes := make([]*v1.Node, len(regIDs))
|
||||
assert.Nil(t, err)
|
||||
|
||||
for index, machineKey := range machineKeys {
|
||||
for index, regID := range regIDs {
|
||||
_, err := headscale.Execute(
|
||||
[]string{
|
||||
"headscale",
|
||||
|
@ -1076,7 +1076,7 @@ func TestNodeCommand(t *testing.T) {
|
|||
"--user",
|
||||
"node-user",
|
||||
"--key",
|
||||
machineKey,
|
||||
regID,
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
|
@ -1093,7 +1093,7 @@ func TestNodeCommand(t *testing.T) {
|
|||
"node-user",
|
||||
"register",
|
||||
"--key",
|
||||
machineKey,
|
||||
regID,
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
|
@ -1104,7 +1104,7 @@ func TestNodeCommand(t *testing.T) {
|
|||
nodes[index] = &node
|
||||
}
|
||||
|
||||
assert.Len(t, nodes, len(machineKeys))
|
||||
assert.Len(t, nodes, len(regIDs))
|
||||
|
||||
// Test list all nodes after added seconds
|
||||
var listAll []v1.Node
|
||||
|
@ -1135,14 +1135,14 @@ func TestNodeCommand(t *testing.T) {
|
|||
assert.Equal(t, "node-4", listAll[3].GetName())
|
||||
assert.Equal(t, "node-5", listAll[4].GetName())
|
||||
|
||||
otherUserMachineKeys := []string{
|
||||
"mkey:b5b444774186d4217adcec407563a1223929465ee2c68a4da13af0d0185b4f8e",
|
||||
"mkey:dc721977ac7415aafa87f7d4574cbe07c6b171834a6d37375782bdc1fb6b3584",
|
||||
otherUserRegIDs := []string{
|
||||
types.MustRegistrationID().String(),
|
||||
types.MustRegistrationID().String(),
|
||||
}
|
||||
otherUserMachines := make([]*v1.Node, len(otherUserMachineKeys))
|
||||
otherUserMachines := make([]*v1.Node, len(otherUserRegIDs))
|
||||
assert.Nil(t, err)
|
||||
|
||||
for index, machineKey := range otherUserMachineKeys {
|
||||
for index, regID := range otherUserRegIDs {
|
||||
_, err := headscale.Execute(
|
||||
[]string{
|
||||
"headscale",
|
||||
|
@ -1153,7 +1153,7 @@ func TestNodeCommand(t *testing.T) {
|
|||
"--user",
|
||||
"other-user",
|
||||
"--key",
|
||||
machineKey,
|
||||
regID,
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
|
@ -1170,7 +1170,7 @@ func TestNodeCommand(t *testing.T) {
|
|||
"other-user",
|
||||
"register",
|
||||
"--key",
|
||||
machineKey,
|
||||
regID,
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
|
@ -1181,7 +1181,7 @@ func TestNodeCommand(t *testing.T) {
|
|||
otherUserMachines[index] = &node
|
||||
}
|
||||
|
||||
assert.Len(t, otherUserMachines, len(otherUserMachineKeys))
|
||||
assert.Len(t, otherUserMachines, len(otherUserRegIDs))
|
||||
|
||||
// Test list all nodes after added otherUser
|
||||
var listAllWithotherUser []v1.Node
|
||||
|
@ -1294,17 +1294,16 @@ func TestNodeExpireCommand(t *testing.T) {
|
|||
headscale, err := scenario.Headscale()
|
||||
assertNoErr(t, err)
|
||||
|
||||
// Pregenerated machine keys
|
||||
machineKeys := []string{
|
||||
"mkey:9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe",
|
||||
"mkey:6abd00bb5fdda622db51387088c68e97e71ce58e7056aa54f592b6a8219d524c",
|
||||
"mkey:f08305b4ee4250b95a70f3b7504d048d75d899993c624a26d422c67af0422507",
|
||||
"mkey:8bc13285cee598acf76b1824a6f4490f7f2e3751b201e28aeb3b07fe81d5b4a1",
|
||||
"mkey:cf7b0fd05da556fdc3bab365787b506fd82d64a70745db70e00e86c1b1c03084",
|
||||
regIDs := []string{
|
||||
types.MustRegistrationID().String(),
|
||||
types.MustRegistrationID().String(),
|
||||
types.MustRegistrationID().String(),
|
||||
types.MustRegistrationID().String(),
|
||||
types.MustRegistrationID().String(),
|
||||
}
|
||||
nodes := make([]*v1.Node, len(machineKeys))
|
||||
nodes := make([]*v1.Node, len(regIDs))
|
||||
|
||||
for index, machineKey := range machineKeys {
|
||||
for index, regID := range regIDs {
|
||||
_, err := headscale.Execute(
|
||||
[]string{
|
||||
"headscale",
|
||||
|
@ -1315,7 +1314,7 @@ func TestNodeExpireCommand(t *testing.T) {
|
|||
"--user",
|
||||
"node-expire-user",
|
||||
"--key",
|
||||
machineKey,
|
||||
regID,
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
|
@ -1332,7 +1331,7 @@ func TestNodeExpireCommand(t *testing.T) {
|
|||
"node-expire-user",
|
||||
"register",
|
||||
"--key",
|
||||
machineKey,
|
||||
regID,
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
|
@ -1343,7 +1342,7 @@ func TestNodeExpireCommand(t *testing.T) {
|
|||
nodes[index] = &node
|
||||
}
|
||||
|
||||
assert.Len(t, nodes, len(machineKeys))
|
||||
assert.Len(t, nodes, len(regIDs))
|
||||
|
||||
var listAll []v1.Node
|
||||
err = executeAndUnmarshal(
|
||||
|
@ -1421,18 +1420,17 @@ func TestNodeRenameCommand(t *testing.T) {
|
|||
headscale, err := scenario.Headscale()
|
||||
assertNoErr(t, err)
|
||||
|
||||
// Pregenerated machine keys
|
||||
machineKeys := []string{
|
||||
"mkey:cf7b0fd05da556fdc3bab365787b506fd82d64a70745db70e00e86c1b1c03084",
|
||||
"mkey:8bc13285cee598acf76b1824a6f4490f7f2e3751b201e28aeb3b07fe81d5b4a1",
|
||||
"mkey:f08305b4ee4250b95a70f3b7504d048d75d899993c624a26d422c67af0422507",
|
||||
"mkey:6abd00bb5fdda622db51387088c68e97e71ce58e7056aa54f592b6a8219d524c",
|
||||
"mkey:9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe",
|
||||
regIDs := []string{
|
||||
types.MustRegistrationID().String(),
|
||||
types.MustRegistrationID().String(),
|
||||
types.MustRegistrationID().String(),
|
||||
types.MustRegistrationID().String(),
|
||||
types.MustRegistrationID().String(),
|
||||
}
|
||||
nodes := make([]*v1.Node, len(machineKeys))
|
||||
nodes := make([]*v1.Node, len(regIDs))
|
||||
assert.Nil(t, err)
|
||||
|
||||
for index, machineKey := range machineKeys {
|
||||
for index, regID := range regIDs {
|
||||
_, err := headscale.Execute(
|
||||
[]string{
|
||||
"headscale",
|
||||
|
@ -1443,7 +1441,7 @@ func TestNodeRenameCommand(t *testing.T) {
|
|||
"--user",
|
||||
"node-rename-command",
|
||||
"--key",
|
||||
machineKey,
|
||||
regID,
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
|
@ -1460,7 +1458,7 @@ func TestNodeRenameCommand(t *testing.T) {
|
|||
"node-rename-command",
|
||||
"register",
|
||||
"--key",
|
||||
machineKey,
|
||||
regID,
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
|
@ -1471,7 +1469,7 @@ func TestNodeRenameCommand(t *testing.T) {
|
|||
nodes[index] = &node
|
||||
}
|
||||
|
||||
assert.Len(t, nodes, len(machineKeys))
|
||||
assert.Len(t, nodes, len(regIDs))
|
||||
|
||||
var listAll []v1.Node
|
||||
err = executeAndUnmarshal(
|
||||
|
@ -1589,7 +1587,7 @@ func TestNodeMoveCommand(t *testing.T) {
|
|||
assertNoErr(t, err)
|
||||
|
||||
// Randomly generated node key
|
||||
machineKey := "mkey:688411b767663479632d44140f08a9fde87383adc7cdeb518f62ce28a17ef0aa"
|
||||
regID := types.MustRegistrationID()
|
||||
|
||||
_, err = headscale.Execute(
|
||||
[]string{
|
||||
|
@ -1601,7 +1599,7 @@ func TestNodeMoveCommand(t *testing.T) {
|
|||
"--user",
|
||||
"old-user",
|
||||
"--key",
|
||||
machineKey,
|
||||
regID.String(),
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
|
@ -1618,7 +1616,7 @@ func TestNodeMoveCommand(t *testing.T) {
|
|||
"old-user",
|
||||
"register",
|
||||
"--key",
|
||||
machineKey,
|
||||
regID.String(),
|
||||
"--output",
|
||||
"json",
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue