Skip to content

Commit

Permalink
fix(influxdb): revert functionality added in pr#10947
Browse files Browse the repository at this point in the history
  • Loading branch information
desa committed Feb 6, 2019
1 parent 552ebb8 commit a7ada29
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 150 deletions.
17 changes: 0 additions & 17 deletions cmd/influx/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,23 +228,6 @@ func authorizationCreateF(cmd *cobra.Command, args []string) error {
OrgID: o.ID,
}

if authorizationCreateFlags.user != "" {
// if the user flag is supplied, then set the user ID explicitly on the request
userSvc, err := newUserService(flags)
if err != nil {
return err
}
userFilter := platform.UserFilter{
Name: &authorizationCreateFlags.user,
}
user, err := userSvc.FindUser(context.Background(), userFilter)
if err != nil {
return err
}

authorization.UserID = user.ID
}

s, err := newAuthorizationService(flags)
if err != nil {
return err
Expand Down
23 changes: 4 additions & 19 deletions http/auth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,10 @@ func (h *AuthorizationHandler) handlePostAuthorization(w http.ResponseWriter, r
return
}

var user *platform.User
// allow the user id to be specified optionally, if it is not set
// we use the id from the authorizer
if req.UserID == nil {
u, err := getAuthorizedUser(r, h.UserService)
if err != nil {
EncodeError(ctx, platform.ErrUnableToCreateToken, w)
return
}

user = u
} else {
u, err := h.UserService.FindUserByID(ctx, *req.UserID)
if err != nil {
EncodeError(ctx, platform.ErrUnableToCreateToken, w)
return
}

user = u
user, err := getAuthorizedUser(r, h.UserService)
if err != nil {
EncodeError(ctx, platform.ErrUnableToCreateToken, w)
return
}

auth := req.toPlatform(user.ID)
Expand Down
116 changes: 2 additions & 114 deletions http/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"context"
"encoding/json"
"fmt"
"go.uber.org/zap"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"

"go.uber.org/zap"

platform "github.com/influxdata/influxdb"
pcontext "github.com/influxdata/influxdb/context"
"github.com/influxdata/influxdb/inmem"
Expand Down Expand Up @@ -522,119 +523,6 @@ func TestService_handlePostAuthorization(t *testing.T) {
`,
},
},
{
name: "create a new authorization with user id set explicitly",
fields: fields{
AuthorizationService: &mock.AuthorizationService{
CreateAuthorizationFn: func(ctx context.Context, c *platform.Authorization) error {
c.ID = platformtesting.MustIDBase16("020f755c3c082000")
c.Token = "new-test-token"
return nil
},
},
UserService: &mock.UserService{
FindUserByIDFn: func(ctx context.Context, id platform.ID) (*platform.User, error) {
if !id.Valid() {
return nil, &platform.Error{
Code: platform.EInvalid,
Msg: "invalid user id",
}
}
return &platform.User{
ID: id,
Name: "u1",
}, nil
},
},
OrganizationService: &mock.OrganizationService{
FindOrganizationByIDF: func(ctx context.Context, id platform.ID) (*platform.Organization, error) {
if !id.Valid() {
return nil, &platform.Error{
Code: platform.EInvalid,
Msg: "invalid org ID",
}
}
return &platform.Organization{
ID: id,
Name: "o1",
}, nil
},
},
LookupService: &mock.LookupService{
NameFn: func(ctx context.Context, resource platform.ResourceType, id platform.ID) (string, error) {
switch resource {
case platform.BucketsResourceType:
return "b1", nil
case platform.OrgsResourceType:
return "o1", nil
}
return "", fmt.Errorf("bad resource type %s", resource)
},
},
},
args: args{
session: &platform.Authorization{
Token: "session-token",
ID: platformtesting.MustIDBase16("020f755c3c082000"),
UserID: platformtesting.MustIDBase16("aaaaaaaaaaaaaaaa"),
OrgID: platformtesting.MustIDBase16("020f755c3c083000"),
Description: "can write to authorization resource",
Permissions: []platform.Permission{
{
Action: platform.WriteAction,
Resource: platform.Resource{
Type: platform.AuthorizationsResourceType,
},
},
},
},
authorization: &platform.Authorization{
ID: platformtesting.MustIDBase16("020f755c3c082000"),
UserID: platformtesting.MustIDBase16("bbbbbbbbbbbbbbbb"),
OrgID: platformtesting.MustIDBase16("020f755c3c083000"),
Description: "only read dashboards sucka",
Permissions: []platform.Permission{
{
Action: platform.ReadAction,
Resource: platform.Resource{
Type: platform.DashboardsResourceType,
OrgID: platformtesting.IDPtr(platformtesting.MustIDBase16("020f755c3c083000")),
},
},
},
},
},
wants: wants{
statusCode: http.StatusCreated,
contentType: "application/json; charset=utf-8",
body: `
{
"links": {
"user": "/api/v2/users/bbbbbbbbbbbbbbbb",
"self": "/api/v2/authorizations/020f755c3c082000"
},
"id": "020f755c3c082000",
"user": "u1",
"userID": "bbbbbbbbbbbbbbbb",
"orgID": "020f755c3c083000",
"org": "o1",
"token": "new-test-token",
"status": "active",
"description": "only read dashboards sucka",
"permissions": [
{
"action": "read",
"resource": {
"type": "dashboards",
"orgID": "020f755c3c083000",
"org": "o1"
}
}
]
}
`,
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit a7ada29

Please sign in to comment.