mirror of
https://github.com/absmach/supermq.git
synced 2026-06-23 07:10:19 +00:00
a0c40ba462
* chore(license): update copyright notices Add CI check for non go files to check that the files contain a license Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * fix(ci): log failed files When the CI fails during check for license header, log the failed file to console so that someone can check on the actual file. Also simplify the grep check to make it more human readable and understandable Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
// Copyright (c) Abstract Machines
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package auth_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/absmach/magistrala/auth"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestExpired(t *testing.T) {
|
|
exp := time.Now().Add(5 * time.Minute)
|
|
exp1 := time.Now()
|
|
cases := []struct {
|
|
desc string
|
|
key auth.Key
|
|
expired bool
|
|
}{
|
|
{
|
|
desc: "not expired key",
|
|
key: auth.Key{
|
|
IssuedAt: time.Now(),
|
|
ExpiresAt: exp,
|
|
},
|
|
expired: false,
|
|
},
|
|
{
|
|
desc: "expired key",
|
|
key: auth.Key{
|
|
IssuedAt: time.Now().UTC().Add(2 * time.Minute),
|
|
ExpiresAt: exp1,
|
|
},
|
|
expired: true,
|
|
},
|
|
{
|
|
desc: "user key with no expiration date",
|
|
key: auth.Key{
|
|
IssuedAt: time.Now(),
|
|
},
|
|
expired: true,
|
|
},
|
|
{
|
|
desc: "API key with no expiration date",
|
|
key: auth.Key{
|
|
IssuedAt: time.Now(),
|
|
Type: auth.APIKey,
|
|
},
|
|
expired: false,
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
res := tc.key.Expired()
|
|
assert.Equal(t, tc.expired, res, fmt.Sprintf("%s: expected %t got %t\n", tc.desc, tc.expired, res))
|
|
}
|
|
}
|