7fde8b908a
* Light client implementation with get-info and list-buckets commands * Fix client package name * Fix go.mod to work with vgo * Use single `fmt.Printf` for `get-info` output * Use unnamed import to client package * Simplify usage of sha256 and sha512 sums * Remove obsolete test code * Use helper structs for unmarshalling bridge info * Remove LGPL license files and adjust copyright headers * Use github.com/zeebo/errs * Use httptest for test http server * Use viper for env var management * Nested struct for swagger * Add github.com/zeebo/errs to go.mod * More bucket tests * word wrap long line * Use zeebo/errs for crypto errors
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
// Copyright (C) 2018 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package client
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
const testMnemonic = "uncle obtain april oxygen cover patient layer abuse off text royal normal"
|
|
|
|
func TestDecryptBucketName(t *testing.T) {
|
|
for i, tt := range []struct {
|
|
encryptedName string
|
|
mnemonic string
|
|
decryptedName string
|
|
errString string
|
|
}{
|
|
{"", "", "", "Invalid mnemonic"},
|
|
{"", testMnemonic, "", "Invalid encrypted name"},
|
|
{testEncryptedBucketName, "", "", "Invalid mnemonic"},
|
|
{testEncryptedBucketName, testMnemonic, testDecryptedBucketName, ""},
|
|
{testEncryptedBucketNameDiffMnemonic, testMnemonic, "", "cipher: message authentication failed"},
|
|
} {
|
|
decryptedName, err := decryptBucketName(tt.encryptedName, tt.mnemonic)
|
|
errTag := fmt.Sprintf("Test case #%d", i)
|
|
if tt.errString != "" {
|
|
assert.EqualError(t, err, tt.errString, errTag)
|
|
continue
|
|
}
|
|
if assert.NoError(t, err, errTag) {
|
|
assert.Equal(t, tt.decryptedName, decryptedName, errTag)
|
|
}
|
|
}
|
|
}
|