Replace and remove ErrNilParameter with ErrInvalidParameter (#295)
This commit is contained in:
1 parent
8f579c75c3
commit
de162c5533
44 files changed
+187
-190
No files matched your search
@@ -123,7 +123,7 @@ func newArgon2Credential(accountId string, password string, conf *Argon2Configur
|
||||
return nil, fmt.Errorf("new: password argon2 credential: no password: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if conf == nil {
|
||||
return nil, fmt.Errorf("new: password argon2 credential: no argon2 configuration: %w", db.ErrNilParameter)
|
||||
return nil, fmt.Errorf("new: password argon2 credential: no argon2 configuration: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
|
||||
id, err := newArgon2CredentialId()
|
||||
|
||||
@@ -349,7 +349,7 @@ func TestArgon2Credential_New(t *testing.T) {
|
||||
conf: nil,
|
||||
},
|
||||
want: nil,
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
wantIsErr: db.ErrInvalidParameter,
|
||||
},
|
||||
{
|
||||
name: "valid-password",
|
||||
|
||||
@@ -25,11 +25,11 @@ type Repository struct {
|
||||
func NewRepository(r db.Reader, w db.Writer, kms *kms.Kms, opt ...Option) (*Repository, error) {
|
||||
switch {
|
||||
case r == nil:
|
||||
return nil, fmt.Errorf("db.Reader: %w", db.ErrNilParameter)
|
||||
return nil, fmt.Errorf("db.Reader: %w", db.ErrInvalidParameter)
|
||||
case w == nil:
|
||||
return nil, fmt.Errorf("db.Writer: %w", db.ErrNilParameter)
|
||||
return nil, fmt.Errorf("db.Writer: %w", db.ErrInvalidParameter)
|
||||
case kms == nil:
|
||||
return nil, fmt.Errorf("kms: %w", db.ErrNilParameter)
|
||||
return nil, fmt.Errorf("kms: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
|
||||
opts := getOpts(opt...)
|
||||
|
||||
@@ -27,10 +27,10 @@ import (
|
||||
// unique within a.AuthMethodId.
|
||||
func (r *Repository) CreateAccount(ctx context.Context, scopeId string, a *Account, opt ...Option) (*Account, error) {
|
||||
if a == nil {
|
||||
return nil, fmt.Errorf("create: password account: %w", db.ErrNilParameter)
|
||||
return nil, fmt.Errorf("create: password account: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if a.Account == nil {
|
||||
return nil, fmt.Errorf("create: password account: embedded Account: %w", db.ErrNilParameter)
|
||||
return nil, fmt.Errorf("create: password account: embedded Account: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if a.AuthMethodId == "" {
|
||||
return nil, fmt.Errorf("create: password account: no auth method id: %w", db.ErrInvalidParameter)
|
||||
@@ -39,7 +39,7 @@ func (r *Repository) CreateAccount(ctx context.Context, scopeId string, a *Accou
|
||||
return nil, fmt.Errorf("create: password account: public id not empty: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if scopeId == "" {
|
||||
return nil, fmt.Errorf("create: password account: scope id empty: %w", db.ErrNilParameter)
|
||||
return nil, fmt.Errorf("create: password account: scope id empty: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if !validLoginName(a.LoginName) {
|
||||
return nil, fmt.Errorf("create: password account: invalid user name: %w", db.ErrInvalidParameter)
|
||||
@@ -157,7 +157,7 @@ func (r *Repository) DeleteAccount(ctx context.Context, scopeId, withPublicId st
|
||||
return db.NoRowsAffected, fmt.Errorf("delete: password account: missing public id: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if scopeId == "" {
|
||||
return db.NoRowsAffected, fmt.Errorf("delete: password account: scope id empty: %w", db.ErrNilParameter)
|
||||
return db.NoRowsAffected, fmt.Errorf("delete: password account: scope id empty: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
ac := allocAccount()
|
||||
ac.PublicId = withPublicId
|
||||
@@ -214,10 +214,10 @@ func validLoginName(u string) bool {
|
||||
// cannot be set to NULL.
|
||||
func (r *Repository) UpdateAccount(ctx context.Context, scopeId string, a *Account, version uint32, fieldMaskPaths []string, opt ...Option) (*Account, int, error) {
|
||||
if a == nil {
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: password account: %w", db.ErrNilParameter)
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: password account: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if a.Account == nil {
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: password account: embedded Account: %w", db.ErrNilParameter)
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: password account: embedded Account: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if a.PublicId == "" {
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: password account: missing public id: %w", db.ErrInvalidParameter)
|
||||
@@ -226,7 +226,7 @@ func (r *Repository) UpdateAccount(ctx context.Context, scopeId string, a *Accou
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: password account: no version supplied: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if scopeId == "" {
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: password account: scope id empty: %w", db.ErrNilParameter)
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: password account: scope id empty: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
|
||||
var changeLoginName bool
|
||||
|
||||
@@ -57,12 +57,12 @@ func TestRepository_CreateAccount(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "nil-Account",
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
wantIsErr: db.ErrInvalidParameter,
|
||||
},
|
||||
{
|
||||
name: "nil-embedded-Account",
|
||||
in: &Account{},
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
wantIsErr: db.ErrInvalidParameter,
|
||||
},
|
||||
{
|
||||
name: "invalid-no-scope-id",
|
||||
@@ -633,7 +633,7 @@ func TestRepository_UpdateAccount(t *testing.T) {
|
||||
},
|
||||
chgFn: makeNil(),
|
||||
masks: []string{"Name", "Description"},
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
wantIsErr: db.ErrInvalidParameter,
|
||||
},
|
||||
{
|
||||
name: "nil-embedded-Account",
|
||||
@@ -642,7 +642,7 @@ func TestRepository_UpdateAccount(t *testing.T) {
|
||||
},
|
||||
chgFn: makeEmbeddedNil(),
|
||||
masks: []string{"Name", "Description"},
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
wantIsErr: db.ErrInvalidParameter,
|
||||
},
|
||||
{
|
||||
name: "no-public-id",
|
||||
|
||||
@@ -24,10 +24,10 @@ import (
|
||||
// unique within m.ScopeId.
|
||||
func (r *Repository) CreateAuthMethod(ctx context.Context, m *AuthMethod, opt ...Option) (*AuthMethod, error) {
|
||||
if m == nil {
|
||||
return nil, fmt.Errorf("create: password auth method: %w", db.ErrNilParameter)
|
||||
return nil, fmt.Errorf("create: password auth method: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if m.AuthMethod == nil {
|
||||
return nil, fmt.Errorf("create: password auth method: embedded AuthMethod: %w", db.ErrNilParameter)
|
||||
return nil, fmt.Errorf("create: password auth method: embedded AuthMethod: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if m.ScopeId == "" {
|
||||
return nil, fmt.Errorf("create: password auth method: no scope id: %w", db.ErrInvalidParameter)
|
||||
@@ -182,13 +182,13 @@ func (r *Repository) DeleteAuthMethod(ctx context.Context, scopeId, publicId str
|
||||
// are included in the fieldMaskPaths, then an error is returned.
|
||||
func (r *Repository) UpdateAuthMethod(ctx context.Context, authMethod *AuthMethod, version uint32, fieldMaskPaths []string, opt ...Option) (*AuthMethod, int, error) {
|
||||
if authMethod == nil {
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: password auth method: missing authMethod: %w", db.ErrNilParameter)
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: password auth method: missing authMethod: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if authMethod.PublicId == "" {
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: password auth method: missing authMethod public id: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if authMethod.ScopeId == "" {
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: password auth method: scope id empty: %w", db.ErrNilParameter)
|
||||
return nil, db.NoRowsAffected, fmt.Errorf("update: password auth method: scope id empty: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
for _, f := range fieldMaskPaths {
|
||||
switch {
|
||||
|
||||
@@ -37,12 +37,12 @@ func TestRepository_CreateAuthMethod(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "nil-AuthMethod",
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
wantIsErr: db.ErrInvalidParameter,
|
||||
},
|
||||
{
|
||||
name: "nil-embedded-AuthMethod",
|
||||
in: &AuthMethod{},
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
wantIsErr: db.ErrInvalidParameter,
|
||||
},
|
||||
{
|
||||
name: "invalid-no-scope-id",
|
||||
|
||||
@@ -42,7 +42,7 @@ func (r *Repository) GetConfiguration(ctx context.Context, authMethodId string)
|
||||
// updates AuthMethod to use the previous configuration.
|
||||
func (r *Repository) SetConfiguration(ctx context.Context, scopeId string, c Configuration) (Configuration, error) {
|
||||
if c == nil {
|
||||
return nil, fmt.Errorf("set password configuration: %w", db.ErrNilParameter)
|
||||
return nil, fmt.Errorf("set password configuration: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if c.AuthMethodId() == "" {
|
||||
return nil, fmt.Errorf("set password configuration: no auth method id: %w", db.ErrInvalidParameter)
|
||||
|
||||
@@ -216,7 +216,7 @@ func TestRepository_SetConfiguration(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "invalid-nil-config",
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
wantIsErr: db.ErrInvalidParameter,
|
||||
},
|
||||
{
|
||||
name: "nil-embedded-config",
|
||||
|
||||
@@ -41,7 +41,7 @@ func (r *Repository) Authenticate(ctx context.Context, scopeId, authMethodId, lo
|
||||
return nil, fmt.Errorf("password authenticate: no password: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if scopeId == "" {
|
||||
return nil, fmt.Errorf("password authenticate: no scopeId: %w", db.ErrNilParameter)
|
||||
return nil, fmt.Errorf("password authenticate: no scopeId: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
|
||||
databaseWrapper, err := r.kms.GetWrapper(ctx, scopeId, kms.KeyPurposeDatabase)
|
||||
@@ -120,7 +120,7 @@ func (r *Repository) ChangePassword(ctx context.Context, scopeId, accountId, old
|
||||
return nil, fmt.Errorf("change password: no version supplied: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if scopeId == "" {
|
||||
return nil, fmt.Errorf("change password: no scopeId: %w", db.ErrNilParameter)
|
||||
return nil, fmt.Errorf("change password: no scopeId: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
|
||||
authAccount, err := r.LookupAccount(ctx, accountId)
|
||||
@@ -258,7 +258,7 @@ func (r *Repository) SetPassword(ctx context.Context, scopeId, accountId, passwo
|
||||
return nil, fmt.Errorf("set password: no version supplied: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
if scopeId == "" {
|
||||
return nil, fmt.Errorf("set password: no scopeId: %w", db.ErrNilParameter)
|
||||
return nil, fmt.Errorf("set password: no scopeId: %w", db.ErrInvalidParameter)
|
||||
}
|
||||
|
||||
oplogWrapper, err := r.kms.GetWrapper(ctx, scopeId, kms.KeyPurposeOplog)
|
||||
|
||||
@@ -67,7 +67,7 @@ func TestRepository_New(t *testing.T) {
|
||||
kms: kmsCache,
|
||||
},
|
||||
want: nil,
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
wantIsErr: db.ErrInvalidParameter,
|
||||
},
|
||||
{
|
||||
name: "nil-writer",
|
||||
@@ -77,7 +77,7 @@ func TestRepository_New(t *testing.T) {
|
||||
kms: kmsCache,
|
||||
},
|
||||
want: nil,
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
wantIsErr: db.ErrInvalidParameter,
|
||||
},
|
||||
{
|
||||
name: "nil-wrapper",
|
||||
@@ -87,7 +87,7 @@ func TestRepository_New(t *testing.T) {
|
||||
kms: nil,
|
||||
},
|
||||
want: nil,
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
wantIsErr: db.ErrInvalidParameter,
|
||||
},
|
||||
{
|
||||
name: "all-nils",
|
||||
@@ -97,7 +97,7 @@ func TestRepository_New(t *testing.T) {
|
||||
kms: nil,
|
||||
},
|
||||
want: nil,
|
||||
wantIsErr: db.ErrNilParameter,
|
||||
wantIsErr: db.ErrInvalidParameter,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in new issue
Block a user