influxdb/testing/user_service.go

862 lines
16 KiB
Go
Raw Normal View History

package testing
import (
"bytes"
"context"
"sort"
"testing"
"github.com/google/go-cmp/cmp"
platform "github.com/influxdata/influxdb"
"github.com/influxdata/influxdb/mock"
)
const (
userOneID = "020f755c3c082000"
userTwoID = "020f755c3c082001"
userThreeID = "020f755c3c082002"
)
var userCmpOptions = cmp.Options{
cmp.Comparer(func(x, y []byte) bool {
return bytes.Equal(x, y)
}),
cmp.Transformer("Sort", func(in []*platform.User) []*platform.User {
out := append([]*platform.User(nil), in...) // Copy input to avoid mutating it
sort.Slice(out, func(i, j int) bool {
return out[i].ID.String() > out[j].ID.String()
})
return out
}),
}
// UserFields will include the IDGenerator, and users
type UserFields struct {
IDGenerator platform.IDGenerator
Users []*platform.User
}
// UserService tests all the service functions.
func UserService(
2018-12-07 18:12:24 +00:00
init func(UserFields, *testing.T) (platform.UserService, string, func()), t *testing.T,
) {
tests := []struct {
name string
2018-12-07 18:12:24 +00:00
fn func(init func(UserFields, *testing.T) (platform.UserService, string, func()),
t *testing.T)
}{
{
name: "CreateUser",
fn: CreateUser,
},
{
name: "FindUserByID",
fn: FindUserByID,
},
{
name: "FindUsers",
fn: FindUsers,
},
{
name: "DeleteUser",
fn: DeleteUser,
},
{
name: "FindUser",
fn: FindUser,
},
{
name: "UpdateUser",
fn: UpdateUser,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.fn(init, t)
})
}
}
// CreateUser testing
func CreateUser(
2018-12-07 18:12:24 +00:00
init func(UserFields, *testing.T) (platform.UserService, string, func()),
t *testing.T,
) {
type args struct {
user *platform.User
}
type wants struct {
err error
users []*platform.User
}
tests := []struct {
name string
fields UserFields
args args
wants wants
}{
{
name: "create users with empty set",
fields: UserFields{
IDGenerator: mock.NewIDGenerator(userOneID, t),
Users: []*platform.User{},
},
args: args{
user: &platform.User{
Name: "name1",
},
},
wants: wants{
users: []*platform.User{
{
Name: "name1",
ID: MustIDBase16(userOneID),
},
},
},
},
{
name: "basic create user",
fields: UserFields{
IDGenerator: mock.NewIDGenerator(userTwoID, t),
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "user1",
},
},
},
args: args{
user: &platform.User{
Name: "user2",
},
},
wants: wants{
users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "user1",
},
{
ID: MustIDBase16(userTwoID),
Name: "user2",
},
},
},
},
{
name: "names should be unique",
fields: UserFields{
IDGenerator: &mock.IDGenerator{
IDFn: func() platform.ID {
return MustIDBase16(userOneID)
},
},
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "user1",
},
},
},
args: args{
user: &platform.User{
Name: "user1",
},
},
wants: wants{
users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "user1",
},
},
2018-12-07 18:12:24 +00:00
err: &platform.Error{
Code: platform.EConflict,
Op: platform.OpCreateUser,
Msg: "user with name user1 already exists",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
2018-12-07 18:12:24 +00:00
s, opPrefix, done := init(tt.fields, t)
defer done()
ctx := context.Background()
err := s.CreateUser(ctx, tt.args.user)
2018-12-07 18:12:24 +00:00
diffPlatformErrors(tt.name, err, tt.wants.err, opPrefix, t)
// Delete only created users - ie., having a not nil ID
if tt.args.user.ID.Valid() {
defer s.DeleteUser(ctx, tt.args.user.ID)
}
users, _, err := s.FindUsers(ctx, platform.UserFilter{})
if err != nil {
t.Fatalf("failed to retrieve users: %v", err)
}
if diff := cmp.Diff(users, tt.wants.users, userCmpOptions...); diff != "" {
t.Errorf("users are different -got/+want\ndiff %s", diff)
}
})
}
}
// FindUserByID testing
func FindUserByID(
2018-12-07 18:12:24 +00:00
init func(UserFields, *testing.T) (platform.UserService, string, func()),
t *testing.T,
) {
type args struct {
id platform.ID
}
type wants struct {
err error
user *platform.User
}
tests := []struct {
name string
fields UserFields
args args
wants wants
}{
{
name: "basic find user by id",
fields: UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "user1",
},
{
ID: MustIDBase16(userTwoID),
Name: "user2",
},
},
},
args: args{
id: MustIDBase16(userTwoID),
},
wants: wants{
user: &platform.User{
ID: MustIDBase16(userTwoID),
Name: "user2",
},
},
},
2018-12-07 18:12:24 +00:00
{
name: "find user by id not exists",
fields: UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "user1",
},
{
ID: MustIDBase16(userTwoID),
Name: "user2",
},
},
},
args: args{
id: MustIDBase16(threeID),
},
wants: wants{
err: &platform.Error{
Code: platform.ENotFound,
Op: platform.OpFindUserByID,
Msg: "user not found",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
2018-12-07 18:12:24 +00:00
s, opPrefix, done := init(tt.fields, t)
defer done()
ctx := context.Background()
user, err := s.FindUserByID(ctx, tt.args.id)
2018-12-07 18:12:24 +00:00
diffPlatformErrors(tt.name, err, tt.wants.err, opPrefix, t)
if diff := cmp.Diff(user, tt.wants.user, userCmpOptions...); diff != "" {
t.Errorf("user is different -got/+want\ndiff %s", diff)
}
})
}
}
// FindUsers testing
func FindUsers(
2018-12-07 18:12:24 +00:00
init func(UserFields, *testing.T) (platform.UserService, string, func()),
t *testing.T,
) {
type args struct {
ID platform.ID
name string
}
type wants struct {
users []*platform.User
err error
}
tests := []struct {
name string
fields UserFields
args args
wants wants
}{
{
name: "find all users",
fields: UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "abc",
},
{
ID: MustIDBase16(userTwoID),
Name: "xyz",
},
},
},
args: args{},
wants: wants{
users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "abc",
},
{
ID: MustIDBase16(userTwoID),
Name: "xyz",
},
},
},
},
{
name: "find user by id",
fields: UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "abc",
},
{
ID: MustIDBase16(userTwoID),
Name: "xyz",
},
},
},
args: args{
ID: MustIDBase16(userTwoID),
},
wants: wants{
users: []*platform.User{
{
ID: MustIDBase16(userTwoID),
Name: "xyz",
},
},
},
},
{
name: "find user by name",
fields: UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "abc",
},
{
ID: MustIDBase16(userTwoID),
Name: "xyz",
},
},
},
args: args{
name: "xyz",
},
wants: wants{
users: []*platform.User{
{
ID: MustIDBase16(userTwoID),
Name: "xyz",
},
},
},
},
2018-12-07 18:12:24 +00:00
{
name: "find user by id not exists",
fields: UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "abc",
},
{
ID: MustIDBase16(userTwoID),
Name: "xyz",
},
},
},
args: args{
ID: MustIDBase16(threeID),
},
wants: wants{
err: &platform.Error{
Code: platform.ENotFound,
Op: platform.OpFindUsers,
Msg: "user not found",
},
},
},
{
name: "find user by name not exists",
fields: UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "abc",
},
{
ID: MustIDBase16(userTwoID),
Name: "xyz",
},
},
},
args: args{
name: "no_exist",
},
wants: wants{
err: &platform.Error{
Code: platform.ENotFound,
Op: platform.OpFindUsers,
Msg: "user not found",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
2018-12-07 18:12:24 +00:00
s, opPrefix, done := init(tt.fields, t)
defer done()
ctx := context.Background()
filter := platform.UserFilter{}
if tt.args.ID.Valid() {
filter.ID = &tt.args.ID
}
if tt.args.name != "" {
filter.Name = &tt.args.name
}
users, _, err := s.FindUsers(ctx, filter)
2018-12-07 18:12:24 +00:00
diffPlatformErrors(tt.name, err, tt.wants.err, opPrefix, t)
if diff := cmp.Diff(users, tt.wants.users, userCmpOptions...); diff != "" {
t.Errorf("users are different -got/+want\ndiff %s", diff)
}
})
}
}
// DeleteUser testing
func DeleteUser(
2018-12-07 18:12:24 +00:00
init func(UserFields, *testing.T) (platform.UserService, string, func()),
t *testing.T,
) {
type args struct {
ID platform.ID
}
type wants struct {
err error
users []*platform.User
}
tests := []struct {
name string
fields UserFields
args args
wants wants
}{
{
name: "delete users using exist id",
fields: UserFields{
Users: []*platform.User{
{
Name: "orgA",
ID: MustIDBase16(userOneID),
},
{
Name: "orgB",
ID: MustIDBase16(userTwoID),
},
},
},
args: args{
ID: MustIDBase16(userOneID),
},
wants: wants{
users: []*platform.User{
{
Name: "orgB",
ID: MustIDBase16(userTwoID),
},
},
},
},
{
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
name: "delete users using id that does not exist",
fields: UserFields{
Users: []*platform.User{
{
Name: "orgA",
ID: MustIDBase16(userOneID),
},
{
Name: "orgB",
ID: MustIDBase16(userTwoID),
},
},
},
args: args{
ID: MustIDBase16(userThreeID),
},
wants: wants{
2018-12-07 18:12:24 +00:00
err: &platform.Error{
Code: platform.ENotFound,
Op: platform.OpDeleteUser,
Msg: "user not found",
},
users: []*platform.User{
{
Name: "orgA",
ID: MustIDBase16(userOneID),
},
{
Name: "orgB",
ID: MustIDBase16(userTwoID),
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
2018-12-07 18:12:24 +00:00
s, opPrefix, done := init(tt.fields, t)
defer done()
ctx := context.Background()
err := s.DeleteUser(ctx, tt.args.ID)
2018-12-07 18:12:24 +00:00
diffPlatformErrors(tt.name, err, tt.wants.err, opPrefix, t)
filter := platform.UserFilter{}
users, _, err := s.FindUsers(ctx, filter)
if err != nil {
t.Fatalf("failed to retrieve users: %v", err)
}
if diff := cmp.Diff(users, tt.wants.users, userCmpOptions...); diff != "" {
t.Errorf("users are different -got/+want\ndiff %s", diff)
}
})
}
}
// FindUser testing
func FindUser(
2018-12-07 18:12:24 +00:00
init func(UserFields, *testing.T) (platform.UserService, string, func()),
t *testing.T,
) {
type args struct {
filter platform.UserFilter
}
type wants struct {
user *platform.User
err error
}
tests := []struct {
name string
fields UserFields
args args
wants wants
}{
{
name: "find user by name",
fields: UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "abc",
},
{
ID: MustIDBase16(userTwoID),
Name: "xyz",
},
},
},
args: args{
filter: platform.UserFilter{
Name: func(s string) *string { return &s }("abc"),
},
},
wants: wants{
user: &platform.User{
ID: MustIDBase16(userOneID),
Name: "abc",
},
},
},
2018-10-11 17:06:10 +00:00
{
name: "find existing user by its id",
fields: UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "abc",
},
{
ID: MustIDBase16(userTwoID),
Name: "xyz",
},
},
},
args: args{
filter: platform.UserFilter{
ID: func(id platform.ID) *platform.ID { return &id }(MustIDBase16(userOneID)),
},
},
wants: wants{
user: &platform.User{
ID: MustIDBase16(userOneID),
Name: "abc",
},
},
},
{
name: "user with name does not exist",
fields: UserFields{
Users: []*platform.User{},
},
args: args{
filter: platform.UserFilter{
Name: func(s string) *string { return &s }("abc"),
},
},
wants: wants{
err: &platform.Error{
Code: platform.ENotFound,
Msg: "user not found",
Op: platform.OpFindUser,
},
},
},
{
name: "user with id does not exist",
2018-10-11 17:06:10 +00:00
fields: UserFields{
Users: []*platform.User{},
},
args: args{
filter: platform.UserFilter{
ID: func(id platform.ID) *platform.ID { return &id }(MustIDBase16(userOneID)),
},
},
wants: wants{
err: &platform.Error{
Code: platform.ENotFound,
Msg: "user not found",
Op: platform.OpFindUser,
},
},
},
{
name: "filter with both name and ID prefers ID",
fields: UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "abc",
},
{
ID: MustIDBase16(userTwoID),
Name: "xyz",
},
},
},
args: args{
filter: platform.UserFilter{
ID: func(id platform.ID) *platform.ID { return &id }(MustIDBase16(userOneID)),
Name: func(s string) *string { return &s }("xyz"),
},
},
wants: wants{
user: &platform.User{
ID: MustIDBase16(userOneID),
Name: "abc",
},
},
},
feat(kv): implemented key/value store with end-to-end integration tests * feat(kv:inmem:bolt): implement user service in a kv * refactor(kv): use consistent func receiver name * feat(kv): add initial basic auth service * refactor(passwords): move auth interface into own file * refactor(passwords): rename basic auth files to passwords * refactor(passwords): rename from BasicAuth to Passwords * refactor(kv): copy bolt user test into kv Co-authored-by: Michael Desa <mjdesa@gmail.com> * feat(kv): add inmem testing to kv store * fix(kv): remove extra user index initialization * feat(kv): attempt at making errors nice * fix(http): return not found error if filter is invalid * fix(http): s/platform/influxdb/ for user service * fix(http): s/platform/influxdb/ for user service * feat(kv): initial port of telegraf configs to kv * feat(kv): first pass at migrating bolt org service to kv * feat(kv): first pass at bucket service * feat(kv): first pass at migrating kvlog to kv package * feat(kv): add resource op logs * feat(kv): first pass at user resource mapping migration * feat(kv): add urm usage to bucket and org services * feat(kv): first pass at kv authz service * feat(kv): add cascading auth delete for users * feat(kv): first pass d authorizer.OrganizationService in kv * feat(cmd/influxd/launcher): user kv services where appropriate * fix(kv): initialize authorizations * fix(influxdb): use same buckets while slowly migrating stuff * fix(kv): make staticcheck pass * feat(kv): add dashboards to kv review: make suggestions from pr review fix: use common bucket names for bolt/kv stores * test(kv): add complete password test coverage * chore(kv): fixes for staticcheck * feat(kv): implement labels generically on kv * feat(kv): implement macro service * feat(kv): add source service * feat(kv): add session service * feat(kv): add kv secret service * refactor(kv): update telegraf and urm with error messages * feat(kv): add lookup service * feat(kv): add kv onboarding service * refactor(kv): update telegraf to avoid repetition * feat(cmd/influxd): use kv lookup service * feat(kv): add telegraf to lookup service * feat(cmd/influxd): use kv telegraf service * feat(kv): initial port of scrapers in bolt to kv * feat(kv): update scraper error messaging * feat(cmd/influxd): add kv scraper * feat(kv): add inmem backend tests * refactor(kv): copy paste errors * refactor(kv): add code to password errors * fix(testing): update error messages for incorrect passwords * feat(kv:inmem:bolt): implement user service in a kv * refactor(kv): use consistent func receiver name * refactor(kv): copy bolt user test into kv Co-authored-by: Michael Desa <mjdesa@gmail.com> * feat(kv): add inmem testing to kv store * fix(kv): remove extra user index initialization * feat(kv): attempt at making errors nice * fix(http): return not found error if filter is invalid * fix(http): s/platform/influxdb/ for user service * feat(kv): first pass at migrating bolt org service to kv * feat(kv): first pass at bucket service * feat(kv): first pass at migrating kvlog to kv package * feat(kv): add resource op logs * feat(kv): first pass at user resource mapping migration * feat(kv): add urm usage to bucket and org services * feat(kv): first pass at kv authz service * feat(kv): add cascading auth delete for users * feat(kv): first pass d authorizer.OrganizationService in kv * feat(cmd/influxd/launcher): user kv services where appropriate * feat(kv): add initial basic auth service * refactor(passwords): move auth interface into own file * refactor(passwords): rename basic auth files to passwords * fix(http): s/platform/influxdb/ for user service * fix(kv): initialize authorizations * fix(influxdb): use same buckets while slowly migrating stuff * fix(kv): make staticcheck pass * feat(kv): add dashboards to kv review: make suggestions from pr review fix: use common bucket names for bolt/kv stores * feat(kv): implement labels generically on kv * refactor(passwords): rename from BasicAuth to Passwords * test(kv): add complete password test coverage * chore(kv): fixes for staticcheck * feat(kv): implement macro service * feat(kv): add source service * feat(kv): add session service * feat(kv): initial port of telegraf configs to kv * feat(kv): initial port of scrapers in bolt to kv * feat(kv): add kv secret service * refactor(kv): update telegraf and urm with error messages * feat(kv): add lookup service * feat(kv): add kv onboarding service * refactor(kv): update telegraf to avoid repetition * feat(cmd/influxd): use kv lookup service * feat(kv): add telegraf to lookup service * feat(cmd/influxd): use kv telegraf service * feat(kv): update scraper error messaging * feat(cmd/influxd): add kv scraper * feat(kv): add inmem backend tests * refactor(kv): copy paste errors * refactor(kv): add code to password errors * fix(testing): update error messages for incorrect passwords * feat(http): initial support for flushing all key/values from kv store * feat(kv): rename macro to variable * feat(cmd/influxd/launcher): user kv services where appropriate * refactor(passwords): rename from BasicAuth to Passwords * feat(kv): implement macro service * test(ui): introduce cypress * test(ui): introduce first typescript test * test(ui/e2e): add ci job * chore: update gitignore to ignore test outputs * feat(inmem): in memory influxdb * test(e2e): adding pinger that checks if influxdb is alive * hackathon * hack * hack * hack * hack * Revert "feat(inmem): in memory influxdb" This reverts commit 30ddf032003e704643b07ce80df61c3299ea7295. * hack * hack * hack * hack * hack * hack * hack * hack * hack * hack * hack * hack * hack * chore: lint ignore node_modules * hack * hack * hack * add user and flush * hack * remove unused vars * hack * hack * ci(circle): prefix e2e artifacts * change test to testid * update cypress * moar testid * fix npm warnings * remove absolte path * chore(ci): remove /home/circleci proto mkdir hack * wip: crud resources e2e * fix(inmem): use inmem kv store services * test(dashboard): add first dashboard crud tests * hack * undo hack * fix: use response from setup for orgID * chore: wip * add convenience getByTitle function * test(e2e): ui can create orgs * test(e2e): add test for org deletion and update * test(e2e): introduce task creation test * test(e2e): create and update of buckets on org view * chore: move types to declaration file * chore: use route fixture in dashboard tests * chore(ci): hack back * test(ui): update snapshots * chore: package-lock * chore: remove macros * fix: launcher rebase issues * fix: compile errors * fix: compile errors * feat(cmd/influxdb): add explicit testing, asset-path, and store flags Co-authored-by: Andrew Watkins <watts@influxdb.com> * fix(cmd/influxd): set default HTTP handler and flags Co-authored-by: Andrew Watkins <watts@influxdb.com> * build(Makefile): add run-e2e and PHONY * feat(kv:inmem:bolt): implement user service in a kv * refactor(kv): use consistent func receiver name * feat(kv): add initial basic auth service * refactor(passwords): move auth interface into own file * refactor(passwords): rename basic auth files to passwords * refactor(passwords): rename from BasicAuth to Passwords * refactor(kv): copy bolt user test into kv Co-authored-by: Michael Desa <mjdesa@gmail.com> * feat(kv): add inmem testing to kv store * fix(kv): remove extra user index initialization * feat(kv): attempt at making errors nice * fix(http): return not found error if filter is invalid * fix(http): s/platform/influxdb/ for user service * fix(http): s/platform/influxdb/ for user service * feat(kv): initial port of telegraf configs to kv * feat(kv): initial port of scrapers in bolt to kv * feat(kv): first pass at migrating bolt org service to kv * feat(kv): first pass at bucket service * feat(kv): first pass at migrating kvlog to kv package * feat(kv): add resource op logs * feat(kv): first pass at user resource mapping migration * feat(kv): add urm usage to bucket and org services * feat(kv): first pass at kv authz service * feat(kv): add cascading auth delete for users * feat(kv): first pass d authorizer.OrganizationService in kv * feat(cmd/influxd/launcher): user kv services where appropriate * fix(kv): initialize authorizations * fix(influxdb): use same buckets while slowly migrating stuff * fix(kv): make staticcheck pass * feat(kv): add dashboards to kv review: make suggestions from pr review fix: use common bucket names for bolt/kv stores * test(kv): add complete password test coverage * chore(kv): fixes for staticcheck * feat(kv): implement labels generically on kv * feat(kv): implement macro service * feat(kv): add source service * feat(kv): add session service * feat(kv): add kv secret service * refactor(kv): update telegraf and urm with error messages * feat(kv): add lookup service * feat(kv): add kv onboarding service * refactor(kv): update telegraf to avoid repetition * feat(cmd/influxd): use kv lookup service * feat(kv): add telegraf to lookup service * feat(cmd/influxd): use kv telegraf service * feat(kv): update scraper error messaging * feat(cmd/influxd): add kv scraper * feat(kv): add inmem backend tests * refactor(kv): copy paste errors * refactor(kv): add code to password errors * fix(testing): update error messages for incorrect passwords * feat(kv): rename macro to variable * refactor(kv): auth/bucket/org/user unique checks return errors now * feat(inmem): add way to get all bucket names from store * feat(inmem): Buckets to return slice of bytes rather than strings * feat(inmem): add locks around Buckets to avoid races * feat(cmd/influx): check for unauthorized error in wrapCheckSetup * chore(e2e): add video and screenshot artifcats to gitignore * docs(ci): add build instructions for e2e tests * feat(kv): add id lookup for authorized resources
2019-02-19 23:47:19 +00:00
{
name: "filter with no name nor id returns error",
fields: UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userTwoID),
Name: "xyz",
},
},
},
args: args{
filter: platform.UserFilter{},
},
wants: wants{
err: &platform.Error{
Code: platform.ENotFound,
Msg: "user not found",
Op: platform.OpFindUser,
},
},
},
{
name: "filter both name and non-existent id returns no user",
fields: UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userTwoID),
Name: "xyz",
},
},
},
args: args{
filter: platform.UserFilter{
ID: func(id platform.ID) *platform.ID { return &id }(MustIDBase16(userOneID)),
Name: func(s string) *string { return &s }("xyz"),
},
2018-10-11 17:06:10 +00:00
},
wants: wants{
2018-12-07 18:12:24 +00:00
err: &platform.Error{
Code: platform.ENotFound,
Msg: "user not found",
Op: platform.OpFindUser,
},
2018-10-11 17:06:10 +00:00
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
2018-12-07 18:12:24 +00:00
s, opPrefix, done := init(tt.fields, t)
defer done()
ctx := context.Background()
user, err := s.FindUser(ctx, tt.args.filter)
2018-12-07 18:12:24 +00:00
diffPlatformErrors(tt.name, err, tt.wants.err, opPrefix, t)
if diff := cmp.Diff(user, tt.wants.user, userCmpOptions...); diff != "" {
t.Errorf("users are different -got/+want\ndiff %s", diff)
}
})
}
}
// UpdateUser testing
func UpdateUser(
2018-12-07 18:12:24 +00:00
init func(UserFields, *testing.T) (platform.UserService, string, func()),
t *testing.T,
) {
type args struct {
name string
id platform.ID
}
type wants struct {
err error
user *platform.User
}
tests := []struct {
name string
fields UserFields
args args
wants wants
}{
{
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
name: "update name",
fields: UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "user1",
},
{
ID: MustIDBase16(userTwoID),
Name: "user2",
},
},
},
args: args{
id: MustIDBase16(userOneID),
name: "changed",
},
wants: wants{
user: &platform.User{
ID: MustIDBase16(userOneID),
Name: "changed",
},
},
},
2018-12-07 18:12:24 +00:00
{
name: "update name with id not exists",
fields: UserFields{
Users: []*platform.User{
{
ID: MustIDBase16(userOneID),
Name: "user1",
},
{
ID: MustIDBase16(userTwoID),
Name: "user2",
},
},
},
args: args{
id: MustIDBase16(threeID),
name: "changed",
},
wants: wants{
err: &platform.Error{
Code: platform.ENotFound,
Op: platform.OpUpdateUser,
Msg: "user not found",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
2018-12-07 18:12:24 +00:00
s, opPrefix, done := init(tt.fields, t)
defer done()
ctx := context.Background()
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
upd := platform.UserUpdate{}
if tt.args.name != "" {
upd.Name = &tt.args.name
}
user, err := s.UpdateUser(ctx, tt.args.id, upd)
2018-12-07 18:12:24 +00:00
diffPlatformErrors(tt.name, err, tt.wants.err, opPrefix, t)
if diff := cmp.Diff(user, tt.wants.user, userCmpOptions...); diff != "" {
t.Errorf("user is different -got/+want\ndiff %s", diff)
}
})
}
}