Skip to content

Commit

Permalink
MF-1103 - API key should ignore empty expiration time (#1104)
Browse files Browse the repository at this point in the history
* Fix API keys expiration validation

Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>

* Fix API docs

Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
  • Loading branch information
dborovcanin authored Apr 7, 2020
1 parent a9d3d07 commit 45da89e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
3 changes: 3 additions & 0 deletions authn/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type Key struct {

// Expired verifies if the key is expired.
func (k Key) Expired() bool {
if k.Type == APIKey && k.ExpiresAt.IsZero() {
return false
}
return k.ExpiresAt.UTC().Before(time.Now().UTC())
}

Expand Down
10 changes: 9 additions & 1 deletion authn/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,20 @@ func TestExpired(t *testing.T) {
expired: true,
},
{
desc: "key with no expiration date",
desc: "user key with no expiration date",
key: authn.Key{
IssuedAt: time.Now(),
},
expired: true,
},
{
desc: "API key with no expiration date",
key: authn.Key{
IssuedAt: time.Now(),
Type: authn.APIKey,
},
expired: false,
},
}

for _, tc := range cases {
Expand Down
21 changes: 18 additions & 3 deletions authn/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ paths:
description: JSON-formatted document describing the new key.
in: body
schema:
$ref: "#/definitions/Key"
$ref: "#/definitions/KeyRequest"
required: true
responses:
201:
Expand Down Expand Up @@ -111,8 +111,23 @@ definitions:
format: date-time
example: "2019-11-26 13:31:52"
description: Time when the Key expires
required:
- type
KeyRequest:
type: object
properties:
type:
type: integer
example: 0
description: API key type. Keys of different type are processed differently
issuer:
type: string
format: e-mail
example: "test@example.com"
description: User's email or service identifier of API key issuer
duration:
type: number
format: integer
example: 23456
description: Number of seconds issued token is valid for.

parameters:
Authorization:
Expand Down

0 comments on commit 45da89e

Please sign in to comment.