Пример #1
0
func deleteWithConfirmation(t *testing.T, confirmation string) (ui *testterm.FakeUI, userRepo *testapi.FakeUserRepository) {
	ui = &testterm.FakeUI{
		Inputs: []string{confirmation},
	}
	user2 := cf.UserFields{}
	user2.Username = "******"
	user2.Guid = "my-found-user-guid"
	userRepo = &testapi.FakeUserRepository{
		FindByUsernameUserFields: user2,
	}

	token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
		Username: "******",
	})
	assert.NoError(t, err)
	org2 := cf.OrganizationFields{}
	org2.Name = "my-org"
	space2 := cf.SpaceFields{}
	space2.Name = "my-space"
	config := &configuration.Configuration{
		SpaceFields:        space2,
		OrganizationFields: org2,
		AccessToken:        token,
	}

	cmd := NewDeleteUser(ui, config, userRepo)

	ctxt := testcmd.NewContext("delete-user", []string{"my-user"})
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}

	testcmd.RunCommand(cmd, ctxt, reqFactory)
	return
}
Пример #2
0
func TestUnsetSpaceRole(t *testing.T) {
	user := cf.UserFields{}
	user.Username = "******"
	user.Guid = "some-user-guid"
	org := cf.Organization{}
	org.Name = "some-org"
	org.Guid = "some-org-guid"

	reqFactory, spaceRepo, userRepo := getUnsetSpaceRoleDeps()
	reqFactory.LoginSuccess = true
	reqFactory.UserFields = user
	reqFactory.Organization = org
	spaceRepo.FindByNameInOrgSpace = cf.Space{}
	spaceRepo.FindByNameInOrgSpace.Name = "some-space"
	spaceRepo.FindByNameInOrgSpace.Guid = "some-space-guid"

	args := []string{"my-username", "my-org", "my-space", "SpaceManager"}

	ui := callUnsetSpaceRole(t, args, spaceRepo, userRepo, reqFactory)

	assert.Equal(t, spaceRepo.FindByNameInOrgName, "my-space")
	assert.Equal(t, spaceRepo.FindByNameInOrgOrgGuid, "some-org-guid")

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Removing role", "SpaceManager", "some-user", "some-org", "some-space", "current-user"},
		{"OK"},
	})
	assert.Equal(t, userRepo.UnsetSpaceRoleRole, cf.SPACE_MANAGER)
	assert.Equal(t, userRepo.UnsetSpaceRoleUserGuid, "some-user-guid")
	assert.Equal(t, userRepo.UnsetSpaceRoleSpaceGuid, "some-space-guid")
}
Пример #3
0
func TestUnsetOrgRole(t *testing.T) {
	userRepo := &testapi.FakeUserRepository{}
	user := cf.UserFields{}
	user.Username = "******"
	user.Guid = "some-user-guid"
	org := cf.Organization{}
	org.Name = "some-org"
	org.Guid = "some-org-guid"
	reqFactory := &testreq.FakeReqFactory{
		LoginSuccess: true,
		UserFields:   user,
		Organization: org,
	}
	args := []string{"my-username", "my-org", "OrgManager"}

	ui := callUnsetOrgRole(t, args, userRepo, reqFactory)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Removing role", "OrgManager", "my-username", "my-org", "current-user"},
		{"OK"},
	})

	assert.Equal(t, userRepo.UnsetOrgRoleRole, cf.ORG_MANAGER)
	assert.Equal(t, userRepo.UnsetOrgRoleUserGuid, "some-user-guid")
	assert.Equal(t, userRepo.UnsetOrgRoleOrganizationGuid, "some-org-guid")
}
Пример #4
0
func TestSpaceUsers(t *testing.T) {
	org := cf.Organization{}
	org.Name = "Org1"
	org.Guid = "org1-guid"
	space := cf.Space{}
	space.Name = "Space1"
	space.Guid = "space1-guid"

	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, Organization: org}
	spaceRepo := &testapi.FakeSpaceRepository{FindByNameInOrgSpace: space}
	userRepo := &testapi.FakeUserRepository{}

	user := cf.UserFields{}
	user.Username = "******"
	user2 := cf.UserFields{}
	user2.Username = "******"
	user3 := cf.UserFields{}
	user3.Username = "******"
	user4 := cf.UserFields{}
	user4.Username = "******"
	userRepo.ListUsersByRole = map[string][]cf.UserFields{
		cf.SPACE_MANAGER:   []cf.UserFields{user, user2},
		cf.SPACE_DEVELOPER: []cf.UserFields{user4},
		cf.SPACE_AUDITOR:   []cf.UserFields{user3},
	}

	ui := callSpaceUsers(t, []string{"my-org", "my-space"}, reqFactory, spaceRepo, userRepo)

	assert.Equal(t, spaceRepo.FindByNameInOrgName, "my-space")
	assert.Equal(t, spaceRepo.FindByNameInOrgOrgGuid, "org1-guid")
	assert.Equal(t, userRepo.ListUsersSpaceGuid, "space1-guid")

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Getting users in org", "Org1", "Space1", "my-user"},
		{"SPACE MANAGER"},
		{"user1"},
		{"user2"},
		{"SPACE DEVELOPER"},
		{"user4"},
		{"SPACE AUDITOR"},
		{"user3"},
	})
}
Пример #5
0
func TestUserReqExecute(t *testing.T) {
	user := cf.UserFields{}
	user.Username = "******"
	user.Guid = "my-user-guid"

	userRepo := &testapi.FakeUserRepository{FindByUsernameUserFields: user}
	ui := new(testterm.FakeUI)

	userReq := newUserRequirement("foo", ui, userRepo)
	success := userReq.Execute()

	assert.True(t, success)
	assert.Equal(t, userRepo.FindByUsernameUsername, "foo")
	assert.Equal(t, userReq.GetUser(), user)
}
Пример #6
0
func TestFindByUsername(t *testing.T) {
	usersResponse := `{ "resources": [
        { "id": "my-guid", "userName": "******" }
    ]}`

	uaaReq := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "GET",
		Path:     "/Users?attributes=id,userName&filter=userName+Eq+%22damien%2Buser1%40pivotallabs.com%22",
		Response: testnet.TestResponse{Status: http.StatusOK, Body: usersResponse},
	})

	uaa, handler, repo := createUsersRepoWithoutCCEndpoints(t, []testnet.TestRequest{uaaReq})
	defer uaa.Close()

	user, apiResponse := repo.FindByUsername("*****@*****.**")
	assert.True(t, handler.AllRequestsCalled())
	assert.True(t, apiResponse.IsSuccessful())

	expectedUserFields := cf.UserFields{}
	expectedUserFields.Username = "******"
	expectedUserFields.Guid = "my-guid"
	assert.Equal(t, user, expectedUserFields)
}