storage: Surface "already exists" errors.
This commit is contained in:
@@ -53,8 +53,10 @@ func (d dexAPI) CreateClient(ctx context.Context, req *api.CreateClientReq) (*ap
|
||||
LogoURL: req.Client.LogoUrl,
|
||||
}
|
||||
if err := d.s.CreateClient(c); err != nil {
|
||||
if err == storage.ErrAlreadyExists {
|
||||
return &api.CreateClientResp{AlreadyExists: true}, nil
|
||||
}
|
||||
d.logger.Errorf("api: failed to create client: %v", err)
|
||||
// TODO(ericchiang): Surface "already exists" errors.
|
||||
return nil, fmt.Errorf("create client: %v", err)
|
||||
}
|
||||
|
||||
@@ -109,6 +111,9 @@ func (d dexAPI) CreatePassword(ctx context.Context, req *api.CreatePasswordReq)
|
||||
UserID: req.Password.UserId,
|
||||
}
|
||||
if err := d.s.CreatePassword(p); err != nil {
|
||||
if err == storage.ErrAlreadyExists {
|
||||
return &api.CreatePasswordResp{AlreadyExists: true}, nil
|
||||
}
|
||||
d.logger.Errorf("api: failed to create password: %v", err)
|
||||
return nil, fmt.Errorf("create password: %v", err)
|
||||
}
|
||||
|
@@ -37,10 +37,18 @@ func TestPassword(t *testing.T) {
|
||||
Password: &p,
|
||||
}
|
||||
|
||||
if _, err := serv.CreatePassword(ctx, &createReq); err != nil {
|
||||
if resp, err := serv.CreatePassword(ctx, &createReq); err != nil || resp.AlreadyExists {
|
||||
if resp.AlreadyExists {
|
||||
t.Fatalf("Unable to create password since %s already exists", createReq.Password.Email)
|
||||
}
|
||||
t.Fatalf("Unable to create password: %v", err)
|
||||
}
|
||||
|
||||
// Attempt to create a password that already exists.
|
||||
if resp, _ := serv.CreatePassword(ctx, &createReq); !resp.AlreadyExists {
|
||||
t.Fatalf("Created password %s twice", createReq.Password.Email)
|
||||
}
|
||||
|
||||
updateReq := api.UpdatePasswordReq{
|
||||
Email: "test@example.com",
|
||||
NewUsername: "test1",
|
||||
|
Reference in New Issue
Block a user