summaryrefslogtreecommitdiff
path: root/internal/authentication/cached_test.go
blob: a60fc3b999f90e2ef8e1997c9b32d767fc21e600 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package authentication

import (
	"crypto/sha256"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestNewCredentialCacheHMAC(t *testing.T) {
	cache := NewCredentialCacheHMAC(sha256.New, time.Second*2)

	require.NoError(t, cache.Put("abc", "123"))

	var valid, found bool

	valid, found = cache.Valid("abc", "123")

	assert.True(t, found)
	assert.True(t, valid)

	valid, found = cache.Valid("abc", "123")

	assert.True(t, found)
	assert.True(t, valid)

	time.Sleep(time.Second * 2)

	valid, found = cache.Valid("abc", "123")

	assert.False(t, found)
	assert.False(t, valid)
}