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"
|
2020-12-26 01:16:43 +00:00
|
|
|
"storj.io/storj/private/multinodeauth"
|
2020-10-19 12:11:25 +01:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2020-12-26 01:16:43 +00:00
|
|
|
func TestAPIKeysDB(t *testing.T) {
|
2020-10-19 12:11:25 +01:00
|
|
|
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
|
2020-12-26 01:16:43 +00:00
|
|
|
apiKeys := db.APIKeys()
|
|
|
|
secret, err := multinodeauth.NewSecret()
|
2020-10-19 12:11:25 +01:00
|
|
|
assert.NoError(t, err)
|
2020-12-26 01:16:43 +00:00
|
|
|
secret2, err := multinodeauth.NewSecret()
|
2020-10-19 12:11:25 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2020-12-26 01:16:43 +00:00
|
|
|
t.Run("Store", func(t *testing.T) {
|
|
|
|
err := apiKeys.Store(ctx, apikeys.APIKey{
|
|
|
|
Secret: secret,
|
2020-10-19 12:11:25 +01:00
|
|
|
CreatedAt: time.Now().UTC(),
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
2020-12-26 01:16:43 +00:00
|
|
|
t.Run("Check", func(t *testing.T) {
|
|
|
|
err := apiKeys.Check(ctx, secret)
|
2020-10-19 12:11:25 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2020-12-26 01:16:43 +00:00
|
|
|
err = apiKeys.Check(ctx, secret2)
|
2020-10-19 12:11:25 +01:00
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
2020-12-26 01:16:43 +00:00
|
|
|
t.Run("Revoke", func(t *testing.T) {
|
|
|
|
err = apiKeys.Revoke(ctx, secret)
|
2020-10-19 12:11:25 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2020-12-26 01:16:43 +00:00
|
|
|
err = apiKeys.Check(ctx, secret)
|
2020-10-19 12:11:25 +01:00
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|