Example #1
0
func TestListingUserRoles(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	mockListRolesResponse(t)

	tenantID := "1d8b6120dcc640fda4fc9194ffc80273"
	userID := "c39e3de9be2d4c779f1dfd6abacc176d"

	err := users.ListRoles(client.ServiceClient(), tenantID, userID).EachPage(func(page pagination.Page) (bool, error) {
		actual, err := users.ExtractRoles(page)
		th.AssertNoErr(t, err)

		expected := []users.Role{
			{ID: "9fe2ff9ee4384b1894a90878d3e92bab", Name: "foo_role"},
			{ID: "1ea3d56793574b668e85960fbf651e13", Name: "admin"},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	th.AssertNoErr(t, err)
}
Example #2
0
func TestRolesAddToUser(t *testing.T) {
	client, err := clients.NewIdentityV2AdminClient()
	if err != nil {
		t.Fatalf("Unable to obtain an identity client: %v", err)
	}

	tenant, err := FindTenant(t, client)
	if err != nil {
		t.Fatalf("Unable to get a tenant: %v", err)
	}

	role, err := FindRole(t, client)
	if err != nil {
		t.Fatalf("Unable to get a role: %v", err)
	}

	user, err := CreateUser(t, client, tenant)
	if err != nil {
		t.Fatalf("Unable to create a user: %v", err)
	}
	defer DeleteUser(t, client, user)

	err = AddUserRole(t, client, tenant, user, role)
	if err != nil {
		t.Fatalf("Unable to add role to user: %v", err)
	}
	defer DeleteUserRole(t, client, tenant, user, role)

	allPages, err := users.ListRoles(client, tenant.ID, user.ID).AllPages()
	if err != nil {
		t.Fatalf("Unable to obtain roles for user: %v", err)
	}

	allRoles, err := users.ExtractRoles(allPages)
	if err != nil {
		t.Fatalf("Unable to extract roles: %v", err)
	}

	t.Logf("Roles of user %s:", user.Name)
	for _, role := range allRoles {
		PrintUserRole(t, &role)
	}
}