mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-20 19:09:07 +01:00
Refactored integration tests
This commit is contained in:
parent
83b4389090
commit
851da9d674
@ -219,7 +219,7 @@ func TestACLHostsInNetMapTable(t *testing.T) {
|
|||||||
// Test to confirm that we can use user:80 from one user
|
// Test to confirm that we can use user:80 from one user
|
||||||
// This should make the node appear in the peer list, but
|
// This should make the node appear in the peer list, but
|
||||||
// disallow ping.
|
// disallow ping.
|
||||||
// This ACL will not allow user1 access its own machines.
|
// This ACL will not allow user1 access its own nodes.
|
||||||
// Reported: https://github.com/juanfont/headscale/issues/699
|
// Reported: https://github.com/juanfont/headscale/issues/699
|
||||||
func TestACLAllowUser80Dst(t *testing.T) {
|
func TestACLAllowUser80Dst(t *testing.T) {
|
||||||
IntegrationSkip(t)
|
IntegrationSkip(t)
|
||||||
@ -324,7 +324,7 @@ func TestACLDenyAllPort80(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test to confirm that we can use user:* from one user.
|
// Test to confirm that we can use user:* from one user.
|
||||||
// This ACL will not allow user1 access its own machines.
|
// This ACL will not allow user1 access its own nodes.
|
||||||
// Reported: https://github.com/juanfont/headscale/issues/699
|
// Reported: https://github.com/juanfont/headscale/issues/699
|
||||||
func TestACLAllowUserDst(t *testing.T) {
|
func TestACLAllowUserDst(t *testing.T) {
|
||||||
IntegrationSkip(t)
|
IntegrationSkip(t)
|
||||||
|
@ -16,7 +16,7 @@ type ControlServer interface {
|
|||||||
WaitForReady() error
|
WaitForReady() error
|
||||||
CreateUser(user string) error
|
CreateUser(user string) error
|
||||||
CreateAuthKey(user string, reusable bool, ephemeral bool) (*v1.PreAuthKey, error)
|
CreateAuthKey(user string, reusable bool, ephemeral bool) (*v1.PreAuthKey, error)
|
||||||
ListMachinesInUser(user string) ([]*v1.Machine, error)
|
ListNodesInUser(user string) ([]*v1.Node, error)
|
||||||
GetCert() []byte
|
GetCert() []byte
|
||||||
GetHostname() string
|
GetHostname() string
|
||||||
GetIP() string
|
GetIP() string
|
||||||
|
@ -266,18 +266,18 @@ func TestEphemeral(t *testing.T) {
|
|||||||
t.Logf("all clients logged out")
|
t.Logf("all clients logged out")
|
||||||
|
|
||||||
for userName := range spec {
|
for userName := range spec {
|
||||||
machines, err := headscale.ListMachinesInUser(userName)
|
nodes, err := headscale.ListNodesInUser(userName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().
|
log.Error().
|
||||||
Err(err).
|
Err(err).
|
||||||
Str("user", userName).
|
Str("user", userName).
|
||||||
Msg("Error listing machines in user")
|
Msg("Error listing nodes in user")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(machines) != 0 {
|
if len(nodes) != 0 {
|
||||||
t.Errorf("expected no machines, got %d in user %s", len(machines), userName)
|
t.Errorf("expected no nodes, got %d in user %s", len(nodes), userName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,8 +617,8 @@ func TestExpireNode(t *testing.T) {
|
|||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var machine v1.Machine
|
var node v1.Node
|
||||||
err = json.Unmarshal([]byte(result), &machine)
|
err = json.Unmarshal([]byte(result), &node)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
time.Sleep(30 * time.Second)
|
time.Sleep(30 * time.Second)
|
||||||
@ -634,10 +634,10 @@ func TestExpireNode(t *testing.T) {
|
|||||||
|
|
||||||
peerPublicKey := strings.TrimPrefix(peerStatus.PublicKey.String(), "nodekey:")
|
peerPublicKey := strings.TrimPrefix(peerStatus.PublicKey.String(), "nodekey:")
|
||||||
|
|
||||||
assert.NotEqual(t, machine.NodeKey, peerPublicKey)
|
assert.NotEqual(t, node.NodeKey, peerPublicKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
if client.Hostname() != machine.Name {
|
if client.Hostname() != node.Name {
|
||||||
// Assert that we have the original count - self - expired node
|
// Assert that we have the original count - self - expired node
|
||||||
assert.Len(t, status.Peers(), len(TailscaleVersions)-2)
|
assert.Len(t, status.Peers(), len(TailscaleVersions)-2)
|
||||||
}
|
}
|
||||||
|
@ -519,11 +519,11 @@ func (t *HeadscaleInContainer) CreateAuthKey(
|
|||||||
return &preAuthKey, nil
|
return &preAuthKey, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListMachinesInUser list the TailscaleClients (Machine, Headscale internal representation)
|
// ListNodesInUser list the TailscaleClients (Machine, Headscale internal representation)
|
||||||
// associated with a user.
|
// associated with a user.
|
||||||
func (t *HeadscaleInContainer) ListMachinesInUser(
|
func (t *HeadscaleInContainer) ListNodesInUser(
|
||||||
user string,
|
user string,
|
||||||
) ([]*v1.Machine, error) {
|
) ([]*v1.Node, error) {
|
||||||
command := []string{"headscale", "--user", user, "nodes", "list", "--output", "json"}
|
command := []string{"headscale", "--user", user, "nodes", "list", "--output", "json"}
|
||||||
|
|
||||||
result, _, err := dockertestutil.ExecuteCommand(
|
result, _, err := dockertestutil.ExecuteCommand(
|
||||||
@ -535,7 +535,7 @@ func (t *HeadscaleInContainer) ListMachinesInUser(
|
|||||||
return nil, fmt.Errorf("failed to execute list node command: %w", err)
|
return nil, fmt.Errorf("failed to execute list node command: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var nodes []*v1.Machine
|
var nodes []*v1.Node
|
||||||
err = json.Unmarshal([]byte(result), &nodes)
|
err = json.Unmarshal([]byte(result), &nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to unmarshal nodes: %w", err)
|
return nil, fmt.Errorf("failed to unmarshal nodes: %w", err)
|
||||||
|
@ -553,17 +553,17 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommandReusableEphemeral() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
|
func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
|
||||||
user, err := s.createUser("machine-user")
|
user, err := s.createUser("node-user")
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
machineKeys := []string{
|
nodeKeys := []string{
|
||||||
"nodekey:9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe",
|
"nodekey:9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe",
|
||||||
"nodekey:6abd00bb5fdda622db51387088c68e97e71ce58e7056aa54f592b6a8219d524c",
|
"nodekey:6abd00bb5fdda622db51387088c68e97e71ce58e7056aa54f592b6a8219d524c",
|
||||||
}
|
}
|
||||||
machines := make([]*v1.Machine, len(machineKeys))
|
nodes := make([]*v1.Node, len(nodeKeys))
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
for index, machineKey := range machineKeys {
|
for index, nodeKey := range nodeKeys {
|
||||||
_, _, err := ExecuteCommand(
|
_, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
[]string{
|
[]string{
|
||||||
@ -571,11 +571,11 @@ func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
|
|||||||
"debug",
|
"debug",
|
||||||
"create-node",
|
"create-node",
|
||||||
"--name",
|
"--name",
|
||||||
fmt.Sprintf("machine-%d", index+1),
|
fmt.Sprintf("node-%d", index+1),
|
||||||
"--user",
|
"--user",
|
||||||
user.Name,
|
user.Name,
|
||||||
"--key",
|
"--key",
|
||||||
machineKey,
|
nodeKey,
|
||||||
"--output",
|
"--output",
|
||||||
"json",
|
"json",
|
||||||
},
|
},
|
||||||
@ -583,7 +583,7 @@ func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
machineResult, _, err := ExecuteCommand(
|
nodeResult, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
[]string{
|
[]string{
|
||||||
"headscale",
|
"headscale",
|
||||||
@ -592,7 +592,7 @@ func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
|
|||||||
user.Name,
|
user.Name,
|
||||||
"register",
|
"register",
|
||||||
"--key",
|
"--key",
|
||||||
machineKey,
|
nodeKey,
|
||||||
"--output",
|
"--output",
|
||||||
"json",
|
"json",
|
||||||
},
|
},
|
||||||
@ -600,13 +600,13 @@ func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var machine v1.Machine
|
var node v1.Node
|
||||||
err = json.Unmarshal([]byte(machineResult), &machine)
|
err = json.Unmarshal([]byte(nodeResult), &node)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
machines[index] = &machine
|
nodes[index] = &node
|
||||||
}
|
}
|
||||||
assert.Len(s.T(), machines, len(machineKeys))
|
assert.Len(s.T(), nodes, len(nodeKeys))
|
||||||
|
|
||||||
addTagResult, _, err := ExecuteCommand(
|
addTagResult, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
@ -622,10 +622,10 @@ func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var machine v1.Machine
|
var node v1.Node
|
||||||
err = json.Unmarshal([]byte(addTagResult), &machine)
|
err = json.Unmarshal([]byte(addTagResult), &node)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
assert.Equal(s.T(), []string{"tag:test"}, machine.ForcedTags)
|
assert.Equal(s.T(), []string{"tag:test"}, node.ForcedTags)
|
||||||
|
|
||||||
// try to set a wrong tag and retrieve the error
|
// try to set a wrong tag and retrieve the error
|
||||||
wrongTagResult, _, err := ExecuteCommand(
|
wrongTagResult, _, err := ExecuteCommand(
|
||||||
@ -660,13 +660,13 @@ func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
|
|||||||
},
|
},
|
||||||
[]string{},
|
[]string{},
|
||||||
)
|
)
|
||||||
resultMachines := make([]*v1.Machine, len(machineKeys))
|
resultNodes := make([]*v1.Node, len(nodeKeys))
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
json.Unmarshal([]byte(listAllResult), &resultMachines)
|
json.Unmarshal([]byte(listAllResult), &resultNodes)
|
||||||
found := false
|
found := false
|
||||||
for _, machine := range resultMachines {
|
for _, node := range resultNodes {
|
||||||
if machine.ForcedTags != nil {
|
if node.ForcedTags != nil {
|
||||||
for _, tag := range machine.ForcedTags {
|
for _, tag := range node.ForcedTags {
|
||||||
if tag == "tag:test" {
|
if tag == "tag:test" {
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
@ -677,29 +677,29 @@ func (s *IntegrationCLITestSuite) TestNodeTagCommand() {
|
|||||||
s.T(),
|
s.T(),
|
||||||
true,
|
true,
|
||||||
found,
|
found,
|
||||||
"should find a machine with the tag 'tag:test' in the list of machines",
|
"should find a node with the tag 'tag:test' in the list of nodes",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
||||||
user, err := s.createUser("machine-user")
|
user, err := s.createUser("node-user")
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
secondUser, err := s.createUser("other-user")
|
secondUser, err := s.createUser("other-user")
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
// Randomly generated machine keys
|
// Randomly generated node keys
|
||||||
machineKeys := []string{
|
nodeKeys := []string{
|
||||||
"nodekey:9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe",
|
"nodekey:9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe",
|
||||||
"nodekey:6abd00bb5fdda622db51387088c68e97e71ce58e7056aa54f592b6a8219d524c",
|
"nodekey:6abd00bb5fdda622db51387088c68e97e71ce58e7056aa54f592b6a8219d524c",
|
||||||
"nodekey:f08305b4ee4250b95a70f3b7504d048d75d899993c624a26d422c67af0422507",
|
"nodekey:f08305b4ee4250b95a70f3b7504d048d75d899993c624a26d422c67af0422507",
|
||||||
"nodekey:8bc13285cee598acf76b1824a6f4490f7f2e3751b201e28aeb3b07fe81d5b4a1",
|
"nodekey:8bc13285cee598acf76b1824a6f4490f7f2e3751b201e28aeb3b07fe81d5b4a1",
|
||||||
"nodekey:cf7b0fd05da556fdc3bab365787b506fd82d64a70745db70e00e86c1b1c03084",
|
"nodekey:cf7b0fd05da556fdc3bab365787b506fd82d64a70745db70e00e86c1b1c03084",
|
||||||
}
|
}
|
||||||
machines := make([]*v1.Machine, len(machineKeys))
|
nodes := make([]*v1.Node, len(nodeKeys))
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
for index, machineKey := range machineKeys {
|
for index, nodeKey := range nodeKeys {
|
||||||
_, _, err := ExecuteCommand(
|
_, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
[]string{
|
[]string{
|
||||||
@ -707,11 +707,11 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
"debug",
|
"debug",
|
||||||
"create-node",
|
"create-node",
|
||||||
"--name",
|
"--name",
|
||||||
fmt.Sprintf("machine-%d", index+1),
|
fmt.Sprintf("node-%d", index+1),
|
||||||
"--user",
|
"--user",
|
||||||
user.Name,
|
user.Name,
|
||||||
"--key",
|
"--key",
|
||||||
machineKey,
|
nodeKey,
|
||||||
"--output",
|
"--output",
|
||||||
"json",
|
"json",
|
||||||
},
|
},
|
||||||
@ -719,7 +719,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
machineResult, _, err := ExecuteCommand(
|
nodeResult, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
[]string{
|
[]string{
|
||||||
"headscale",
|
"headscale",
|
||||||
@ -728,7 +728,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
user.Name,
|
user.Name,
|
||||||
"register",
|
"register",
|
||||||
"--key",
|
"--key",
|
||||||
machineKey,
|
nodeKey,
|
||||||
"--output",
|
"--output",
|
||||||
"json",
|
"json",
|
||||||
},
|
},
|
||||||
@ -736,14 +736,14 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var machine v1.Machine
|
var node v1.Node
|
||||||
err = json.Unmarshal([]byte(machineResult), &machine)
|
err = json.Unmarshal([]byte(nodeResult), &node)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
machines[index] = &machine
|
nodes[index] = &node
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Len(s.T(), machines, len(machineKeys))
|
assert.Len(s.T(), nodes, len(nodeKeys))
|
||||||
|
|
||||||
// Test list all nodes after added seconds
|
// Test list all nodes after added seconds
|
||||||
listAllResult, _, err := ExecuteCommand(
|
listAllResult, _, err := ExecuteCommand(
|
||||||
@ -759,7 +759,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var listAll []v1.Machine
|
var listAll []v1.Node
|
||||||
err = json.Unmarshal([]byte(listAllResult), &listAll)
|
err = json.Unmarshal([]byte(listAllResult), &listAll)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
@ -771,20 +771,20 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
assert.Equal(s.T(), uint64(4), listAll[3].Id)
|
assert.Equal(s.T(), uint64(4), listAll[3].Id)
|
||||||
assert.Equal(s.T(), uint64(5), listAll[4].Id)
|
assert.Equal(s.T(), uint64(5), listAll[4].Id)
|
||||||
|
|
||||||
assert.Equal(s.T(), "machine-1", listAll[0].Name)
|
assert.Equal(s.T(), "node-1", listAll[0].Name)
|
||||||
assert.Equal(s.T(), "machine-2", listAll[1].Name)
|
assert.Equal(s.T(), "node-2", listAll[1].Name)
|
||||||
assert.Equal(s.T(), "machine-3", listAll[2].Name)
|
assert.Equal(s.T(), "node-3", listAll[2].Name)
|
||||||
assert.Equal(s.T(), "machine-4", listAll[3].Name)
|
assert.Equal(s.T(), "node-4", listAll[3].Name)
|
||||||
assert.Equal(s.T(), "machine-5", listAll[4].Name)
|
assert.Equal(s.T(), "node-5", listAll[4].Name)
|
||||||
|
|
||||||
otherUserMachineKeys := []string{
|
otherUserNodeKeys := []string{
|
||||||
"nodekey:b5b444774186d4217adcec407563a1223929465ee2c68a4da13af0d0185b4f8e",
|
"nodekey:b5b444774186d4217adcec407563a1223929465ee2c68a4da13af0d0185b4f8e",
|
||||||
"nodekey:dc721977ac7415aafa87f7d4574cbe07c6b171834a6d37375782bdc1fb6b3584",
|
"nodekey:dc721977ac7415aafa87f7d4574cbe07c6b171834a6d37375782bdc1fb6b3584",
|
||||||
}
|
}
|
||||||
otherUserMachines := make([]*v1.Machine, len(otherUserMachineKeys))
|
otherUserNodes := make([]*v1.Node, len(otherUserNodeKeys))
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
for index, machineKey := range otherUserMachineKeys {
|
for index, nodeKey := range otherUserNodeKeys {
|
||||||
_, _, err := ExecuteCommand(
|
_, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
[]string{
|
[]string{
|
||||||
@ -792,11 +792,11 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
"debug",
|
"debug",
|
||||||
"create-node",
|
"create-node",
|
||||||
"--name",
|
"--name",
|
||||||
fmt.Sprintf("otherUser-machine-%d", index+1),
|
fmt.Sprintf("otherUser-node-%d", index+1),
|
||||||
"--user",
|
"--user",
|
||||||
secondUser.Name,
|
secondUser.Name,
|
||||||
"--key",
|
"--key",
|
||||||
machineKey,
|
nodeKey,
|
||||||
"--output",
|
"--output",
|
||||||
"json",
|
"json",
|
||||||
},
|
},
|
||||||
@ -804,7 +804,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
machineResult, _, err := ExecuteCommand(
|
nodeResult, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
[]string{
|
[]string{
|
||||||
"headscale",
|
"headscale",
|
||||||
@ -813,7 +813,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
secondUser.Name,
|
secondUser.Name,
|
||||||
"register",
|
"register",
|
||||||
"--key",
|
"--key",
|
||||||
machineKey,
|
nodeKey,
|
||||||
"--output",
|
"--output",
|
||||||
"json",
|
"json",
|
||||||
},
|
},
|
||||||
@ -821,14 +821,14 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var machine v1.Machine
|
var node v1.Node
|
||||||
err = json.Unmarshal([]byte(machineResult), &machine)
|
err = json.Unmarshal([]byte(nodeResult), &node)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
otherUserMachines[index] = &machine
|
otherUserNodes[index] = &node
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Len(s.T(), otherUserMachines, len(otherUserMachineKeys))
|
assert.Len(s.T(), otherUserNodes, len(otherUserNodeKeys))
|
||||||
|
|
||||||
// Test list all nodes after added otherUser
|
// Test list all nodes after added otherUser
|
||||||
listAllWithotherUserResult, _, err := ExecuteCommand(
|
listAllWithotherUserResult, _, err := ExecuteCommand(
|
||||||
@ -844,21 +844,21 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var listAllWithotherUser []v1.Machine
|
var listAllWithotherUser []v1.Node
|
||||||
err = json.Unmarshal(
|
err = json.Unmarshal(
|
||||||
[]byte(listAllWithotherUserResult),
|
[]byte(listAllWithotherUserResult),
|
||||||
&listAllWithotherUser,
|
&listAllWithotherUser,
|
||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
// All nodes, machines + otherUser
|
// All nodes, nodes + otherUser
|
||||||
assert.Len(s.T(), listAllWithotherUser, 7)
|
assert.Len(s.T(), listAllWithotherUser, 7)
|
||||||
|
|
||||||
assert.Equal(s.T(), uint64(6), listAllWithotherUser[5].Id)
|
assert.Equal(s.T(), uint64(6), listAllWithotherUser[5].Id)
|
||||||
assert.Equal(s.T(), uint64(7), listAllWithotherUser[6].Id)
|
assert.Equal(s.T(), uint64(7), listAllWithotherUser[6].Id)
|
||||||
|
|
||||||
assert.Equal(s.T(), "otherUser-machine-1", listAllWithotherUser[5].Name)
|
assert.Equal(s.T(), "otherUser-node-1", listAllWithotherUser[5].Name)
|
||||||
assert.Equal(s.T(), "otherUser-machine-2", listAllWithotherUser[6].Name)
|
assert.Equal(s.T(), "otherUser-node-2", listAllWithotherUser[6].Name)
|
||||||
|
|
||||||
// Test list all nodes after added otherUser
|
// Test list all nodes after added otherUser
|
||||||
listOnlyotherUserMachineUserResult, _, err := ExecuteCommand(
|
listOnlyotherUserMachineUserResult, _, err := ExecuteCommand(
|
||||||
@ -876,7 +876,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var listOnlyotherUserMachineUser []v1.Machine
|
var listOnlyotherUserMachineUser []v1.Node
|
||||||
err = json.Unmarshal(
|
err = json.Unmarshal(
|
||||||
[]byte(listOnlyotherUserMachineUserResult),
|
[]byte(listOnlyotherUserMachineUserResult),
|
||||||
&listOnlyotherUserMachineUser,
|
&listOnlyotherUserMachineUser,
|
||||||
@ -890,16 +890,16 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
|
|
||||||
assert.Equal(
|
assert.Equal(
|
||||||
s.T(),
|
s.T(),
|
||||||
"otherUser-machine-1",
|
"otherUser-node-1",
|
||||||
listOnlyotherUserMachineUser[0].Name,
|
listOnlyotherUserMachineUser[0].Name,
|
||||||
)
|
)
|
||||||
assert.Equal(
|
assert.Equal(
|
||||||
s.T(),
|
s.T(),
|
||||||
"otherUser-machine-2",
|
"otherUser-node-2",
|
||||||
listOnlyotherUserMachineUser[1].Name,
|
listOnlyotherUserMachineUser[1].Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Delete a machines
|
// Delete a nodes
|
||||||
_, _, err = ExecuteCommand(
|
_, _, err = ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
[]string{
|
[]string{
|
||||||
@ -907,7 +907,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
"nodes",
|
"nodes",
|
||||||
"delete",
|
"delete",
|
||||||
"--identifier",
|
"--identifier",
|
||||||
// Delete the last added machine
|
// Delete the last added node
|
||||||
"4",
|
"4",
|
||||||
"--output",
|
"--output",
|
||||||
"json",
|
"json",
|
||||||
@ -917,7 +917,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
// Test: list main user after machine is deleted
|
// Test: list main user after node is deleted
|
||||||
listOnlyMachineUserAfterDeleteResult, _, err := ExecuteCommand(
|
listOnlyMachineUserAfterDeleteResult, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
[]string{
|
[]string{
|
||||||
@ -933,7 +933,7 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var listOnlyMachineUserAfterDelete []v1.Machine
|
var listOnlyMachineUserAfterDelete []v1.Node
|
||||||
err = json.Unmarshal(
|
err = json.Unmarshal(
|
||||||
[]byte(listOnlyMachineUserAfterDeleteResult),
|
[]byte(listOnlyMachineUserAfterDeleteResult),
|
||||||
&listOnlyMachineUserAfterDelete,
|
&listOnlyMachineUserAfterDelete,
|
||||||
@ -944,21 +944,21 @@ func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *IntegrationCLITestSuite) TestNodeExpireCommand() {
|
func (s *IntegrationCLITestSuite) TestNodeExpireCommand() {
|
||||||
user, err := s.createUser("machine-expire-user")
|
user, err := s.createUser("node-expire-user")
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
// Randomly generated machine keys
|
// Randomly generated node keys
|
||||||
machineKeys := []string{
|
nodeKeys := []string{
|
||||||
"nodekey:9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe",
|
"nodekey:9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe",
|
||||||
"nodekey:6abd00bb5fdda622db51387088c68e97e71ce58e7056aa54f592b6a8219d524c",
|
"nodekey:6abd00bb5fdda622db51387088c68e97e71ce58e7056aa54f592b6a8219d524c",
|
||||||
"nodekey:f08305b4ee4250b95a70f3b7504d048d75d899993c624a26d422c67af0422507",
|
"nodekey:f08305b4ee4250b95a70f3b7504d048d75d899993c624a26d422c67af0422507",
|
||||||
"nodekey:8bc13285cee598acf76b1824a6f4490f7f2e3751b201e28aeb3b07fe81d5b4a1",
|
"nodekey:8bc13285cee598acf76b1824a6f4490f7f2e3751b201e28aeb3b07fe81d5b4a1",
|
||||||
"nodekey:cf7b0fd05da556fdc3bab365787b506fd82d64a70745db70e00e86c1b1c03084",
|
"nodekey:cf7b0fd05da556fdc3bab365787b506fd82d64a70745db70e00e86c1b1c03084",
|
||||||
}
|
}
|
||||||
machines := make([]*v1.Machine, len(machineKeys))
|
nodes := make([]*v1.Node, len(nodeKeys))
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
for index, machineKey := range machineKeys {
|
for index, nodeKey := range nodeKeys {
|
||||||
_, _, err := ExecuteCommand(
|
_, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
[]string{
|
[]string{
|
||||||
@ -966,11 +966,11 @@ func (s *IntegrationCLITestSuite) TestNodeExpireCommand() {
|
|||||||
"debug",
|
"debug",
|
||||||
"create-node",
|
"create-node",
|
||||||
"--name",
|
"--name",
|
||||||
fmt.Sprintf("machine-%d", index+1),
|
fmt.Sprintf("node-%d", index+1),
|
||||||
"--user",
|
"--user",
|
||||||
user.Name,
|
user.Name,
|
||||||
"--key",
|
"--key",
|
||||||
machineKey,
|
nodeKey,
|
||||||
"--output",
|
"--output",
|
||||||
"json",
|
"json",
|
||||||
},
|
},
|
||||||
@ -978,7 +978,7 @@ func (s *IntegrationCLITestSuite) TestNodeExpireCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
machineResult, _, err := ExecuteCommand(
|
nodeResult, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
[]string{
|
[]string{
|
||||||
"headscale",
|
"headscale",
|
||||||
@ -987,7 +987,7 @@ func (s *IntegrationCLITestSuite) TestNodeExpireCommand() {
|
|||||||
user.Name,
|
user.Name,
|
||||||
"register",
|
"register",
|
||||||
"--key",
|
"--key",
|
||||||
machineKey,
|
nodeKey,
|
||||||
"--output",
|
"--output",
|
||||||
"json",
|
"json",
|
||||||
},
|
},
|
||||||
@ -995,14 +995,14 @@ func (s *IntegrationCLITestSuite) TestNodeExpireCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var machine v1.Machine
|
var node v1.Node
|
||||||
err = json.Unmarshal([]byte(machineResult), &machine)
|
err = json.Unmarshal([]byte(nodeResult), &node)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
machines[index] = &machine
|
nodes[index] = &node
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Len(s.T(), machines, len(machineKeys))
|
assert.Len(s.T(), nodes, len(nodeKeys))
|
||||||
|
|
||||||
listAllResult, _, err := ExecuteCommand(
|
listAllResult, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
@ -1017,7 +1017,7 @@ func (s *IntegrationCLITestSuite) TestNodeExpireCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var listAll []v1.Machine
|
var listAll []v1.Node
|
||||||
err = json.Unmarshal([]byte(listAllResult), &listAll)
|
err = json.Unmarshal([]byte(listAllResult), &listAll)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
@ -1057,7 +1057,7 @@ func (s *IntegrationCLITestSuite) TestNodeExpireCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var listAllAfterExpiry []v1.Machine
|
var listAllAfterExpiry []v1.Node
|
||||||
err = json.Unmarshal([]byte(listAllAfterExpiryResult), &listAllAfterExpiry)
|
err = json.Unmarshal([]byte(listAllAfterExpiryResult), &listAllAfterExpiry)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
@ -1071,21 +1071,21 @@ func (s *IntegrationCLITestSuite) TestNodeExpireCommand() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
|
func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
|
||||||
user, err := s.createUser("machine-rename-command")
|
user, err := s.createUser("node-rename-command")
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
// Randomly generated machine keys
|
// Randomly generated node keys
|
||||||
machineKeys := []string{
|
nodeKeys := []string{
|
||||||
"nodekey:cf7b0fd05da556fdc3bab365787b506fd82d64a70745db70e00e86c1b1c03084",
|
"nodekey:cf7b0fd05da556fdc3bab365787b506fd82d64a70745db70e00e86c1b1c03084",
|
||||||
"nodekey:8bc13285cee598acf76b1824a6f4490f7f2e3751b201e28aeb3b07fe81d5b4a1",
|
"nodekey:8bc13285cee598acf76b1824a6f4490f7f2e3751b201e28aeb3b07fe81d5b4a1",
|
||||||
"nodekey:f08305b4ee4250b95a70f3b7504d048d75d899993c624a26d422c67af0422507",
|
"nodekey:f08305b4ee4250b95a70f3b7504d048d75d899993c624a26d422c67af0422507",
|
||||||
"nodekey:6abd00bb5fdda622db51387088c68e97e71ce58e7056aa54f592b6a8219d524c",
|
"nodekey:6abd00bb5fdda622db51387088c68e97e71ce58e7056aa54f592b6a8219d524c",
|
||||||
"nodekey:9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe",
|
"nodekey:9b2ffa7e08cc421a3d2cca9012280f6a236fd0de0b4ce005b30a98ad930306fe",
|
||||||
}
|
}
|
||||||
machines := make([]*v1.Machine, len(machineKeys))
|
nodes := make([]*v1.Node, len(nodeKeys))
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
for index, machineKey := range machineKeys {
|
for index, nodeKey := range nodeKeys {
|
||||||
_, _, err := ExecuteCommand(
|
_, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
[]string{
|
[]string{
|
||||||
@ -1093,11 +1093,11 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
|
|||||||
"debug",
|
"debug",
|
||||||
"create-node",
|
"create-node",
|
||||||
"--name",
|
"--name",
|
||||||
fmt.Sprintf("machine-%d", index+1),
|
fmt.Sprintf("node-%d", index+1),
|
||||||
"--user",
|
"--user",
|
||||||
user.Name,
|
user.Name,
|
||||||
"--key",
|
"--key",
|
||||||
machineKey,
|
nodeKey,
|
||||||
"--output",
|
"--output",
|
||||||
"json",
|
"json",
|
||||||
},
|
},
|
||||||
@ -1105,7 +1105,7 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
machineResult, _, err := ExecuteCommand(
|
nodeResult, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
[]string{
|
[]string{
|
||||||
"headscale",
|
"headscale",
|
||||||
@ -1114,7 +1114,7 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
|
|||||||
user.Name,
|
user.Name,
|
||||||
"register",
|
"register",
|
||||||
"--key",
|
"--key",
|
||||||
machineKey,
|
nodeKey,
|
||||||
"--output",
|
"--output",
|
||||||
"json",
|
"json",
|
||||||
},
|
},
|
||||||
@ -1122,14 +1122,14 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var machine v1.Machine
|
var node v1.Node
|
||||||
err = json.Unmarshal([]byte(machineResult), &machine)
|
err = json.Unmarshal([]byte(nodeResult), &node)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
machines[index] = &machine
|
nodes[index] = &node
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Len(s.T(), machines, len(machineKeys))
|
assert.Len(s.T(), nodes, len(nodeKeys))
|
||||||
|
|
||||||
listAllResult, _, err := ExecuteCommand(
|
listAllResult, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
@ -1144,17 +1144,17 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var listAll []v1.Machine
|
var listAll []v1.Node
|
||||||
err = json.Unmarshal([]byte(listAllResult), &listAll)
|
err = json.Unmarshal([]byte(listAllResult), &listAll)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
assert.Len(s.T(), listAll, 5)
|
assert.Len(s.T(), listAll, 5)
|
||||||
|
|
||||||
assert.Contains(s.T(), listAll[0].GetGivenName(), "machine-1")
|
assert.Contains(s.T(), listAll[0].GetGivenName(), "node-1")
|
||||||
assert.Contains(s.T(), listAll[1].GetGivenName(), "machine-2")
|
assert.Contains(s.T(), listAll[1].GetGivenName(), "node-2")
|
||||||
assert.Contains(s.T(), listAll[2].GetGivenName(), "machine-3")
|
assert.Contains(s.T(), listAll[2].GetGivenName(), "node-3")
|
||||||
assert.Contains(s.T(), listAll[3].GetGivenName(), "machine-4")
|
assert.Contains(s.T(), listAll[3].GetGivenName(), "node-4")
|
||||||
assert.Contains(s.T(), listAll[4].GetGivenName(), "machine-5")
|
assert.Contains(s.T(), listAll[4].GetGivenName(), "node-5")
|
||||||
|
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
_, _, err := ExecuteCommand(
|
_, _, err := ExecuteCommand(
|
||||||
@ -1165,7 +1165,7 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
|
|||||||
"rename",
|
"rename",
|
||||||
"--identifier",
|
"--identifier",
|
||||||
fmt.Sprintf("%d", listAll[i].Id),
|
fmt.Sprintf("%d", listAll[i].Id),
|
||||||
fmt.Sprintf("newmachine-%d", i+1),
|
fmt.Sprintf("newnode-%d", i+1),
|
||||||
},
|
},
|
||||||
[]string{},
|
[]string{},
|
||||||
)
|
)
|
||||||
@ -1185,17 +1185,17 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var listAllAfterRename []v1.Machine
|
var listAllAfterRename []v1.Node
|
||||||
err = json.Unmarshal([]byte(listAllAfterRenameResult), &listAllAfterRename)
|
err = json.Unmarshal([]byte(listAllAfterRenameResult), &listAllAfterRename)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
assert.Len(s.T(), listAllAfterRename, 5)
|
assert.Len(s.T(), listAllAfterRename, 5)
|
||||||
|
|
||||||
assert.Equal(s.T(), "newmachine-1", listAllAfterRename[0].GetGivenName())
|
assert.Equal(s.T(), "newnode-1", listAllAfterRename[0].GetGivenName())
|
||||||
assert.Equal(s.T(), "newmachine-2", listAllAfterRename[1].GetGivenName())
|
assert.Equal(s.T(), "newnode-2", listAllAfterRename[1].GetGivenName())
|
||||||
assert.Equal(s.T(), "newmachine-3", listAllAfterRename[2].GetGivenName())
|
assert.Equal(s.T(), "newnode-3", listAllAfterRename[2].GetGivenName())
|
||||||
assert.Contains(s.T(), listAllAfterRename[3].GetGivenName(), "machine-4")
|
assert.Contains(s.T(), listAllAfterRename[3].GetGivenName(), "node-4")
|
||||||
assert.Contains(s.T(), listAllAfterRename[4].GetGivenName(), "machine-5")
|
assert.Contains(s.T(), listAllAfterRename[4].GetGivenName(), "node-5")
|
||||||
|
|
||||||
// Test failure for too long names
|
// Test failure for too long names
|
||||||
result, _, err := ExecuteCommand(
|
result, _, err := ExecuteCommand(
|
||||||
@ -1226,7 +1226,7 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var listAllAfterRenameAttempt []v1.Machine
|
var listAllAfterRenameAttempt []v1.Node
|
||||||
err = json.Unmarshal(
|
err = json.Unmarshal(
|
||||||
[]byte(listAllAfterRenameAttemptResult),
|
[]byte(listAllAfterRenameAttemptResult),
|
||||||
&listAllAfterRenameAttempt,
|
&listAllAfterRenameAttempt,
|
||||||
@ -1235,11 +1235,11 @@ func (s *IntegrationCLITestSuite) TestNodeRenameCommand() {
|
|||||||
|
|
||||||
assert.Len(s.T(), listAllAfterRenameAttempt, 5)
|
assert.Len(s.T(), listAllAfterRenameAttempt, 5)
|
||||||
|
|
||||||
assert.Equal(s.T(), "newmachine-1", listAllAfterRenameAttempt[0].GetGivenName())
|
assert.Equal(s.T(), "newnode-1", listAllAfterRenameAttempt[0].GetGivenName())
|
||||||
assert.Equal(s.T(), "newmachine-2", listAllAfterRenameAttempt[1].GetGivenName())
|
assert.Equal(s.T(), "newnode-2", listAllAfterRenameAttempt[1].GetGivenName())
|
||||||
assert.Equal(s.T(), "newmachine-3", listAllAfterRenameAttempt[2].GetGivenName())
|
assert.Equal(s.T(), "newnode-3", listAllAfterRenameAttempt[2].GetGivenName())
|
||||||
assert.Contains(s.T(), listAllAfterRenameAttempt[3].GetGivenName(), "machine-4")
|
assert.Contains(s.T(), listAllAfterRenameAttempt[3].GetGivenName(), "node-4")
|
||||||
assert.Contains(s.T(), listAllAfterRenameAttempt[4].GetGivenName(), "machine-5")
|
assert.Contains(s.T(), listAllAfterRenameAttempt[4].GetGivenName(), "node-5")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *IntegrationCLITestSuite) TestApiKeyCommand() {
|
func (s *IntegrationCLITestSuite) TestApiKeyCommand() {
|
||||||
@ -1393,8 +1393,8 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
|
|||||||
newUser, err := s.createUser("new-user")
|
newUser, err := s.createUser("new-user")
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
// Randomly generated machine key
|
// Randomly generated node key
|
||||||
machineKey := "nodekey:688411b767663479632d44140f08a9fde87383adc7cdeb518f62ce28a17ef0aa"
|
nodeKey := "nodekey:688411b767663479632d44140f08a9fde87383adc7cdeb518f62ce28a17ef0aa"
|
||||||
|
|
||||||
_, _, err = ExecuteCommand(
|
_, _, err = ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
@ -1403,11 +1403,11 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
|
|||||||
"debug",
|
"debug",
|
||||||
"create-node",
|
"create-node",
|
||||||
"--name",
|
"--name",
|
||||||
"nomad-machine",
|
"nomad-node",
|
||||||
"--user",
|
"--user",
|
||||||
oldUser.Name,
|
oldUser.Name,
|
||||||
"--key",
|
"--key",
|
||||||
machineKey,
|
nodeKey,
|
||||||
"--output",
|
"--output",
|
||||||
"json",
|
"json",
|
||||||
},
|
},
|
||||||
@ -1415,7 +1415,7 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
machineResult, _, err := ExecuteCommand(
|
nodeResult, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
[]string{
|
[]string{
|
||||||
"headscale",
|
"headscale",
|
||||||
@ -1424,7 +1424,7 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
|
|||||||
oldUser.Name,
|
oldUser.Name,
|
||||||
"register",
|
"register",
|
||||||
"--key",
|
"--key",
|
||||||
machineKey,
|
nodeKey,
|
||||||
"--output",
|
"--output",
|
||||||
"json",
|
"json",
|
||||||
},
|
},
|
||||||
@ -1432,15 +1432,15 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var machine v1.Machine
|
var node v1.Node
|
||||||
err = json.Unmarshal([]byte(machineResult), &machine)
|
err = json.Unmarshal([]byte(nodeResult), &node)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
assert.Equal(s.T(), uint64(1), machine.Id)
|
assert.Equal(s.T(), uint64(1), node.Id)
|
||||||
assert.Equal(s.T(), "nomad-machine", machine.Name)
|
assert.Equal(s.T(), "nomad-node", node.Name)
|
||||||
assert.Equal(s.T(), machine.User.Name, oldUser.Name)
|
assert.Equal(s.T(), node.User.Name, oldUser.Name)
|
||||||
|
|
||||||
machineId := fmt.Sprintf("%d", machine.Id)
|
nodeId := fmt.Sprintf("%d", node.Id)
|
||||||
|
|
||||||
moveToNewNSResult, _, err := ExecuteCommand(
|
moveToNewNSResult, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
@ -1449,7 +1449,7 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
|
|||||||
"nodes",
|
"nodes",
|
||||||
"move",
|
"move",
|
||||||
"--identifier",
|
"--identifier",
|
||||||
machineId,
|
nodeId,
|
||||||
"--user",
|
"--user",
|
||||||
newUser.Name,
|
newUser.Name,
|
||||||
"--output",
|
"--output",
|
||||||
@ -1459,10 +1459,10 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
err = json.Unmarshal([]byte(moveToNewNSResult), &machine)
|
err = json.Unmarshal([]byte(moveToNewNSResult), &node)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
assert.Equal(s.T(), machine.User, newUser)
|
assert.Equal(s.T(), node.User, newUser)
|
||||||
|
|
||||||
listAllNodesResult, _, err := ExecuteCommand(
|
listAllNodesResult, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
@ -1477,14 +1477,14 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
var allNodes []v1.Machine
|
var allNodes []v1.Node
|
||||||
err = json.Unmarshal([]byte(listAllNodesResult), &allNodes)
|
err = json.Unmarshal([]byte(listAllNodesResult), &allNodes)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
assert.Len(s.T(), allNodes, 1)
|
assert.Len(s.T(), allNodes, 1)
|
||||||
|
|
||||||
assert.Equal(s.T(), allNodes[0].Id, machine.Id)
|
assert.Equal(s.T(), allNodes[0].Id, node.Id)
|
||||||
assert.Equal(s.T(), allNodes[0].User, machine.User)
|
assert.Equal(s.T(), allNodes[0].User, node.User)
|
||||||
assert.Equal(s.T(), allNodes[0].User, newUser)
|
assert.Equal(s.T(), allNodes[0].User, newUser)
|
||||||
|
|
||||||
moveToNonExistingNSResult, _, err := ExecuteCommand(
|
moveToNonExistingNSResult, _, err := ExecuteCommand(
|
||||||
@ -1494,7 +1494,7 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
|
|||||||
"nodes",
|
"nodes",
|
||||||
"move",
|
"move",
|
||||||
"--identifier",
|
"--identifier",
|
||||||
machineId,
|
nodeId,
|
||||||
"--user",
|
"--user",
|
||||||
"non-existing-user",
|
"non-existing-user",
|
||||||
"--output",
|
"--output",
|
||||||
@ -1509,7 +1509,7 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
|
|||||||
string(moveToNonExistingNSResult),
|
string(moveToNonExistingNSResult),
|
||||||
"User not found",
|
"User not found",
|
||||||
)
|
)
|
||||||
assert.Equal(s.T(), machine.User, newUser)
|
assert.Equal(s.T(), node.User, newUser)
|
||||||
|
|
||||||
moveToOldNSResult, _, err := ExecuteCommand(
|
moveToOldNSResult, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
@ -1518,7 +1518,7 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
|
|||||||
"nodes",
|
"nodes",
|
||||||
"move",
|
"move",
|
||||||
"--identifier",
|
"--identifier",
|
||||||
machineId,
|
nodeId,
|
||||||
"--user",
|
"--user",
|
||||||
oldUser.Name,
|
oldUser.Name,
|
||||||
"--output",
|
"--output",
|
||||||
@ -1528,10 +1528,10 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
err = json.Unmarshal([]byte(moveToOldNSResult), &machine)
|
err = json.Unmarshal([]byte(moveToOldNSResult), &node)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
assert.Equal(s.T(), machine.User, oldUser)
|
assert.Equal(s.T(), node.User, oldUser)
|
||||||
|
|
||||||
moveToSameNSResult, _, err := ExecuteCommand(
|
moveToSameNSResult, _, err := ExecuteCommand(
|
||||||
&s.headscale,
|
&s.headscale,
|
||||||
@ -1540,7 +1540,7 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
|
|||||||
"nodes",
|
"nodes",
|
||||||
"move",
|
"move",
|
||||||
"--identifier",
|
"--identifier",
|
||||||
machineId,
|
nodeId,
|
||||||
"--user",
|
"--user",
|
||||||
oldUser.Name,
|
oldUser.Name,
|
||||||
"--output",
|
"--output",
|
||||||
@ -1550,10 +1550,10 @@ func (s *IntegrationCLITestSuite) TestNodeMoveCommand() {
|
|||||||
)
|
)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
err = json.Unmarshal([]byte(moveToSameNSResult), &machine)
|
err = json.Unmarshal([]byte(moveToSameNSResult), &node)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
assert.Equal(s.T(), machine.User, oldUser)
|
assert.Equal(s.T(), node.User, oldUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *IntegrationCLITestSuite) TestLoadConfigFromCommand() {
|
func (s *IntegrationCLITestSuite) TestLoadConfigFromCommand() {
|
||||||
|
@ -215,7 +215,7 @@ func getDNSNames(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var listAll []v1.Machine
|
var listAll []v1.Node
|
||||||
err = json.Unmarshal([]byte(listAllResult), &listAll)
|
err = json.Unmarshal([]byte(listAllResult), &listAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user