refactor: Update internal/db and oplog to use go-dbw package for database operations. (#1785)

* chore: Add new dbw dependency

* refactor: Convert to use dbw.DB

* refactor (db): Change GetTicket(...) signature

* feature (db tests): Added TestDeleteWhere(...)
Adding this allows us to eliminate a leak of the gorm library

* refactor: Add ctx to ScanRows(...) signature
This is required to refactor all the deprecated errors pkg calls.
This refactor required adding a context to quite a few call chains
and in particular the job scheduler bits

* feature (db/tests): Add support for test opt: WithTestLogLevel(...)
This test only option allows callers to specify a log level for the
underlying db package (where supported/applicable) when calling
TestSetup(...)

* refactor (db): Simplify Db type
Only store the underlying *DB and create the *RW on demand when
needed.

* refactor (oplog): Port to using dbw pkg for db operations

* refactor (db): Remove gormDB(...) func

* tests (db): Add unit tests for TestDeleteWhere(...)

* chore: make fmt changes to formatting
This commit is contained in:
Jim authored and GitHub committed 2022-01-05 14:38:38 -05:00
1 parent 002d004114
commit 591ec476e7
160 files changed
+4369 -3164

No files matched your search

+4 -4
View File
@@ -68,7 +68,7 @@ select count(*) from test_auth_method where public_id = @public_id
require.NoError(err)
defer rows.Close()
for rows.Next() {
err := rw.ScanRows(rows, &count)
err := rw.ScanRows(ctx, rows, &count)
require.NoError(err)
}
assert.Equal(1, count.Count)
@@ -78,7 +78,7 @@ select count(*) from test_auth_method where public_id = @public_id
require.NoError(err)
defer rows.Close()
for rows.Next() {
err := rw.ScanRows(rows, &count)
err := rw.ScanRows(ctx, rows, &count)
require.NoError(err)
}
assert.Equal(1, count.Count)
@@ -150,7 +150,7 @@ values
require.NoError(err)
defer rows.Close()
for rows.Next() {
err := rw.ScanRows(rows, &count)
err := rw.ScanRows(ctx, rows, &count)
require.NoError(err)
}
assert.Equal(1, count.Count)
@@ -160,7 +160,7 @@ values
require.NoError(err)
defer rows.Close()
for rows.Next() {
err := rw.ScanRows(rows, &count)
err := rw.ScanRows(ctx, rows, &count)
require.NoError(err)
}
assert.Equal(1, count.Count)
+4 -5
View File
@@ -127,7 +127,7 @@ func TestAccountClaimMap_Create(t *testing.T) {
assert.NoError(err)
}
found := AllocAccountClaimMap()
require.NoError(rw.LookupWhere(ctx, &found, "oidc_method_id = ? and to_claim = ?", tt.args.authMethodId, tt.args.to))
require.NoError(rw.LookupWhere(ctx, &found, "oidc_method_id = ? and to_claim = ?", []interface{}{tt.args.authMethodId, tt.args.to}))
assert.Equal(got, &found)
}
})
@@ -145,9 +145,8 @@ func TestAccountClaimMap_Delete(t *testing.T) {
databaseWrapper, err := kmsCache.GetWrapper(context.Background(), org.PublicId, kms.KeyPurposeDatabase)
require.NoError(t, err)
testAuthMethod :=
TestAuthMethod(t, conn, databaseWrapper, org.PublicId, InactiveState, "alice_rp", "my-dogs-name",
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]), WithAudClaims("alice.com")) // seed an extra callback url to just make sure the delete only gets the right num of rows
testAuthMethod := TestAuthMethod(t, conn, databaseWrapper, org.PublicId, InactiveState, "alice_rp", "my-dogs-name",
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]), WithAudClaims("alice.com")) // seed an extra callback url to just make sure the delete only gets the right num of rows
testResource := func(authMethodId string, fromClaim string, toClaim AccountToClaim) *AccountClaimMap {
c, err := NewAccountClaimMap(context.TODO(), authMethodId, fromClaim, toClaim)
@@ -209,7 +208,7 @@ func TestAccountClaimMap_Delete(t *testing.T) {
}
assert.Equal(tt.wantRowsDeleted, deletedRows)
found := AllocAccountClaimMap()
err = rw.LookupWhere(ctx, &found, "oidc_method_id = ? and to_claim = ?", tt.AccountClaimMap.OidcMethodId, tt.AccountClaimMap.ToClaim)
err = rw.LookupWhere(ctx, &found, "oidc_method_id = ? and to_claim = ?", []interface{}{tt.AccountClaimMap.OidcMethodId, tt.AccountClaimMap.ToClaim})
assert.True(errors.IsNotFoundError(err))
})
}
+10 -11
View File
@@ -229,17 +229,16 @@ func TestAccount_Delete(t *testing.T) {
databaseWrapper, err := kmsCache.GetWrapper(context.Background(), org.PublicId, kms.KeyPurposeDatabase)
require.NoError(t, err)
testAuthMethod :=
TestAuthMethod(
t,
conn,
databaseWrapper,
org.PublicId,
InactiveState,
"alice_rp",
"my-dogs-name",
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]),
WithIssuer(TestConvertToUrls(t, "https://alice.com")[0]))
testAuthMethod := TestAuthMethod(
t,
conn,
databaseWrapper,
org.PublicId,
InactiveState,
"alice_rp",
"my-dogs-name",
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]),
WithIssuer(TestConvertToUrls(t, "https://alice.com")[0]))
testResource := func(authMethodId string, subject string) *Account {
u, err := url.Parse(testAuthMethod.GetIssuer())
+4 -5
View File
@@ -113,7 +113,7 @@ func TestAudClaim_Create(t *testing.T) {
assert.NoError(err)
}
found := AllocAudClaim()
require.NoError(rw.LookupWhere(ctx, &found, "oidc_method_id = ? and aud_claim = ?", tt.args.authMethodId, tt.args.aud))
require.NoError(rw.LookupWhere(ctx, &found, "oidc_method_id = ? and aud_claim = ?", []interface{}{tt.args.authMethodId, tt.args.aud}))
assert.Equal(got, &found)
}
})
@@ -132,9 +132,8 @@ func TestAudClaim_Delete(t *testing.T) {
databaseWrapper, err := kmsCache.GetWrapper(context.Background(), org.PublicId, kms.KeyPurposeDatabase)
require.NoError(t, err)
testAuthMethod :=
TestAuthMethod(t, conn, databaseWrapper, org.PublicId, InactiveState, "alice_rp", "my-dogs-name",
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]), WithAudClaims("alice.com")) // seed an extra callback url to just make sure the delete only gets the right num of rows
testAuthMethod := TestAuthMethod(t, conn, databaseWrapper, org.PublicId, InactiveState, "alice_rp", "my-dogs-name",
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]), WithAudClaims("alice.com")) // seed an extra callback url to just make sure the delete only gets the right num of rows
testResource := func(authMethodId string, AudClaim string) *AudClaim {
c, err := NewAudClaim(ctx, authMethodId, AudClaim)
@@ -192,7 +191,7 @@ func TestAudClaim_Delete(t *testing.T) {
}
assert.Equal(tt.wantRowsDeleted, deletedRows)
found := AllocAudClaim()
err = rw.LookupWhere(ctx, &found, "oidc_method_id = ? and aud_claim = ?", tt.AudClaim.OidcMethodId, tt.AudClaim.Aud)
err = rw.LookupWhere(ctx, &found, "oidc_method_id = ? and aud_claim = ?", []interface{}{tt.AudClaim.OidcMethodId, tt.AudClaim.Aud})
assert.True(errors.IsNotFoundError(err))
})
}
+3 -4
View File
@@ -112,7 +112,7 @@ func TestCertificate_Create(t *testing.T) {
assert.NoError(err)
}
found := AllocCertificate()
require.NoError(rw.LookupWhere(ctx, &found, "oidc_method_id = ? and certificate = ?", tt.args.authMethodId, tt.args.certificate))
require.NoError(rw.LookupWhere(ctx, &found, "oidc_method_id = ? and certificate = ?", []interface{}{tt.args.authMethodId, tt.args.certificate}))
assert.Equal(got, &found)
}
})
@@ -133,8 +133,7 @@ func TestCertificate_Delete(t *testing.T) {
cert, _ := testGenerateCA(t, "localhost")
testAuthMethod :=
TestAuthMethod(t, conn, databaseWrapper, org.PublicId, InactiveState, "alice_rp", "my-dogs-name", WithApiUrl(TestConvertToUrls(t, "https://apiurl.com")[0]), WithCertificates(cert)) // seed an extra callback url to just make sure the delete only gets the right num of rows
testAuthMethod := TestAuthMethod(t, conn, databaseWrapper, org.PublicId, InactiveState, "alice_rp", "my-dogs-name", WithApiUrl(TestConvertToUrls(t, "https://apiurl.com")[0]), WithCertificates(cert)) // seed an extra callback url to just make sure the delete only gets the right num of rows
// make another test cert
_, pem2 := testGenerateCA(t, "localhost")
@@ -197,7 +196,7 @@ func TestCertificate_Delete(t *testing.T) {
}
assert.Equal(tt.wantRowsDeleted, deletedRows)
found := AllocCertificate()
err = rw.LookupWhere(ctx, &found, "oidc_method_id = ? and certificate = ?", tt.Certificate.OidcMethodId, tt.Certificate.Cert)
err = rw.LookupWhere(ctx, &found, "oidc_method_id = ? and certificate = ?", []interface{}{tt.Certificate.OidcMethodId, tt.Certificate.Cert})
assert.True(errors.IsNotFoundError(err))
})
}
+4 -5
View File
@@ -115,7 +115,7 @@ func TestClaimsScope_Create(t *testing.T) {
}
assert.NoError(err)
found := AllocClaimsScope()
require.NoError(rw.LookupWhere(ctx, &found, "oidc_method_id = ? and scope = ?", tt.args.authMethodId, tt.args.claimsScope))
require.NoError(rw.LookupWhere(ctx, &found, "oidc_method_id = ? and scope = ?", []interface{}{tt.args.authMethodId, tt.args.claimsScope}))
}
})
}
@@ -133,9 +133,8 @@ func TestClaimsScope_Delete(t *testing.T) {
databaseWrapper, err := kmsCache.GetWrapper(context.Background(), org.PublicId, kms.KeyPurposeDatabase)
require.NoError(t, err)
testAuthMethod :=
TestAuthMethod(t, conn, databaseWrapper, org.PublicId, InactiveState, "alice_rp", "my-dogs-name",
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]), WithAudClaims("alice.com")) // seed an extra callback url to just make sure the delete only gets the right num of rows
testAuthMethod := TestAuthMethod(t, conn, databaseWrapper, org.PublicId, InactiveState, "alice_rp", "my-dogs-name",
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]), WithAudClaims("alice.com")) // seed an extra callback url to just make sure the delete only gets the right num of rows
testResource := func(authMethodId string, claimsScope string) *ClaimsScope {
c, err := NewClaimsScope(ctx, authMethodId, claimsScope)
@@ -193,7 +192,7 @@ func TestClaimsScope_Delete(t *testing.T) {
}
assert.Equal(tt.wantRowsDeleted, deletedRows)
found := AllocClaimsScope()
err = rw.LookupWhere(ctx, &found, "oidc_method_id = ? and scope = ?", tt.claimsScope.OidcMethodId, tt.claimsScope.Scope)
err = rw.LookupWhere(ctx, &found, "oidc_method_id = ? and scope = ?", []interface{}{tt.claimsScope.OidcMethodId, tt.claimsScope.Scope})
assert.True(errors.IsNotFoundError(err))
})
}
+9 -9
View File
@@ -105,7 +105,7 @@ func TestAudClaim_ImmutableFields(t *testing.T) {
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]), WithAudClaims("alice.com"))
new := AllocAudClaim()
require.NoError(t, rw.LookupWhere(ctx, &new, "oidc_method_id = ? and aud_claim = ?", am.PublicId, "alice.com"))
require.NoError(t, rw.LookupWhere(ctx, &new, "oidc_method_id = ? and aud_claim = ?", []interface{}{am.PublicId, "alice.com"}))
tests := []struct {
name string
@@ -147,7 +147,7 @@ func TestAudClaim_ImmutableFields(t *testing.T) {
orig := new.Clone()
orig.SetTableName(defaultAuthMethodTableName)
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and aud_claim = ?", orig.OidcMethodId, orig.Aud))
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and aud_claim = ?", []interface{}{orig.OidcMethodId, orig.Aud}))
require.NoError(err)
@@ -158,7 +158,7 @@ func TestAudClaim_ImmutableFields(t *testing.T) {
after := new.Clone()
after.SetTableName(defaultAuthMethodTableName)
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and aud_claim = ?", after.OidcMethodId, after.Aud))
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and aud_claim = ?", []interface{}{after.OidcMethodId, after.Aud}))
assert.True(proto.Equal(orig, after))
})
@@ -186,7 +186,7 @@ func TestCertificate_ImmutableFields(t *testing.T) {
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]), WithCertificates(x509))
new := AllocCertificate()
require.NoError(t, rw.LookupWhere(ctx, &new, "oidc_method_id = ? and certificate = ?", am.PublicId, pem))
require.NoError(t, rw.LookupWhere(ctx, &new, "oidc_method_id = ? and certificate = ?", []interface{}{am.PublicId, pem}))
tests := []struct {
name string
@@ -228,7 +228,7 @@ func TestCertificate_ImmutableFields(t *testing.T) {
orig := new.Clone()
orig.SetTableName(defaultAuthMethodTableName)
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and certificate = ?", orig.OidcMethodId, orig.Cert))
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and certificate = ?", []interface{}{orig.OidcMethodId, orig.Cert}))
require.NoError(err)
@@ -239,7 +239,7 @@ func TestCertificate_ImmutableFields(t *testing.T) {
after := new.Clone()
after.SetTableName(defaultAuthMethodTableName)
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and certificate = ?", after.OidcMethodId, after.Cert))
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and certificate = ?", []interface{}{after.OidcMethodId, after.Cert}))
assert.True(proto.Equal(orig, after))
})
@@ -263,7 +263,7 @@ func TestSigningAlg_ImmutableFields(t *testing.T) {
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]), WithSigningAlgs(RS256))
new := AllocSigningAlg()
require.NoError(t, rw.LookupWhere(ctx, &new, "oidc_method_id = ? and signing_alg_name = ?", am.PublicId, RS256))
require.NoError(t, rw.LookupWhere(ctx, &new, "oidc_method_id = ? and signing_alg_name = ?", []interface{}{am.PublicId, RS256}))
tests := []struct {
name string
@@ -305,7 +305,7 @@ func TestSigningAlg_ImmutableFields(t *testing.T) {
orig := new.Clone()
orig.SetTableName(defaultAuthMethodTableName)
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and signing_alg_name = ?", orig.OidcMethodId, orig.Alg))
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and signing_alg_name = ?", []interface{}{orig.OidcMethodId, orig.Alg}))
require.NoError(err)
@@ -316,7 +316,7 @@ func TestSigningAlg_ImmutableFields(t *testing.T) {
after := new.Clone()
after.SetTableName(defaultAuthMethodTableName)
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and signing_alg_name = ?", after.OidcMethodId, after.Alg))
require.NoError(rw.LookupWhere(ctx, &new, "oidc_method_id = ? and signing_alg_name = ?", []interface{}{after.OidcMethodId, after.Alg}))
assert.True(proto.Equal(orig, after))
})
@@ -947,7 +947,7 @@ func TestRepository_UpdateAccount(t *testing.T) {
chgFn: combine(nonExistentPublicId(), changeName("updating-non-existent-Account-test-update-name-repo")),
masks: []string{NameField},
wantIsErr: errors.RecordNotFound,
wantErrMsg: "oidc.(Repository).UpdateAccount: abcd_OOOOOOOOOO: db.DoTx: oidc.(Repository).UpdateAccount: db.Update: db.lookupAfterWrite: db.LookupById: record not found, search issue: error #1100",
wantErrMsg: "oidc.(Repository).UpdateAccount: abcd_OOOOOOOOOO: db.DoTx: oidc.(Repository).UpdateAccount: db.Update: record not found, search issue: error #1100: dbw.Update: dbw.lookupAfterWrite: dbw.LookupById: record not found",
},
{
name: "empty-field-mask",
+3 -3
View File
@@ -176,7 +176,7 @@ func (r *Repository) upsertAccount(ctx context.Context, am *AuthMethod, IdTokenC
var rowCnt int
for rows.Next() {
rowCnt += 1
err = r.reader.ScanRows(rows, &result)
err = r.reader.ScanRows(ctx, rows, &result)
if err != nil {
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to scan rows for account"))
}
@@ -184,7 +184,7 @@ func (r *Repository) upsertAccount(ctx context.Context, am *AuthMethod, IdTokenC
if rowCnt > 1 {
return errors.New(ctx, errors.MultipleRecords, op, fmt.Sprintf("expected 1 row but got: %d", rowCnt))
}
if err := reader.LookupWhere(ctx, &updatedAcct, "auth_method_id = ? and issuer = ? and subject = ?", am.PublicId, iss, sub); err != nil {
if err := reader.LookupWhere(ctx, &updatedAcct, "auth_method_id = ? and issuer = ? and subject = ?", []interface{}{am.PublicId, iss, sub}); err != nil {
return errors.Wrap(ctx, err, op, errors.WithMsg(fmt.Sprintf("unable to look up auth oidc account for: %s / %s / %s", am.PublicId, iss, sub)))
}
// include the version incase of predictable account public ids based on a calculation using authmethod id and subject
@@ -238,7 +238,7 @@ func upsertOplog(ctx context.Context, w db.Writer, oplogWrapper wrapping.Wrapper
if operation == oplog.OpType_OP_TYPE_UPDATE && len(fieldMasks) == 0 && len(nullMasks) == 0 {
return errors.New(ctx, errors.InvalidParameter, op, "update operations must specify field masks and/or null masks")
}
ticket, err := w.GetTicket(acct)
ticket, err := w.GetTicket(ctx, acct)
if err != nil {
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to get ticket"))
}
@@ -72,7 +72,7 @@ func (r *Repository) CreateAuthMethod(ctx context.Context, am *AuthMethod, opt .
db.ExpBackoff{},
func(_ db.Reader, w db.Writer) error {
msgs := make([]*oplog.Message, 0, 5)
ticket, err := w.GetTicket(am)
ticket, err := w.GetTicket(ctx, am)
if err != nil {
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to get ticket"))
}
@@ -256,7 +256,7 @@ func (r *Repository) UpdateAuthMethod(ctx context.Context, am *AuthMethod, versi
db.ExpBackoff{},
func(reader db.Reader, w db.Writer) error {
msgs := make([]*oplog.Message, 0, 7) // AuthMethod, Algs*2, Certs*2, Audiences*2
ticket, err := w.GetTicket(am)
ticket, err := w.GetTicket(ctx, am)
if err != nil {
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to get ticket"))
}
@@ -78,7 +78,7 @@ func (r *Repository) SetManagedGroupMemberships(ctx context.Context, am *AuthMet
// We need a ticket, which won't be redeemed until all the other
// writes are successful. We can't just use a single ticket because
// we need to write oplog entries for deletes and adds.
mgTicket, err := w.GetTicket(ticketMg)
mgTicket, err := w.GetTicket(ctx, ticketMg)
if err != nil {
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to get ticket for oidc managed groups"))
}
@@ -703,7 +703,7 @@ func TestRepository_UpdateManagedGroup(t *testing.T) {
chgFn: combine(nonExistentPublicId(), changeName("updating-non-existent-ManagedGroup-test-update-name-repo")),
masks: []string{NameField},
wantIsErr: errors.RecordNotFound,
wantErrMsg: "oidc.(Repository).UpdateManagedGroup: abcd_OOOOOOOOOO: db.DoTx: oidc.(Repository).UpdateManagedGroup: db.Update: db.lookupAfterWrite: db.LookupById: record not found, search issue: error #1100",
wantErrMsg: "oidc.(Repository).UpdateManagedGroup: abcd_OOOOOOOOOO: db.DoTx: oidc.(Repository).UpdateManagedGroup: db.Update: record not found, search issue: error #1100: dbw.Update: dbw.lookupAfterWrite: dbw.LookupById: record not found",
},
{
name: "empty-field-mask",
+5 -3
View File
@@ -35,6 +35,8 @@ func Test_Callback(t *testing.T) {
rootWrapper := db.TestWrapper(t)
kmsCache := kms.TestKms(t, conn, rootWrapper)
testCtx := context.Background()
// some standard factories for unit tests which
// are used in the Callback(...) call
iamRepoFn := func() (*iam.Repository, error) {
@@ -373,7 +375,7 @@ func Test_Callback(t *testing.T) {
// make sure the account was updated properly
var acct Account
err = rw.LookupWhere(ctx, &acct, "auth_method_id = ? and subject = ?", tt.am.PublicId, tt.wantSubject)
err = rw.LookupWhere(ctx, &acct, "auth_method_id = ? and subject = ?", []interface{}{tt.am.PublicId, tt.wantSubject})
require.NoError(err)
assert.Equal(tt.wantInfoEmail, acct.Email)
assert.Equal(tt.wantInfoName, acct.FullName)
@@ -393,7 +395,7 @@ func Test_Callback(t *testing.T) {
require.NoError(err)
oplogWrapper, err := kmsCache.GetWrapper(ctx, tt.am.ScopeId, kms.KeyPurposeOplog)
require.NoError(err)
types, err := oplog.NewTypeCatalog(
types, err := oplog.NewTypeCatalog(testCtx,
oplog.Type{Interface: new(store.Account), Name: "auth_oidc_account"},
oplog.Type{Interface: new(iamStore.User), Name: "iam_user"},
oplog.Type{Interface: new(authStore.Account), Name: "auth_account"},
@@ -407,7 +409,7 @@ func Test_Callback(t *testing.T) {
e.Cipherer = oplogWrapper
err := e.DecryptData(ctx)
require.NoError(err)
msgs, err := e.UnmarshalData(types)
msgs, err := e.UnmarshalData(ctx, types)
require.NoError(err)
for _, m := range msgs {
switch m.TypeName {
+13 -14
View File
@@ -122,7 +122,7 @@ func TestSigningAlg_Create(t *testing.T) {
assert.NoError(err)
}
found := AllocSigningAlg()
require.NoError(rw.LookupWhere(ctx, &found, "oidc_method_id = ? and signing_alg_name = ?", tt.args.authMethodId, string(tt.args.alg)))
require.NoError(rw.LookupWhere(ctx, &found, "oidc_method_id = ? and signing_alg_name = ?", []interface{}{tt.args.authMethodId, string(tt.args.alg)}))
assert.Equal(got, &found)
}
})
@@ -141,18 +141,17 @@ func TestSigningAlg_Delete(t *testing.T) {
databaseWrapper, err := kmsCache.GetWrapper(context.Background(), org.PublicId, kms.KeyPurposeDatabase)
require.NoError(t, err)
testAuthMethod :=
TestAuthMethod(
t,
conn,
databaseWrapper,
org.PublicId,
InactiveState,
"alice_rp",
"my-dogs-name",
WithIssuer(TestConvertToUrls(t, "https://alice.com")[0]),
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]),
WithSigningAlgs(RS256)) // seed an extra callback url to just make sure the delete only gets the right num of rows
testAuthMethod := TestAuthMethod(
t,
conn,
databaseWrapper,
org.PublicId,
InactiveState,
"alice_rp",
"my-dogs-name",
WithIssuer(TestConvertToUrls(t, "https://alice.com")[0]),
WithApiUrl(TestConvertToUrls(t, "https://api.com")[0]),
WithSigningAlgs(RS256)) // seed an extra callback url to just make sure the delete only gets the right num of rows
testResource := func(authMethodId string, signingAlg Alg) *SigningAlg {
c, err := NewSigningAlg(ctx, authMethodId, signingAlg)
@@ -210,7 +209,7 @@ func TestSigningAlg_Delete(t *testing.T) {
}
assert.Equal(tt.wantRowsDeleted, deletedRows)
found := AllocSigningAlg()
err = rw.LookupWhere(ctx, &found, "oidc_method_id = ? and signing_alg_name = ?", tt.SigningAlg.OidcMethodId, tt.SigningAlg.String())
err = rw.LookupWhere(ctx, &found, "oidc_method_id = ? and signing_alg_name = ?", []interface{}{tt.SigningAlg.OidcMethodId, tt.SigningAlg.String()})
assert.Truef(errors.IsNotFoundError(err), "unexpected error: %s", err.Error())
})
}
@@ -697,7 +697,7 @@ func TestRepository_UpdateAccount(t *testing.T) {
chgFn: combine(nonExistentPublicId(), changeName("test-update-name-repo")),
masks: []string{"Name"},
wantIsErr: errors.RecordNotFound,
wantErrMsg: "password.(Repository).UpdateAccount: abcd_OOOOOOOOOO: db.DoTx: password.(Repository).UpdateAccount: db.Update: db.lookupAfterWrite: db.LookupById: record not found, search issue: error #1100",
wantErrMsg: "password.(Repository).UpdateAccount: abcd_OOOOOOOOOO: db.DoTx: password.(Repository).UpdateAccount: db.Update: record not found, search issue: error #1100: dbw.Update: dbw.lookupAfterWrite: dbw.LookupById: record not found",
},
{
name: "empty-field-mask",
@@ -92,7 +92,7 @@ func (r *Repository) setArgon2Conf(ctx context.Context, scopeId string, c *Argon
_, err = r.writer.DoTx(ctx, db.StdRetryCnt, db.ExpBackoff{},
func(rr db.Reader, w db.Writer) error {
where, args := c.whereDup()
if err := rr.LookupWhere(ctx, newArgon2Conf, where, args...); err != nil {
if err := rr.LookupWhere(ctx, newArgon2Conf, where, args); err != nil {
if !errors.IsNotFoundError(err) {
return errors.Wrap(ctx, err, op)
}
@@ -134,7 +134,7 @@ func (c *currentConfig) TableName() string {
func (r *Repository) currentConfig(ctx context.Context, authMethodId string) (*currentConfig, error) {
const op = "password.(Repository).currentConfig"
var cc currentConfig
if err := r.reader.LookupWhere(ctx, &cc, "password_method_id = ?", authMethodId); err != nil {
if err := r.reader.LookupWhere(ctx, &cc, "password_method_id = ?", []interface{}{authMethodId}); err != nil {
return nil, errors.Wrap(ctx, err, op)
}
return &cc, nil
@@ -151,7 +151,7 @@ func (r *Repository) currentConfigForAccount(ctx context.Context, accountId stri
defer rows.Close()
for rows.Next() {
var conf currentConfig
if err := r.reader.ScanRows(rows, &conf); err != nil {
if err := r.reader.ScanRows(ctx, rows, &conf); err != nil {
return nil, errors.Wrap(ctx, err, op)
}
confs = append(confs, conf)
@@ -221,7 +221,7 @@ func (r *Repository) authenticate(ctx context.Context, scopeId, authMethodId, lo
defer rows.Close()
for rows.Next() {
var aa authAccount
if err := r.reader.ScanRows(rows, &aa); err != nil {
if err := r.reader.ScanRows(ctx, rows, &aa); err != nil {
return nil, errors.Wrap(ctx, err, op)
}
accts = append(accts, aa)
@@ -316,7 +316,7 @@ func (r *Repository) SetPassword(ctx context.Context, scopeId, accountId, passwo
acct = updatedAccount
oldCred := allocCredential()
if err := rr.LookupWhere(ctx, &oldCred, "password_account_id = ?", accountId); err != nil {
if err := rr.LookupWhere(ctx, &oldCred, "password_account_id = ?", []interface{}{accountId}); err != nil {
if !errors.IsNotFoundError(err) {
return errors.Wrap(ctx, err, op)
}
@@ -171,7 +171,7 @@ func TestRepository_AuthenticateRehash(t *testing.T) {
// Get the credential for the new account and verify the KDF used the
// original argon2 configuration
origCred := &Argon2Credential{Argon2Credential: &store.Argon2Credential{}}
require.NoError(rw.LookupWhere(ctx, origCred, "password_account_id = ?", origAcct.PublicId))
require.NoError(rw.LookupWhere(ctx, origCred, "password_account_id = ?", []interface{}{origAcct.PublicId}))
assert.Equal(origAcct.PublicId, origCred.PasswordAccountId)
assert.Equal(origConfId, origCred.PasswordConfId)
assert.Equal(origCred.CreateTime, origCred.UpdateTime, "create and update times are equal")