diff --git a/management/server/http/api/openapi.yml b/management/server/http/api/openapi.yml index d109113d9..0f9a67aef 100644 --- a/management/server/http/api/openapi.yml +++ b/management/server/http/api/openapi.yml @@ -369,7 +369,9 @@ components: expires_in: description: Expiration time in seconds type: integer - example: 43200 + minimum: 86400 + maximum: 31536000 + example: 86400 revoked: description: Setup key revocation status type: boolean diff --git a/management/server/http/setupkeys_handler.go b/management/server/http/setupkeys_handler.go index 5f9d06714..58a3c1091 100644 --- a/management/server/http/setupkeys_handler.go +++ b/management/server/http/setupkeys_handler.go @@ -60,6 +60,13 @@ func (h *SetupKeysHandler) CreateSetupKey(w http.ResponseWriter, r *http.Request expiresIn := time.Duration(req.ExpiresIn) * time.Second + day := time.Hour * 24 + year := day * 365 + if expiresIn < day || expiresIn > year { + util.WriteError(status.Errorf(status.InvalidArgument, "expiresIn should be between 1 day and 365 days"), w) + return + } + if req.AutoGroups == nil { req.AutoGroups = []string{} } diff --git a/management/server/http/setupkeys_handler_test.go b/management/server/http/setupkeys_handler_test.go index 970d007ef..4a5a9af62 100644 --- a/management/server/http/setupkeys_handler_test.go +++ b/management/server/http/setupkeys_handler_test.go @@ -143,7 +143,7 @@ func TestSetupKeysHandlers(t *testing.T) { requestType: http.MethodPost, requestPath: "/api/setup-keys", requestBody: bytes.NewBuffer( - []byte(fmt.Sprintf("{\"name\":\"%s\",\"type\":\"%s\"}", newSetupKey.Name, newSetupKey.Type))), + []byte(fmt.Sprintf("{\"name\":\"%s\",\"type\":\"%s\",\"expires_in\":86400}", newSetupKey.Name, newSetupKey.Type))), expectedStatus: http.StatusOK, expectedBody: true, expectedSetupKey: toResponseBody(newSetupKey),