Skip to content

Commit

Permalink
fix: improve error message when onboarding requests are missing data (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
danxmoran authored Jul 16, 2021
1 parent adc9033 commit 460842b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Because of the version bump to `go`, the macOS build for this release requires a
1. [21866](https://github.com/influxdata/influxdb/pull/21866): Remove incorrect optimization for group-by.
1. [21867](https://github.com/influxdata/influxdb/pull/21867): Return an error instead of panicking when InfluxQL statement rewrites fail.
1. [21868](https://github.com/influxdata/influxdb/pull/21868): Migrate restored KV snapshots to latest schema before using them.
1. [21869](https://github.com/influxdata/influxdb/pull/21869): Specify which fields are missing when rejecting an incomplete onboarding request.

## v2.0.7 [2021-06-04]
----------------------
Expand Down
5 changes: 0 additions & 5 deletions tenant/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ var (
Msg: "onboarding has already been completed",
}

ErrOnboardInvalid = &influxdb.Error{
Code: influxdb.EEmptyValue,
Msg: "onboard failed, missing value",
}

ErrNotFound = &influxdb.Error{
Code: influxdb.ENotFound,
Msg: "not found",
Expand Down
26 changes: 24 additions & 2 deletions tenant/service_onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package tenant
import (
"context"
"fmt"
"strings"

"github.com/influxdata/influxdb/v2"
icontext "github.com/influxdata/influxdb/v2/context"
"github.com/influxdata/influxdb/v2/kv"
Expand Down Expand Up @@ -89,8 +91,28 @@ 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, userID influxdb.ID) []influxdb.Permission) (*influxdb.OnboardingResults, error) {
if req == nil || req.User == "" || req.Org == "" || req.Bucket == "" {
return nil, ErrOnboardInvalid
if req == nil {
return nil, &influxdb.Error{
Code: influxdb.EEmptyValue,
Msg: "onboarding failed: no request body provided",
}
}

var missingFields []string
if req.User == "" {
missingFields = append(missingFields, "username")
}
if req.Org == "" {
missingFields = append(missingFields, "org")
}
if req.Bucket == "" {
missingFields = append(missingFields, "bucket")
}
if len(missingFields) > 0 {
return nil, &influxdb.Error{
Code: influxdb.EUnprocessableEntity,
Msg: fmt.Sprintf("onboarding failed: missing required fields [%s]", strings.Join(missingFields, ",")),
}
}

result := &influxdb.OnboardingResults{}
Expand Down
25 changes: 3 additions & 22 deletions testing/onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func OnboardInitialUser(
},
},
wants: wants{
errCode: platform.EEmptyValue,
errCode: platform.EUnprocessableEntity,
},
},
{
Expand All @@ -101,7 +101,7 @@ func OnboardInitialUser(
},
},
wants: wants{
errCode: platform.EEmptyValue,
errCode: platform.EUnprocessableEntity,
},
},
{
Expand All @@ -120,26 +120,7 @@ func OnboardInitialUser(
},
},
wants: wants{
errCode: platform.EEmptyValue,
},
},
{
name: "missing password should fail",
fields: OnboardingFields{
IDGenerator: &loopIDGenerator{
s: []string{oneID, twoID, threeID, fourID},
},
TokenGenerator: mock.NewTokenGenerator(oneToken, nil),
IsOnboarding: true,
},
args: args{
request: &platform.OnboardingRequest{
User: "admin",
Org: "org1",
},
},
wants: wants{
errCode: platform.EEmptyValue,
errCode: platform.EUnprocessableEntity,
},
},
{
Expand Down

0 comments on commit 460842b

Please sign in to comment.