2017-11-08 21:56:34 +00:00
|
|
|
|
package server
|
2017-04-06 18:40:57 +00:00
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
2017-10-19 18:17:40 +00:00
|
|
|
|
"fmt"
|
2017-04-06 18:40:57 +00:00
|
|
|
|
"net/http"
|
|
|
|
|
"net/http/httptest"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2020-04-03 17:39:20 +00:00
|
|
|
|
"github.com/influxdata/influxdb/v2/chronograf"
|
|
|
|
|
"github.com/influxdata/influxdb/v2/chronograf/mocks"
|
|
|
|
|
"github.com/influxdata/influxdb/v2/chronograf/oauth2"
|
|
|
|
|
"github.com/influxdata/influxdb/v2/chronograf/roles"
|
2017-04-06 18:40:57 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestAuthorizedToken(t *testing.T) {
|
|
|
|
|
var tests = []struct {
|
|
|
|
|
Desc string
|
|
|
|
|
Code int
|
|
|
|
|
Principal oauth2.Principal
|
|
|
|
|
ValidateErr error
|
|
|
|
|
Expected string
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
Desc: "Error in validate",
|
|
|
|
|
Code: http.StatusForbidden,
|
|
|
|
|
ValidateErr: errors.New("error"),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Desc: "Authorized ok",
|
|
|
|
|
Code: http.StatusOK,
|
|
|
|
|
Principal: oauth2.Principal{
|
|
|
|
|
Subject: "Principal Strickland",
|
|
|
|
|
},
|
|
|
|
|
Expected: "Principal Strickland",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
// next is a sentinel StatusOK and
|
|
|
|
|
// principal recorder.
|
|
|
|
|
var principal oauth2.Principal
|
|
|
|
|
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
|
principal = r.Context().Value(oauth2.PrincipalKey).(oauth2.Principal)
|
|
|
|
|
})
|
|
|
|
|
req, _ := http.NewRequest("GET", "", nil)
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
|
2017-10-26 22:46:06 +00:00
|
|
|
|
a := &mocks.Authenticator{
|
2017-04-06 18:40:57 +00:00
|
|
|
|
Principal: test.Principal,
|
|
|
|
|
ValidateErr: test.ValidateErr,
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-16 16:45:00 +00:00
|
|
|
|
logger := &chronograf.NoopLogger{}
|
2017-11-08 21:56:34 +00:00
|
|
|
|
handler := AuthorizedToken(a, logger, next)
|
2017-04-06 18:40:57 +00:00
|
|
|
|
handler.ServeHTTP(w, req)
|
|
|
|
|
if w.Code != test.Code {
|
|
|
|
|
t.Errorf("Status code expected: %d actual %d", test.Code, w.Code)
|
|
|
|
|
} else if principal != test.Principal {
|
|
|
|
|
t.Errorf("Principal mismatch expected: %s actual %s", test.Principal, principal)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-18 16:35:40 +00:00
|
|
|
|
func TestAuthorizedUser(t *testing.T) {
|
|
|
|
|
type fields struct {
|
2017-10-27 20:19:43 +00:00
|
|
|
|
UsersStore chronograf.UsersStore
|
|
|
|
|
OrganizationsStore chronograf.OrganizationsStore
|
|
|
|
|
Logger chronograf.Logger
|
2017-10-18 16:35:40 +00:00
|
|
|
|
}
|
|
|
|
|
type args struct {
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal *oauth2.Principal
|
|
|
|
|
scheme string
|
|
|
|
|
useAuth bool
|
|
|
|
|
role string
|
2017-10-18 16:35:40 +00:00
|
|
|
|
}
|
|
|
|
|
tests := []struct {
|
2017-11-10 16:18:06 +00:00
|
|
|
|
name string
|
|
|
|
|
fields fields
|
|
|
|
|
args args
|
|
|
|
|
hasOrganizationContext bool
|
|
|
|
|
hasSuperAdminContext bool
|
|
|
|
|
hasRoleContext bool
|
|
|
|
|
hasServerContext bool
|
|
|
|
|
authorized bool
|
2017-10-18 16:35:40 +00:00
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "Not using auth",
|
|
|
|
|
fields: fields{
|
2017-11-03 16:55:55 +00:00
|
|
|
|
UsersStore: &mocks.UsersStore{},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-03 16:55:55 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
useAuth: false,
|
|
|
|
|
},
|
2018-07-06 01:40:52 +00:00
|
|
|
|
hasOrganizationContext: true,
|
2017-11-10 16:18:06 +00:00
|
|
|
|
hasSuperAdminContext: false,
|
|
|
|
|
hasRoleContext: false,
|
|
|
|
|
hasServerContext: true,
|
|
|
|
|
authorized: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
2018-01-16 21:45:58 +00:00
|
|
|
|
{
|
|
|
|
|
name: "User with member role is member authorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2018-01-16 21:45:58 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
Roles: []chronograf.Role{
|
|
|
|
|
{
|
|
|
|
|
Name: roles.MemberRoleName,
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
|
|
|
|
ID: "0",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2018-01-16 21:45:58 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
|
|
|
|
ID: "1337",
|
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2018-01-16 21:45:58 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "member",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
|
|
|
|
authorized: true,
|
|
|
|
|
hasOrganizationContext: true,
|
|
|
|
|
hasSuperAdminContext: false,
|
|
|
|
|
hasRoleContext: true,
|
|
|
|
|
hasServerContext: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with viewer role is member authorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2018-01-16 21:45:58 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
Roles: []chronograf.Role{
|
|
|
|
|
{
|
|
|
|
|
Name: roles.ViewerRoleName,
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
|
|
|
|
ID: "0",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2018-01-16 21:45:58 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
|
|
|
|
ID: "1337",
|
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2018-01-16 21:45:58 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "member",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
|
|
|
|
authorized: true,
|
|
|
|
|
hasOrganizationContext: true,
|
|
|
|
|
hasSuperAdminContext: false,
|
|
|
|
|
hasRoleContext: true,
|
|
|
|
|
hasServerContext: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with editor role is member authorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2018-01-16 21:45:58 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
Roles: []chronograf.Role{
|
|
|
|
|
{
|
|
|
|
|
Name: roles.EditorRoleName,
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
|
|
|
|
ID: "0",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2018-01-16 21:45:58 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
|
|
|
|
ID: "1337",
|
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2018-01-16 21:45:58 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "member",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
|
|
|
|
authorized: true,
|
|
|
|
|
hasOrganizationContext: true,
|
|
|
|
|
hasSuperAdminContext: false,
|
|
|
|
|
hasRoleContext: true,
|
|
|
|
|
hasServerContext: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with admin role is member authorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2018-01-16 21:45:58 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
Roles: []chronograf.Role{
|
|
|
|
|
{
|
|
|
|
|
Name: roles.AdminRoleName,
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
|
|
|
|
ID: "0",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2018-01-16 21:45:58 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
|
|
|
|
ID: "1337",
|
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2018-01-16 21:45:58 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "member",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
|
|
|
|
authorized: true,
|
|
|
|
|
hasOrganizationContext: true,
|
|
|
|
|
hasSuperAdminContext: false,
|
|
|
|
|
hasRoleContext: true,
|
|
|
|
|
hasServerContext: false,
|
|
|
|
|
},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
{
|
|
|
|
|
name: "User with viewer role is viewer authorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.ViewerRoleName,
|
2017-10-31 20:41:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "viewer",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
2017-11-10 16:18:06 +00:00
|
|
|
|
authorized: true,
|
|
|
|
|
hasOrganizationContext: true,
|
|
|
|
|
hasSuperAdminContext: false,
|
|
|
|
|
hasRoleContext: true,
|
|
|
|
|
hasServerContext: false,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with editor role is viewer authorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.EditorRoleName,
|
2017-10-31 20:41:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "viewer",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
2017-11-10 16:18:06 +00:00
|
|
|
|
authorized: true,
|
|
|
|
|
hasOrganizationContext: true,
|
|
|
|
|
hasSuperAdminContext: false,
|
|
|
|
|
hasRoleContext: true,
|
|
|
|
|
hasServerContext: false,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with admin role is viewer authorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.AdminRoleName,
|
2017-10-31 20:41:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "viewer",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
2017-11-10 16:18:06 +00:00
|
|
|
|
authorized: true,
|
|
|
|
|
hasOrganizationContext: true,
|
|
|
|
|
hasSuperAdminContext: false,
|
|
|
|
|
hasRoleContext: true,
|
|
|
|
|
hasServerContext: false,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with viewer role is editor unauthorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.ViewerRoleName,
|
2017-10-31 20:41:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "editor",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with editor role is editor authorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.EditorRoleName,
|
2017-10-31 20:41:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "editor",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
2017-11-10 16:18:06 +00:00
|
|
|
|
authorized: true,
|
|
|
|
|
hasOrganizationContext: true,
|
|
|
|
|
hasSuperAdminContext: false,
|
|
|
|
|
hasRoleContext: true,
|
|
|
|
|
hasServerContext: false,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with admin role is editor authorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.AdminRoleName,
|
2017-10-31 20:41:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "editor",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
2017-11-10 16:18:06 +00:00
|
|
|
|
authorized: true,
|
|
|
|
|
hasOrganizationContext: true,
|
|
|
|
|
hasSuperAdminContext: false,
|
|
|
|
|
hasRoleContext: true,
|
|
|
|
|
hasServerContext: false,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with viewer role is admin unauthorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.ViewerRoleName,
|
2017-10-31 20:41:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "admin",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with editor role is admin unauthorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.EditorRoleName,
|
2017-10-31 20:41:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "admin",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with admin role is admin authorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.AdminRoleName,
|
2017-10-31 20:41:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "admin",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
2017-11-10 16:18:06 +00:00
|
|
|
|
authorized: true,
|
|
|
|
|
hasOrganizationContext: true,
|
|
|
|
|
hasSuperAdminContext: false,
|
|
|
|
|
hasRoleContext: true,
|
|
|
|
|
hasServerContext: false,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with no role is viewer unauthorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "view",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with no role is editor unauthorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "editor",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with no role is admin unauthorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "admin",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with unknown role is viewer unauthorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{
|
|
|
|
|
{
|
|
|
|
|
Name: "sweet_role",
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "viewer",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with unknown role is editor unauthorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{
|
|
|
|
|
{
|
|
|
|
|
Name: "sweet_role",
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
2018-07-06 01:40:52 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
|
|
|
|
ID: "0",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "editor",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with unknown role is admin unauthorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
2017-10-18 18:45:33 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-19 18:17:40 +00:00
|
|
|
|
}
|
2017-10-18 18:45:33 +00:00
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
2017-10-24 23:17:59 +00:00
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
2017-10-18 18:45:33 +00:00
|
|
|
|
Roles: []chronograf.Role{
|
|
|
|
|
{
|
|
|
|
|
Name: "sweet_role",
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:19:43 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
2017-10-27 20:53:16 +00:00
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "admin",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
{
|
|
|
|
|
name: "User with viewer role is SuperAdmin unauthorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-11-01 20:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
Roles: []chronograf.Role{
|
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.ViewerRoleName,
|
2017-11-01 20:38:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-11-01 20:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-11-01 20:38:17 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "superadmin",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with editor role is SuperAdmin unauthorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-11-01 20:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
Roles: []chronograf.Role{
|
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.EditorRoleName,
|
2017-11-01 20:38:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-11-01 20:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-11-01 20:38:17 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "superadmin",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "User with admin role is SuperAdmin unauthorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-11-01 20:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
Roles: []chronograf.Role{
|
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.AdminRoleName,
|
2017-11-01 20:38:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-11-01 20:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-11-01 20:38:17 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "superadmin",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "SuperAdmin is Viewer authorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-11-01 20:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
SuperAdmin: true,
|
|
|
|
|
Roles: []chronograf.Role{
|
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.MemberRoleName,
|
2017-11-01 20:38:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-11-01 20:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-11-01 20:38:17 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "viewer",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
2017-11-10 16:18:06 +00:00
|
|
|
|
authorized: true,
|
|
|
|
|
hasOrganizationContext: true,
|
|
|
|
|
hasSuperAdminContext: true,
|
|
|
|
|
hasRoleContext: true,
|
|
|
|
|
hasServerContext: false,
|
2017-11-01 20:38:17 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "SuperAdmin is Editor authorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-11-01 20:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
SuperAdmin: true,
|
|
|
|
|
Roles: []chronograf.Role{
|
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.MemberRoleName,
|
2017-11-01 20:38:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-11-01 20:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-11-01 20:38:17 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "editor",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
2017-11-10 16:18:06 +00:00
|
|
|
|
authorized: true,
|
|
|
|
|
hasOrganizationContext: true,
|
|
|
|
|
hasSuperAdminContext: true,
|
|
|
|
|
hasRoleContext: true,
|
|
|
|
|
hasServerContext: false,
|
2017-11-01 20:38:17 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "SuperAdmin is Admin authorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-11-01 20:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
SuperAdmin: true,
|
|
|
|
|
Roles: []chronograf.Role{
|
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.MemberRoleName,
|
2017-11-01 20:38:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-11-01 20:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-11-01 20:38:17 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "admin",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
2017-11-10 16:18:06 +00:00
|
|
|
|
authorized: true,
|
|
|
|
|
hasOrganizationContext: true,
|
|
|
|
|
hasSuperAdminContext: true,
|
|
|
|
|
hasRoleContext: true,
|
|
|
|
|
hasServerContext: false,
|
2017-11-01 20:38:17 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "SuperAdmin is SuperAdmin authorized",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-11-01 20:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
SuperAdmin: true,
|
|
|
|
|
Roles: []chronograf.Role{
|
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.MemberRoleName,
|
2017-11-01 20:38:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-11-01 20:38:17 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-11-01 20:38:17 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-11-01 20:38:17 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "superadmin",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
2017-11-10 16:18:06 +00:00
|
|
|
|
authorized: true,
|
|
|
|
|
hasOrganizationContext: true,
|
|
|
|
|
hasSuperAdminContext: true,
|
|
|
|
|
hasRoleContext: true,
|
|
|
|
|
hasServerContext: false,
|
2017-11-01 20:38:17 +00:00
|
|
|
|
},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
{
|
|
|
|
|
name: "Invalid principal – principal is nil",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-27 20:53:16 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
Roles: []chronograf.Role{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.AdminRoleName,
|
2017-10-31 20:41:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:53:16 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:53:16 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: nil,
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "admin",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Invalid principal - missing organization",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-27 20:53:16 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
Roles: []chronograf.Role{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.AdminRoleName,
|
2017-10-31 20:41:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:53:16 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:53:16 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "admin",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Invalid principal - organization id not uint64",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-27 20:53:16 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
Roles: []chronograf.Role{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.AdminRoleName,
|
2017-10-31 20:41:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:53:16 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:53:16 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1ee7",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "admin",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Failed to retrieve organization",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-27 20:53:16 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
Roles: []chronograf.Role{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.AdminRoleName,
|
2017-10-31 20:41:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:53:16 +00:00
|
|
|
|
}
|
|
|
|
|
switch *q.ID {
|
2017-12-18 22:07:40 +00:00
|
|
|
|
case "1338":
|
2017-10-27 20:53:16 +00:00
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1338",
|
2017-10-27 20:53:16 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
default:
|
|
|
|
|
return nil, chronograf.ErrOrganizationNotFound
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billysteve",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "admin",
|
|
|
|
|
useAuth: true,
|
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Failed to retrieve user",
|
|
|
|
|
fields: fields{
|
|
|
|
|
UsersStore: &mocks.UsersStore{
|
|
|
|
|
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
|
|
|
|
|
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid user query: missing Name, Provider, and/or Scheme")
|
2017-10-27 20:53:16 +00:00
|
|
|
|
}
|
|
|
|
|
switch *q.Name {
|
|
|
|
|
case "billysteve":
|
|
|
|
|
return &chronograf.User{
|
|
|
|
|
ID: 1337,
|
|
|
|
|
Name: "billysteve",
|
|
|
|
|
Provider: "google",
|
|
|
|
|
Scheme: "oauth2",
|
|
|
|
|
Roles: []chronograf.Role{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
{
|
2017-11-03 20:32:05 +00:00
|
|
|
|
Name: roles.AdminRoleName,
|
2017-10-31 20:41:17 +00:00
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
default:
|
|
|
|
|
return nil, chronograf.ErrUserNotFound
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
OrganizationsStore: &mocks.OrganizationsStore{
|
2017-11-02 20:47:45 +00:00
|
|
|
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "0",
|
2017-11-02 20:47:45 +00:00
|
|
|
|
}, nil
|
|
|
|
|
},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
GetF: func(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
|
|
|
|
|
if q.ID == nil {
|
2018-11-21 14:22:35 +00:00
|
|
|
|
return nil, fmt.Errorf("invalid organization query: missing ID")
|
2017-10-27 20:53:16 +00:00
|
|
|
|
}
|
|
|
|
|
return &chronograf.Organization{
|
2017-12-18 22:07:40 +00:00
|
|
|
|
ID: "1337",
|
2017-10-27 20:53:16 +00:00
|
|
|
|
Name: "The ShillBillThrilliettas",
|
|
|
|
|
}, nil
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2017-10-27 20:53:16 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
principal: &oauth2.Principal{
|
|
|
|
|
Subject: "billietta",
|
|
|
|
|
Issuer: "google",
|
|
|
|
|
Organization: "1337",
|
|
|
|
|
},
|
|
|
|
|
scheme: "oauth2",
|
|
|
|
|
role: "admin",
|
|
|
|
|
useAuth: true,
|
2017-10-18 16:35:40 +00:00
|
|
|
|
},
|
|
|
|
|
authorized: false,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
var authorized bool
|
2017-11-08 21:56:34 +00:00
|
|
|
|
var hasServerCtx bool
|
|
|
|
|
var hasSuperAdminCtx bool
|
2017-11-10 16:18:06 +00:00
|
|
|
|
var hasOrganizationCtx bool
|
2017-11-08 21:56:34 +00:00
|
|
|
|
var hasRoleCtx bool
|
2017-10-18 16:35:40 +00:00
|
|
|
|
next := func(w http.ResponseWriter, r *http.Request) {
|
2017-11-08 21:56:34 +00:00
|
|
|
|
ctx := r.Context()
|
|
|
|
|
hasServerCtx = hasServerContext(ctx)
|
|
|
|
|
hasSuperAdminCtx = hasSuperAdminContext(ctx)
|
2017-11-10 16:18:06 +00:00
|
|
|
|
_, hasOrganizationCtx = hasOrganizationContext(ctx)
|
2017-11-08 21:56:34 +00:00
|
|
|
|
_, hasRoleCtx = hasRoleContext(ctx)
|
2017-10-18 16:35:40 +00:00
|
|
|
|
authorized = true
|
|
|
|
|
}
|
2017-11-08 21:56:34 +00:00
|
|
|
|
fn := AuthorizedUser(
|
|
|
|
|
&Store{
|
2017-10-31 20:41:17 +00:00
|
|
|
|
UsersStore: tt.fields.UsersStore,
|
|
|
|
|
OrganizationsStore: tt.fields.OrganizationsStore,
|
|
|
|
|
},
|
2017-10-27 20:19:43 +00:00
|
|
|
|
tt.args.useAuth,
|
|
|
|
|
tt.args.role,
|
|
|
|
|
tt.fields.Logger,
|
|
|
|
|
next,
|
|
|
|
|
)
|
2017-10-18 16:35:40 +00:00
|
|
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
r := httptest.NewRequest(
|
|
|
|
|
"GET",
|
|
|
|
|
"http://any.url", // can be any valid URL as we are bypassing mux
|
|
|
|
|
nil,
|
|
|
|
|
)
|
2017-10-27 20:53:16 +00:00
|
|
|
|
if tt.args.principal == nil {
|
|
|
|
|
r = r.WithContext(context.WithValue(r.Context(), oauth2.PrincipalKey, nil))
|
|
|
|
|
} else {
|
|
|
|
|
r = r.WithContext(context.WithValue(r.Context(), oauth2.PrincipalKey, *tt.args.principal))
|
|
|
|
|
}
|
2017-10-18 16:35:40 +00:00
|
|
|
|
fn(w, r)
|
|
|
|
|
|
|
|
|
|
if authorized != tt.authorized {
|
2017-10-19 18:17:40 +00:00
|
|
|
|
t.Errorf("%q. AuthorizedUser() = %v, expected %v", tt.name, authorized, tt.authorized)
|
2017-10-18 16:35:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-21 23:55:26 +00:00
|
|
|
|
if !authorized && w.Code != http.StatusForbidden {
|
|
|
|
|
t.Errorf("%q. AuthorizedUser() Status Code = %v, expected %v", tt.name, w.Code, http.StatusForbidden)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-08 21:56:34 +00:00
|
|
|
|
if hasServerCtx != tt.hasServerContext {
|
|
|
|
|
t.Errorf("%q. AuthorizedUser().Context().Server = %v, expected %v", tt.name, hasServerCtx, tt.hasServerContext)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if hasSuperAdminCtx != tt.hasSuperAdminContext {
|
|
|
|
|
t.Errorf("%q. AuthorizedUser().Context().SuperAdmin = %v, expected %v", tt.name, hasSuperAdminCtx, tt.hasSuperAdminContext)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-10 16:18:06 +00:00
|
|
|
|
if hasOrganizationCtx != tt.hasOrganizationContext {
|
|
|
|
|
t.Errorf("%q. AuthorizedUser.Context().Organization = %v, expected %v", tt.name, hasOrganizationCtx, tt.hasOrganizationContext)
|
2017-11-08 21:56:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if hasRoleCtx != tt.hasRoleContext {
|
|
|
|
|
t.Errorf("%q. AuthorizedUser().Context().Role = %v, expected %v", tt.name, hasRoleCtx, tt.hasRoleContext)
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 16:35:40 +00:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-09 18:43:33 +00:00
|
|
|
|
|
2018-01-16 21:45:58 +00:00
|
|
|
|
func TestRawStoreAccess(t *testing.T) {
|
2018-01-09 18:43:33 +00:00
|
|
|
|
type fields struct {
|
|
|
|
|
Logger chronograf.Logger
|
|
|
|
|
}
|
|
|
|
|
type args struct {
|
|
|
|
|
principal *oauth2.Principal
|
|
|
|
|
serverContext bool
|
|
|
|
|
user *chronograf.User
|
|
|
|
|
}
|
|
|
|
|
type wants struct {
|
|
|
|
|
authorized bool
|
|
|
|
|
hasServerContext bool
|
|
|
|
|
}
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
fields fields
|
|
|
|
|
args args
|
|
|
|
|
wants wants
|
|
|
|
|
}{
|
|
|
|
|
{
|
2018-01-16 21:45:58 +00:00
|
|
|
|
name: "middleware already has server context",
|
2018-01-09 18:43:33 +00:00
|
|
|
|
fields: fields{
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2018-01-09 18:43:33 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
serverContext: true,
|
|
|
|
|
},
|
|
|
|
|
wants: wants{
|
|
|
|
|
authorized: true,
|
|
|
|
|
hasServerContext: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2018-01-16 21:45:58 +00:00
|
|
|
|
name: "user on context is a SuperAdmin",
|
2018-01-09 18:43:33 +00:00
|
|
|
|
fields: fields{
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2018-01-09 18:43:33 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
user: &chronograf.User{
|
|
|
|
|
SuperAdmin: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wants: wants{
|
|
|
|
|
authorized: true,
|
|
|
|
|
hasServerContext: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2018-01-16 21:45:58 +00:00
|
|
|
|
name: "user on context is a not SuperAdmin",
|
2018-01-09 18:43:33 +00:00
|
|
|
|
fields: fields{
|
2018-11-16 16:45:00 +00:00
|
|
|
|
Logger: &chronograf.NoopLogger{},
|
2018-01-09 18:43:33 +00:00
|
|
|
|
},
|
|
|
|
|
args: args{
|
|
|
|
|
user: &chronograf.User{
|
|
|
|
|
SuperAdmin: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
wants: wants{
|
|
|
|
|
authorized: false,
|
|
|
|
|
hasServerContext: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
var authorized bool
|
|
|
|
|
var hasServerCtx bool
|
|
|
|
|
next := func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
ctx := r.Context()
|
|
|
|
|
hasServerCtx = hasServerContext(ctx)
|
|
|
|
|
authorized = true
|
|
|
|
|
}
|
2018-01-16 21:45:58 +00:00
|
|
|
|
fn := RawStoreAccess(
|
2018-01-09 18:43:33 +00:00
|
|
|
|
tt.fields.Logger,
|
|
|
|
|
next,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
url := "http://any.url"
|
|
|
|
|
r := httptest.NewRequest(
|
|
|
|
|
"GET",
|
|
|
|
|
url,
|
|
|
|
|
nil,
|
|
|
|
|
)
|
|
|
|
|
if tt.args.principal == nil {
|
|
|
|
|
r = r.WithContext(context.WithValue(r.Context(), oauth2.PrincipalKey, nil))
|
|
|
|
|
} else {
|
|
|
|
|
r = r.WithContext(context.WithValue(r.Context(), oauth2.PrincipalKey, *tt.args.principal))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if tt.args.serverContext {
|
|
|
|
|
r = r.WithContext(serverContext(r.Context()))
|
|
|
|
|
}
|
|
|
|
|
if tt.args.user != nil {
|
|
|
|
|
r = r.WithContext(context.WithValue(r.Context(), UserContextKey, tt.args.user))
|
|
|
|
|
}
|
|
|
|
|
fn(w, r)
|
|
|
|
|
|
|
|
|
|
if authorized != tt.wants.authorized {
|
2018-01-16 21:45:58 +00:00
|
|
|
|
t.Errorf("%q. RawStoreAccess() = %v, expected %v", tt.name, authorized, tt.wants.authorized)
|
2018-01-09 18:43:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !authorized && w.Code != http.StatusForbidden {
|
2018-01-16 21:45:58 +00:00
|
|
|
|
t.Errorf("%q. RawStoreAccess() Status Code = %v, expected %v", tt.name, w.Code, http.StatusForbidden)
|
2018-01-09 18:43:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if hasServerCtx != tt.wants.hasServerContext {
|
2018-01-16 21:45:58 +00:00
|
|
|
|
t.Errorf("%q. RawStoreAccess().Context().Server = %v, expected %v", tt.name, hasServerCtx, tt.wants.hasServerContext)
|
2018-01-09 18:43:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|