Fix Reusable typo, add tests for Augustines scenario

This commit is contained in:
Kristoffer Dalby 2021-11-08 20:49:03 +00:00
parent 6371135459
commit 0803c407a9
5 changed files with 103 additions and 4 deletions

View File

@ -97,7 +97,7 @@ var registerNodeCmd = &cobra.Command{
response, err := client.RegisterMachine(ctx, request)
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
}

View File

@ -75,7 +75,7 @@ var listPreAuthKeys = &cobra.Command{
if k.GetEphemeral() {
reusable = "N/A"
} else {
reusable = fmt.Sprintf("%v", k.GetResuable())
reusable = fmt.Sprintf("%v", k.GetReusable())
}
d = append(d, []string{
@ -112,9 +112,15 @@ var createPreAuthKeyCmd = &cobra.Command{
reusable, _ := cmd.Flags().GetBool("reusable")
ephemeral, _ := cmd.Flags().GetBool("ephemeral")
log.Trace().
Bool("reusable", reusable).
Bool("ephemeral", ephemeral).
Str("namespace", namespace).
Msg("Preparing to create preauthkey")
request := &v1.CreatePreAuthKeyRequest{
Namespace: namespace,
Resuable: reusable,
Reusable: reusable,
Ephemeral: ephemeral,
}

View File

@ -106,7 +106,7 @@ func (api headscaleV1APIServer) CreatePreAuthKey(
preAuthKey, err := api.h.CreatePreAuthKey(
request.GetNamespace(),
request.GetResuable(),
request.GetReusable(),
request.GetEphemeral(),
&expiration,
)
@ -155,6 +155,7 @@ func (api headscaleV1APIServer) RegisterMachine(
ctx context.Context,
request *v1.RegisterMachineRequest,
) (*v1.RegisterMachineResponse, error) {
log.Trace().Str("namespace", request.GetNamespace()).Str("machine_key", request.GetKey()).Msg("Registering machine")
machine, err := api.h.RegisterMachine(
request.GetKey(),
request.GetNamespace(),

View File

@ -396,6 +396,97 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommandWithoutExpiry() {
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() {
namespace, err := s.createNamespace("machine-namespace")
assert.Nil(s.T(), err)

View File

@ -269,6 +269,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
var preAuthKey v1.PreAuthKey
err = json.Unmarshal([]byte(preAuthResult), &preAuthKey)
assert.Nil(s.T(), err)
assert.True(s.T(), preAuthKey.Reusable)
headscaleEndpoint := "http://headscale:8080"