Remove the default org (#270)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-08-17 15:38:41 -04:00
1 parent 01059e6ca8
commit 282177afc2
24 files changed
+190 -431

No files matched your search

+13 -8
View File
@@ -8,6 +8,7 @@ import (
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/authmethods"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/servers/controller"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -15,11 +16,9 @@ import (
func TestAccounts_List(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -27,6 +26,9 @@ func TestAccounts_List(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
org := iam.TestOrg(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
accountClient := authmethods.NewAccountsClient(client)
expected, apiErr, err := accountClient.List(tc.Context(), amId)
@@ -76,11 +78,9 @@ func comparableSlice(in []*authmethods.Account) []authmethods.Account {
func TestAccount_Crud(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -88,6 +88,9 @@ func TestAccount_Crud(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
org := iam.TestOrg(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
accountClient := authmethods.NewAccountsClient(client)
checkAccount := func(step string, u *authmethods.Account, apiErr *api.Error, err error, wantedName string, wantedVersion uint32) {
@@ -129,11 +132,9 @@ func TestAccount_Crud(t *testing.T) {
func TestAccount_CustomMethods(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -141,6 +142,9 @@ func TestAccount_CustomMethods(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
org := iam.TestOrg(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
accountClient := authmethods.NewAccountsClient(client)
al, apiErr, err := accountClient.List(tc.Context(), amId)
@@ -165,11 +169,9 @@ func TestAccount_CustomMethods(t *testing.T) {
func TestAccount_Errors(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -177,6 +179,9 @@ func TestAccount_Errors(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
org := iam.TestOrg(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
accountClient := authmethods.NewAccountsClient(client)
u, apiErr, err := accountClient.Create(tc.Context(), amId, authmethods.WithType("password"), authmethods.WithPasswordAccountLoginName("first"))
+9 -25
View File
@@ -7,7 +7,6 @@ import (
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/groups"
"github.com/hashicorp/boundary/api/scopes"
"github.com/hashicorp/boundary/api/users"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/servers/controller"
@@ -17,11 +16,9 @@ import (
func TestGroup_List(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -29,13 +26,10 @@ func TestGroup_List(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
proj, apiErr, err := scopes.NewScopesClient(client).Create(tc.Context(), orgId)
require.NoError(err)
require.Nil(apiErr)
org, proj := iam.TestScopes(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
projClient := client.Clone()
projClient.SetScopeId(proj.Id)
projClient.SetScopeId(proj.GetPublicId())
cases := []struct {
name string
@@ -92,11 +86,9 @@ func comparableSlice(in []*groups.Group) []groups.Group {
func TestGroup_Crud(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -104,13 +96,10 @@ func TestGroup_Crud(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
proj, apiErr, err := scopes.NewScopesClient(client).Create(tc.Context(), orgId)
require.NoError(err)
require.Nil(apiErr)
org, proj := iam.TestScopes(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
projClient := client.Clone()
projClient.SetScopeId(proj.Id)
projClient.SetScopeId(proj.GetPublicId())
checkGroup := func(step string, g *groups.Group, apiErr *api.Error, err error, wantedName string, wantedVersion uint32, expectedUserIds []string) {
require.NoError(err, step)
@@ -189,11 +178,9 @@ func TestGroup_Crud(t *testing.T) {
func TestGroup_Errors(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -201,13 +188,10 @@ func TestGroup_Errors(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
proj, apiErr, err := scopes.NewScopesClient(client).Create(tc.Context(), orgId)
require.NoError(err)
require.Nil(apiErr)
org, proj := iam.TestScopes(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
projClient := client.Clone()
projClient.SetScopeId(proj.Id)
projClient.SetScopeId(proj.GetPublicId())
cases := []struct {
name string
+6 -17
View File
@@ -6,8 +6,8 @@ import (
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/hosts"
"github.com/hashicorp/boundary/api/scopes"
"github.com/hashicorp/boundary/internal/host/static"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/servers/controller"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -15,11 +15,9 @@ import (
func TestCatalogs_Crud(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -27,13 +25,10 @@ func TestCatalogs_Crud(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
proj, apiErr, err := scopes.NewScopesClient(client).Create(tc.Context(), orgId)
require.NoError(err)
require.Nil(apiErr)
org, proj := iam.TestScopes(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
projClient := client.Clone()
projClient.SetScopeId(proj.Id)
projClient.SetScopeId(proj.GetPublicId())
checkCatalog := func(step string, hc *hosts.HostCatalog, apiErr *api.Error, err error, wantedName string, wantVersion uint32) {
require.NoError(err, step)
@@ -75,11 +70,9 @@ func TestCatalogs_Crud(t *testing.T) {
// TODO: Get better coverage for expected errors and error formats.
func TestCatalogs_Errors(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -87,12 +80,8 @@ func TestCatalogs_Errors(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
proj, apiErr, err := scopes.NewScopesClient(client).Create(tc.Context(), orgId)
require.NoError(err)
require.Nil(apiErr)
client.SetScopeId(proj.Id)
_, proj := iam.TestScopes(t, tc.DbConn())
client.SetScopeId(proj.GetPublicId())
pc := hosts.NewHostCatalogsClient(client)
hc, apiErr, err := pc.Create(tc.Context(), hosts.WithType("static"))
+15 -55
View File
@@ -7,9 +7,7 @@ import (
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/groups"
"github.com/hashicorp/boundary/api/internal/strutil"
"github.com/hashicorp/boundary/api/roles"
"github.com/hashicorp/boundary/api/scopes"
"github.com/hashicorp/boundary/api/users"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/servers/controller"
@@ -20,11 +18,9 @@ import (
func TestCustom(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -32,13 +28,10 @@ func TestCustom(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
proj, apiErr, err := scopes.NewScopesClient(client).Create(tc.Context(), orgId)
require.NoError(err)
require.Nil(apiErr)
org, proj := iam.TestScopes(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
projClient := client.Clone()
projClient.SetScopeId(proj.Id)
projClient.SetScopeId(proj.GetPublicId())
cases := []struct {
name string
@@ -138,11 +131,9 @@ func TestCustom(t *testing.T) {
func TestRole_List(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -150,13 +141,10 @@ func TestRole_List(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
proj, apiErr, err := scopes.NewScopesClient(client).Create(tc.Context(), orgId)
require.NoError(err)
require.Nil(apiErr)
org, proj := iam.TestScopes(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
projClient := client.Clone()
projClient.SetScopeId(proj.Id)
projClient.SetScopeId(proj.GetPublicId())
cases := []struct {
name string
@@ -178,13 +166,7 @@ func TestRole_List(t *testing.T) {
p1, apiErr, err := roleClient.List(tc.Context())
require.NoError(err)
assert.Nil(apiErr)
var defaultRoleIds []string
if tt.name == "org" {
require.True(len(p1) == 2)
defaultRoleIds = []string{p1[0].Id, p1[1].Id}
} else {
require.Len(p1, 0)
}
require.Len(p1, 0)
var expected []*roles.Role
for i := 0; i < 10; i++ {
@@ -198,13 +180,7 @@ func TestRole_List(t *testing.T) {
p2, apiErr, err := roleClient.List(tc.Context())
assert.NoError(err)
assert.Nil(apiErr)
var p2ForComparison []*roles.Role
for _, v := range p2 {
if !strutil.StrListContains(defaultRoleIds, v.Id) {
p2ForComparison = append(p2ForComparison, v)
}
}
assert.ElementsMatch(comparableSlice(expected[:1]), comparableSlice(p2ForComparison))
assert.ElementsMatch(comparableSlice(expected[:1]), comparableSlice(p2))
for i := 1; i < 10; i++ {
expected[i], apiErr, err = roleClient.Create(tc.Context(), roles.WithName(expected[i].Name))
@@ -214,13 +190,7 @@ func TestRole_List(t *testing.T) {
p3, apiErr, err := roleClient.List(tc.Context())
require.NoError(err)
assert.Nil(apiErr)
var p3ForComparison []*roles.Role
for _, v := range p3 {
if !strutil.StrListContains(defaultRoleIds, v.Id) {
p3ForComparison = append(p3ForComparison, v)
}
}
assert.ElementsMatch(comparableSlice(expected), comparableSlice(p3ForComparison))
assert.ElementsMatch(comparableSlice(expected), comparableSlice(p3))
})
}
}
@@ -242,11 +212,9 @@ func comparableSlice(in []*roles.Role) []roles.Role {
func TestRole_Crud(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -254,13 +222,10 @@ func TestRole_Crud(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
proj, apiErr, err := scopes.NewScopesClient(client).Create(tc.Context(), orgId)
require.NoError(err)
require.Nil(apiErr)
org, proj := iam.TestScopes(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
projClient := client.Clone()
projClient.SetScopeId(proj.Id)
projClient.SetScopeId(proj.GetPublicId())
cases := []struct {
name string
@@ -320,11 +285,9 @@ func TestRole_Crud(t *testing.T) {
func TestRole_Errors(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -332,13 +295,10 @@ func TestRole_Errors(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
proj, apiErr, err := scopes.NewScopesClient(client).Create(tc.Context(), orgId)
require.NoError(err)
require.Nil(apiErr)
org, proj := iam.TestScopes(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
projClient := client.Clone()
projClient.SetScopeId(proj.Id)
projClient.SetScopeId(proj.GetPublicId())
cases := []struct {
name string
+15 -11
View File
@@ -7,6 +7,7 @@ import (
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/scopes"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/servers/controller"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -14,11 +15,9 @@ import (
func TestProjects_List(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -26,20 +25,23 @@ func TestProjects_List(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
org := iam.TestOrg(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
scps := scopes.NewScopesClient(client)
pl, apiErr, err := scps.List(tc.Context(), orgId)
pl, apiErr, err := scps.List(tc.Context(), org.GetPublicId())
require.NoError(err)
assert.Nil(apiErr)
assert.Empty(pl)
expected := make([]*scopes.Scope, 10)
for i := 0; i < 10; i++ {
expected[i], apiErr, err = scps.Create(tc.Context(), orgId, scopes.WithName(fmt.Sprintf("%d", i)))
expected[i], apiErr, err = scps.Create(tc.Context(), org.GetPublicId(), scopes.WithName(fmt.Sprintf("%d", i)))
require.NoError(err)
assert.Nil(apiErr)
}
pl, apiErr, err = scps.List(tc.Context(), orgId)
pl, apiErr, err = scps.List(tc.Context(), org.GetPublicId())
require.NoError(err)
assert.Nil(apiErr)
assert.ElementsMatch(comparableSlice(expected), comparableSlice(pl))
@@ -62,11 +64,9 @@ func comparableSlice(in []*scopes.Scope) []scopes.Scope {
func TestProjects_Crud(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -74,6 +74,9 @@ func TestProjects_Crud(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
org, _ := iam.TestScopes(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
scps := scopes.NewScopesClient(client)
checkProject := func(step string, s *scopes.Scope, apiErr *api.Error, err error, wantedName string, wantedVersion uint32) {
@@ -88,7 +91,7 @@ func TestProjects_Crud(t *testing.T) {
assert.Equal(wantedVersion, s.Version)
}
s, apiErr, err := scps.Create(tc.Context(), orgId, scopes.WithName("foo"))
s, apiErr, err := scps.Create(tc.Context(), org.GetPublicId(), scopes.WithName("foo"))
checkProject("create", s, apiErr, err, "foo", 1)
s, apiErr, err = scps.Read(tc.Context(), s.Id)
@@ -114,11 +117,9 @@ func TestProjects_Crud(t *testing.T) {
// TODO: Get better coverage for expected errors and error formats.
func TestProject_Errors(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -126,9 +127,12 @@ func TestProject_Errors(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
org, _ := iam.TestScopes(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
scps := scopes.NewScopesClient(client)
createdProj, apiErr, err := scps.Create(tc.Context(), orgId)
createdProj, apiErr, err := scps.Create(tc.Context(), org.GetPublicId())
require.NoError(err)
assert.NotNil(createdProj)
assert.Nil(apiErr)
+6 -6
View File
@@ -15,11 +15,9 @@ import (
func TestUsers_List(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -27,6 +25,8 @@ func TestUsers_List(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
org := iam.TestOrg(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
userClient := users.NewUsersClient(client)
ul, apiErr, err := userClient.List(tc.Context())
@@ -76,11 +76,9 @@ func comparableSlice(in []*users.User) []users.User {
func TestUser_Crud(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -88,6 +86,8 @@ func TestUser_Crud(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
org := iam.TestOrg(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
userClient := users.NewUsersClient(client)
checkUser := func(step string, u *users.User, apiErr *api.Error, err error, wantedName string, wantedVersion uint32) {
@@ -129,11 +129,9 @@ func TestUser_Crud(t *testing.T) {
func TestUser_Errors(t *testing.T) {
assert, require := assert.New(t), require.New(t)
orgId := "o_1234567890"
amId := "paum_1234567890"
tc := controller.NewTestController(t, &controller.TestControllerOpts{
DisableAuthorizationFailures: true,
DefaultOrgId: orgId,
DefaultAuthMethodId: amId,
DefaultLoginName: "user",
DefaultPassword: "passpass",
@@ -141,6 +139,8 @@ func TestUser_Errors(t *testing.T) {
defer tc.Shutdown()
client := tc.Client()
org := iam.TestOrg(t, tc.DbConn())
client.SetScopeId(org.GetPublicId())
userClient := users.NewUsersClient(client)
u, apiErr, err := userClient.Create(tc.Context(), users.WithName("first"))