Update anon listing test (#917)

This commit is contained in:
Louis Ruch authored and GitHub committed 2021-02-05 14:00:19 -05:00
1 parent 628a02ad15
commit 6e40d8e483
1 file changed
+2 -25
+2 -25
View File
@@ -1,10 +1,8 @@
package cluster
import (
"fmt"
"testing"
"github.com/hashicorp/boundary/api/roles"
"github.com/hashicorp/boundary/api/scopes"
"github.com/hashicorp/boundary/internal/cmd/config"
"github.com/hashicorp/boundary/internal/servers/controller"
@@ -29,31 +27,10 @@ func TestAnonListing(t *testing.T) {
})
defer c1.Shutdown()
// Should get no scopes back because anon user doesn't have permissions
// Anon user has list and read permissions on scopes by default,
// verify that list scopes returns expected scope without setting token
client := c1.Client()
scps, err := scopes.NewClient(client).List(c1.Context(), scope.Global.String())
require.NoError(err)
require.Len(scps.Items, 0)
// Authenticate as admin
client.SetToken(c1.Token().Token)
// Should get an org scope back
scps, err = scopes.NewClient(client).List(c1.Context(), scope.Global.String())
require.NoError(err)
require.Len(scps.Items, 1)
// Create a new role, give read action on the scope, add u_anon
orgId := scps.Items[0].Id
role, err := roles.NewClient(client).Create(c1.Context(), scope.Global.String())
require.NoError(err)
_, err = roles.NewClient(client).AddGrants(c1.Context(), role.Item.Id, 0, []string{fmt.Sprintf("id=%s;actions=read", orgId)}, roles.WithAutomaticVersioning(true))
require.NoError(err)
_, err = roles.NewClient(client).AddPrincipals(c1.Context(), role.Item.Id, 0, []string{"u_anon"}, roles.WithAutomaticVersioning(true))
require.NoError(err)
// Go back to anonymous
client.SetToken("")
scps, err = scopes.NewClient(client).List(c1.Context(), scope.Global.String())
require.NoError(err)
require.Len(scps.Items, 1)
}