mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-23 18:15:26 +00:00
Fix Reusable typo, add tests for Augustines scenario
This commit is contained in:
parent
6371135459
commit
0803c407a9
@ -97,7 +97,7 @@ var registerNodeCmd = &cobra.Command{
|
|||||||
|
|
||||||
response, err := client.RegisterMachine(ctx, request)
|
response, err := client.RegisterMachine(ctx, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ErrorOutput(err, fmt.Sprintf("Cannot register machine: %s\n", err), output)
|
ErrorOutput(err, fmt.Sprintf("Cannot register machine: %s\n", status.Convert(err).Message()), output)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ var listPreAuthKeys = &cobra.Command{
|
|||||||
if k.GetEphemeral() {
|
if k.GetEphemeral() {
|
||||||
reusable = "N/A"
|
reusable = "N/A"
|
||||||
} else {
|
} else {
|
||||||
reusable = fmt.Sprintf("%v", k.GetResuable())
|
reusable = fmt.Sprintf("%v", k.GetReusable())
|
||||||
}
|
}
|
||||||
|
|
||||||
d = append(d, []string{
|
d = append(d, []string{
|
||||||
@ -112,9 +112,15 @@ var createPreAuthKeyCmd = &cobra.Command{
|
|||||||
reusable, _ := cmd.Flags().GetBool("reusable")
|
reusable, _ := cmd.Flags().GetBool("reusable")
|
||||||
ephemeral, _ := cmd.Flags().GetBool("ephemeral")
|
ephemeral, _ := cmd.Flags().GetBool("ephemeral")
|
||||||
|
|
||||||
|
log.Trace().
|
||||||
|
Bool("reusable", reusable).
|
||||||
|
Bool("ephemeral", ephemeral).
|
||||||
|
Str("namespace", namespace).
|
||||||
|
Msg("Preparing to create preauthkey")
|
||||||
|
|
||||||
request := &v1.CreatePreAuthKeyRequest{
|
request := &v1.CreatePreAuthKeyRequest{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Resuable: reusable,
|
Reusable: reusable,
|
||||||
Ephemeral: ephemeral,
|
Ephemeral: ephemeral,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ func (api headscaleV1APIServer) CreatePreAuthKey(
|
|||||||
|
|
||||||
preAuthKey, err := api.h.CreatePreAuthKey(
|
preAuthKey, err := api.h.CreatePreAuthKey(
|
||||||
request.GetNamespace(),
|
request.GetNamespace(),
|
||||||
request.GetResuable(),
|
request.GetReusable(),
|
||||||
request.GetEphemeral(),
|
request.GetEphemeral(),
|
||||||
&expiration,
|
&expiration,
|
||||||
)
|
)
|
||||||
@ -155,6 +155,7 @@ func (api headscaleV1APIServer) RegisterMachine(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *v1.RegisterMachineRequest,
|
request *v1.RegisterMachineRequest,
|
||||||
) (*v1.RegisterMachineResponse, error) {
|
) (*v1.RegisterMachineResponse, error) {
|
||||||
|
log.Trace().Str("namespace", request.GetNamespace()).Str("machine_key", request.GetKey()).Msg("Registering machine")
|
||||||
machine, err := api.h.RegisterMachine(
|
machine, err := api.h.RegisterMachine(
|
||||||
request.GetKey(),
|
request.GetKey(),
|
||||||
request.GetNamespace(),
|
request.GetNamespace(),
|
||||||
|
@ -396,6 +396,97 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommandWithoutExpiry() {
|
|||||||
assert.True(s.T(), time.Time{}.Equal(listedPreAuthKeys[0].Expiration.AsTime()))
|
assert.True(s.T(), time.Time{}.Equal(listedPreAuthKeys[0].Expiration.AsTime()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *IntegrationCLITestSuite) TestPreAuthKeyCommandReusableEphemeral() {
|
||||||
|
namespace, err := s.createNamespace("pre-auth-key-reus-ephm-namespace")
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
|
preAuthReusableResult, err := ExecuteCommand(
|
||||||
|
&s.headscale,
|
||||||
|
[]string{
|
||||||
|
"headscale",
|
||||||
|
"preauthkeys",
|
||||||
|
"--namespace",
|
||||||
|
namespace.Name,
|
||||||
|
"create",
|
||||||
|
"--reusable=true",
|
||||||
|
"--output",
|
||||||
|
"json",
|
||||||
|
},
|
||||||
|
[]string{},
|
||||||
|
)
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
|
var preAuthReusableKey v1.PreAuthKey
|
||||||
|
err = json.Unmarshal([]byte(preAuthReusableResult), &preAuthReusableKey)
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
|
assert.True(s.T(), preAuthReusableKey.GetReusable())
|
||||||
|
assert.False(s.T(), preAuthReusableKey.GetEphemeral())
|
||||||
|
|
||||||
|
preAuthEphemeralResult, err := ExecuteCommand(
|
||||||
|
&s.headscale,
|
||||||
|
[]string{
|
||||||
|
"headscale",
|
||||||
|
"preauthkeys",
|
||||||
|
"--namespace",
|
||||||
|
namespace.Name,
|
||||||
|
"create",
|
||||||
|
"--ephemeral=true",
|
||||||
|
"--output",
|
||||||
|
"json",
|
||||||
|
},
|
||||||
|
[]string{},
|
||||||
|
)
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
|
var preAuthEphemeralKey v1.PreAuthKey
|
||||||
|
err = json.Unmarshal([]byte(preAuthEphemeralResult), &preAuthEphemeralKey)
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
|
assert.True(s.T(), preAuthEphemeralKey.GetEphemeral())
|
||||||
|
assert.False(s.T(), preAuthEphemeralKey.GetReusable())
|
||||||
|
|
||||||
|
// TODO(kradalby): Evaluate if we need a case to test for reusable and ephemeral
|
||||||
|
// preAuthReusableAndEphemeralResult, err := ExecuteCommand(
|
||||||
|
// &s.headscale,
|
||||||
|
// []string{
|
||||||
|
// "headscale",
|
||||||
|
// "preauthkeys",
|
||||||
|
// "--namespace",
|
||||||
|
// namespace.Name,
|
||||||
|
// "create",
|
||||||
|
// "--ephemeral",
|
||||||
|
// "--reusable",
|
||||||
|
// "--output",
|
||||||
|
// "json",
|
||||||
|
// },
|
||||||
|
// []string{},
|
||||||
|
// )
|
||||||
|
// assert.NotNil(s.T(), err)
|
||||||
|
|
||||||
|
// Test list of keys
|
||||||
|
listResult, err := ExecuteCommand(
|
||||||
|
&s.headscale,
|
||||||
|
[]string{
|
||||||
|
"headscale",
|
||||||
|
"preauthkeys",
|
||||||
|
"--namespace",
|
||||||
|
namespace.Name,
|
||||||
|
"list",
|
||||||
|
"--output",
|
||||||
|
"json",
|
||||||
|
},
|
||||||
|
[]string{},
|
||||||
|
)
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
|
var listedPreAuthKeys []v1.PreAuthKey
|
||||||
|
err = json.Unmarshal([]byte(listResult), &listedPreAuthKeys)
|
||||||
|
assert.Nil(s.T(), err)
|
||||||
|
|
||||||
|
assert.Len(s.T(), listedPreAuthKeys, 2)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
func (s *IntegrationCLITestSuite) TestNodeCommand() {
|
||||||
namespace, err := s.createNamespace("machine-namespace")
|
namespace, err := s.createNamespace("machine-namespace")
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
@ -269,6 +269,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
|
|||||||
var preAuthKey v1.PreAuthKey
|
var preAuthKey v1.PreAuthKey
|
||||||
err = json.Unmarshal([]byte(preAuthResult), &preAuthKey)
|
err = json.Unmarshal([]byte(preAuthResult), &preAuthKey)
|
||||||
assert.Nil(s.T(), err)
|
assert.Nil(s.T(), err)
|
||||||
|
assert.True(s.T(), preAuthKey.Reusable)
|
||||||
|
|
||||||
headscaleEndpoint := "http://headscale:8080"
|
headscaleEndpoint := "http://headscale:8080"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user