Merge pull request #237 from cure/preauthkeys-fix-default-expiration

Fix default preauthkey expiration
This commit is contained in:
Ward Vandewege 2021-11-26 11:09:43 -05:00 committed by GitHub
commit d944aa6e79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View File

@ -13,7 +13,7 @@ import (
)
const (
DefaultPreAuthKeyExpiry = 24 * time.Hour
DefaultPreAuthKeyExpiry = 1 * time.Hour
)
func init() {
@ -145,14 +145,12 @@ var createPreAuthKeyCmd = &cobra.Command{
Ephemeral: ephemeral,
}
if cmd.Flags().Changed("expiration") {
duration, _ := cmd.Flags().GetDuration("expiration")
expiration := time.Now().UTC().Add(duration)
duration, _ := cmd.Flags().GetDuration("expiration")
expiration := time.Now().UTC().Add(duration)
log.Trace().Dur("expiration", duration).Msg("expiration has been set")
log.Trace().Dur("expiration", duration).Msg("expiration has been set")
request.Expiration = timestamppb.New(expiration)
}
request.Expiration = timestamppb.New(expiration)
ctx, client, conn, cancel := getHeadscaleCLIClient()
defer cancel()

View File

@ -426,7 +426,12 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommandWithoutExpiry() {
assert.Nil(s.T(), err)
assert.Len(s.T(), listedPreAuthKeys, 1)
assert.True(s.T(), time.Time{}.Equal(listedPreAuthKeys[0].Expiration.AsTime()))
assert.True(s.T(), listedPreAuthKeys[0].Expiration.AsTime().After(time.Now()))
assert.True(
s.T(),
listedPreAuthKeys[0].Expiration.AsTime().Before(time.Now().Add(time.Minute*70)),
)
}
func (s *IntegrationCLITestSuite) TestPreAuthKeyCommandReusableEphemeral() {