AuthToken Tests now use recently added TestAuthMethod and TestAccount (#226)

This commit is contained in:
Todd Knight authored and GitHub committed 2020-07-31 11:43:03 -07:00
1 parent 5ceb335466
commit 41b2d36d98
13 files changed
+207 -176

No files matched your search

-37
View File
@@ -7,47 +7,10 @@ import (
"github.com/hashicorp/watchtower/internal/auth/password/store"
"github.com/hashicorp/watchtower/internal/db"
"github.com/hashicorp/watchtower/internal/iam"
"github.com/jinzhu/gorm"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func testAuthMethods(t *testing.T, conn *gorm.DB, count int) []*AuthMethod {
t.Helper()
assert, require := assert.New(t), require.New(t)
w := db.New(conn)
org, _ := iam.TestScopes(t, conn)
var auts []*AuthMethod
for i := 0; i < count; i++ {
cat, err := NewAuthMethod(org.GetPublicId())
assert.NoError(err)
require.NotNil(cat)
id, err := newAuthMethodId()
assert.NoError(err)
require.NotEmpty(id)
cat.PublicId = id
conf := NewArgon2Configuration()
require.NotNil(conf)
conf.PrivateId, err = newArgon2ConfigurationId()
require.NoError(err)
conf.PasswordMethodId = cat.PublicId
cat.PasswordConfId = conf.PrivateId
ctx := context.Background()
_, err2 := w.DoTx(ctx, db.StdRetryCnt, db.ExpBackoff{},
func(_ db.Reader, iw db.Writer) error {
require.NoError(iw.Create(ctx, conf))
return iw.Create(ctx, cat)
},
)
require.NoError(err2)
auts = append(auts, cat)
}
return auts
}
func TestAuthMethod_New(t *testing.T) {
conn, _ := db.TestSetup(t, "postgres")