diff options
Diffstat (limited to 'internal/authentication/cached_test.go')
| -rw-r--r-- | internal/authentication/cached_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/authentication/cached_test.go b/internal/authentication/cached_test.go new file mode 100644 index 000000000..a60fc3b99 --- /dev/null +++ b/internal/authentication/cached_test.go @@ -0,0 +1,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) +} |
