Files
threshold/internal/auth/password/account_test.go
T
Jeff Mitchell 74544f6324 Encrypt tokens on the way out and decrypt on the way in (#302)
* Encrypt tokens on the way out and decrypt on the way in

This isn't a security feature related to tokens specifically; it's so
that we can discard cryptographically bad tokens before we ever hit the
DB. This way we can't pass through a DDoS to the database due to
fetching obviously invalid token values.

I'm using base58 to encode the resulting value as there aren't great
base62 options, and allowing base64 / and + values can hamper usability
by creating copying/highlighting breaks.
2020-08-25 00:20:50 -04:00

115 lines
2.2 KiB
Go

package password
import (
"testing"
"github.com/hashicorp/boundary/internal/auth/password/store"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/iam"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAccount_New(t *testing.T) {
conn, _ := db.TestSetup(t, "postgres")
wrapper := db.TestWrapper(t)
o, _ := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
auts := TestAuthMethods(t, conn, o.GetPublicId(), 1)
aut := auts[0]
type args struct {
authMethodId string
opts []Option
}
var tests = []struct {
name string
args args
want *Account
wantErr bool
}{
{
name: "blank-authMethodId",
args: args{
authMethodId: "",
},
want: nil,
wantErr: true,
},
{
name: "valid-no-options",
args: args{
authMethodId: aut.GetPublicId(),
},
want: &Account{
Account: &store.Account{
AuthMethodId: aut.GetPublicId(),
},
},
},
{
name: "valid-with-user-name",
args: args{
authMethodId: aut.GetPublicId(),
opts: []Option{
WithLoginName("kazmierczak1"),
},
},
want: &Account{
Account: &store.Account{
AuthMethodId: aut.GetPublicId(),
LoginName: "kazmierczak1",
},
},
},
{
name: "valid-with-name",
args: args{
authMethodId: aut.GetPublicId(),
opts: []Option{
WithName("test-name"),
},
},
want: &Account{
Account: &store.Account{
AuthMethodId: aut.GetPublicId(),
Name: "test-name",
},
},
},
{
name: "valid-with-description",
args: args{
authMethodId: aut.GetPublicId(),
opts: []Option{
WithDescription("test-description"),
},
},
want: &Account{
Account: &store.Account{
AuthMethodId: aut.GetPublicId(),
Description: "test-description",
},
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
got, err := NewAccount(tt.args.authMethodId, tt.args.opts...)
if tt.wantErr {
assert.Error(err)
require.Nil(got)
return
}
assert.NoError(err)
require.NotNil(got)
assert.Emptyf(got.PublicId, "PublicId set")
assert.Equal(tt.want, got)
})
}
}