Ejemplo n.º 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
}
Ejemplo n.º 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")
}
Ejemplo n.º 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")
}
Ejemplo n.º 4
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)
}
Ejemplo n.º 5
0
func TestDeleteUserWithForceOption(t *testing.T) {
	foundUserFields := cf.UserFields{}
	foundUserFields.Guid = "my-found-user-guid"
	userRepo := &testapi.FakeUserRepository{FindByUsernameUserFields: foundUserFields}
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}

	ui := callDeleteUser(t, []string{"-f", "my-user"}, userRepo, reqFactory)

	assert.Equal(t, len(ui.Outputs), 2)
	assert.Equal(t, len(ui.Prompts), 0)
	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting user", "my-user"},
		{"OK"},
	})

	assert.Equal(t, userRepo.FindByUsernameUsername, "my-user")
	assert.Equal(t, userRepo.DeleteUserGuid, "my-found-user-guid")
}
Ejemplo n.º 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)
}