Skip to content

Commit

Permalink
feat(onboard): allow optional password
Browse files Browse the repository at this point in the history
We can now allow passwords as an optional arguement. This facilitates
api only users.
  • Loading branch information
lyondhill committed Aug 5, 2020
1 parent fdea2c6 commit d15a8a0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
1 change: 0 additions & 1 deletion http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10625,7 +10625,6 @@ components:
type: integer
required:
- username
- password
- org
- bucket
OnboardingResponse:
Expand Down
2 changes: 1 addition & 1 deletion tenant/service_onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *OnboardService) OnboardUser(ctx context.Context, req *influxdb.Onboardi

// onboardUser allows us to onboard new users.
func (s *OnboardService) onboardUser(ctx context.Context, req *influxdb.OnboardingRequest, permFn func(orgID influxdb.ID) []influxdb.Permission) (*influxdb.OnboardingResults, error) {
if req == nil || req.User == "" || req.Password == "" || req.Org == "" || req.Bucket == "" {
if req == nil || req.User == "" || req.Org == "" || req.Bucket == "" {
return nil, ErrOnboardInvalid
}

Expand Down
59 changes: 48 additions & 11 deletions testing/onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func OnboardInitialUser(
},
},
{
name: "missing password",
name: "missing username",
fields: OnboardingFields{
IDGenerator: &loopIDGenerator{
s: []string{oneID, twoID, threeID, fourID},
Expand All @@ -77,7 +77,6 @@ func OnboardInitialUser(
},
args: args{
request: &platform.OnboardingRequest{
User: "admin",
Org: "org1",
Bucket: "bucket1",
},
Expand All @@ -87,7 +86,7 @@ func OnboardInitialUser(
},
},
{
name: "missing username",
name: "missing org",
fields: OnboardingFields{
IDGenerator: &loopIDGenerator{
s: []string{oneID, twoID, threeID, fourID},
Expand All @@ -97,7 +96,7 @@ func OnboardInitialUser(
},
args: args{
request: &platform.OnboardingRequest{
Org: "org1",
User: "admin",
Bucket: "bucket1",
},
},
Expand All @@ -106,7 +105,7 @@ func OnboardInitialUser(
},
},
{
name: "missing org",
name: "missing bucket",
fields: OnboardingFields{
IDGenerator: &loopIDGenerator{
s: []string{oneID, twoID, threeID, fourID},
Expand All @@ -116,16 +115,16 @@ func OnboardInitialUser(
},
args: args{
request: &platform.OnboardingRequest{
User: "admin",
Bucket: "bucket1",
User: "admin",
Org: "org1",
},
},
wants: wants{
errCode: platform.EEmptyValue,
},
},
{
name: "missing bucket",
name: "missing password should still work",
fields: OnboardingFields{
IDGenerator: &loopIDGenerator{
s: []string{oneID, twoID, threeID, fourID},
Expand All @@ -135,12 +134,50 @@ func OnboardInitialUser(
},
args: args{
request: &platform.OnboardingRequest{
User: "admin",
Org: "org1",
User: "admin",
Org: "org1",
Bucket: "bucket1",
},
},
wants: wants{
errCode: platform.EEmptyValue,
results: &platform.OnboardingResults{
User: &platform.User{
ID: MustIDBase16(oneID),
Name: "admin",
Status: platform.Active,
},
Org: &platform.Organization{
ID: MustIDBase16(twoID),
Name: "org1",
CRUDLog: platform.CRUDLog{
CreatedAt: time.Date(2006, 5, 4, 1, 2, 3, 0, time.UTC),
UpdatedAt: time.Date(2006, 5, 4, 1, 2, 3, 0, time.UTC),
},
},
Bucket: &platform.Bucket{
ID: MustIDBase16(threeID),
Name: "bucket1",
OrgID: MustIDBase16(twoID),
RetentionPeriod: 0,
CRUDLog: platform.CRUDLog{
CreatedAt: time.Date(2006, 5, 4, 1, 2, 3, 0, time.UTC),
UpdatedAt: time.Date(2006, 5, 4, 1, 2, 3, 0, time.UTC),
},
},
Auth: &platform.Authorization{
ID: MustIDBase16(fourID),
Token: oneToken,
Status: platform.Active,
UserID: MustIDBase16(oneID),
Description: "admin's Token",
OrgID: MustIDBase16(twoID),
Permissions: platform.OperPermissions(),
CRUDLog: platform.CRUDLog{
CreatedAt: time.Date(2006, 5, 4, 1, 2, 3, 0, time.UTC),
UpdatedAt: time.Date(2006, 5, 4, 1, 2, 3, 0, time.UTC),
},
},
},
},
},
{
Expand Down

0 comments on commit d15a8a0

Please sign in to comment.