2020-10-19 12:11:25 +01:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2020-11-09 15:22:30 +00:00
|
|
|
package apikeys_test
|
2020-10-19 12:11:25 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/zeebo/assert"
|
|
|
|
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/storj/storagenode"
|
2020-11-09 15:22:30 +00:00
|
|
|
"storj.io/storj/storagenode/apikeys"
|
2020-10-19 12:11:25 +01:00
|
|
|
"storj.io/storj/storagenode/storagenodedb/storagenodedbtest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSecretDB(t *testing.T) {
|
|
|
|
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
|
|
|
|
secrets := db.Secret()
|
2020-11-09 15:22:30 +00:00
|
|
|
token, err := apikeys.NewSecret()
|
2020-10-19 12:11:25 +01:00
|
|
|
assert.NoError(t, err)
|
2020-11-09 15:22:30 +00:00
|
|
|
token2, err := apikeys.NewSecret()
|
2020-10-19 12:11:25 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("Test StoreSecret", func(t *testing.T) {
|
2020-11-09 15:22:30 +00:00
|
|
|
err := secrets.Store(ctx, apikeys.APIKey{
|
2020-10-19 12:11:25 +01:00
|
|
|
Secret: token,
|
|
|
|
CreatedAt: time.Now().UTC(),
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test CheckSecret", func(t *testing.T) {
|
|
|
|
err := secrets.Check(ctx, token)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = secrets.Check(ctx, token2)
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test RevokeSecret", func(t *testing.T) {
|
|
|
|
err = secrets.Revoke(ctx, token)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = secrets.Check(ctx, token)
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|