Skip to content

Commit

Permalink
Merge branch 'enable-tokens-tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Harris authored and Paul Harris committed Jul 26, 2016
2 parents 347d865 + 62326a0 commit 23f8255
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ abstract class _Invite {
* The invite link
*/
@JsonProperty("inviteLink")
@Nullable
abstract String getInviteLink();

/**
* The origin
*/
@JsonProperty("origin")
@Nullable
abstract String getOrigin();

/**
Expand All @@ -70,6 +72,7 @@ abstract class _Invite {
* The user id
*/
@JsonProperty("userId")
@Nullable
abstract String getUserId();

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ public class IntegrationTestConfiguration {

private static final List<String> GROUPS = Arrays.asList(
"cloud_controller.admin",
"scim.create",
"scim.invite",
"scim.read",
"scim.userids",
"scim.write",
"zones.read",
"zones.write");
Expand All @@ -85,7 +88,11 @@ public class IntegrationTestConfiguration {
"cloud_controller.admin",
"cloud_controller.read",
"cloud_controller.write",
"password.write",
"scim.create",
"scim.invite",
"scim.read",
"scim.userids",
"scim.write",
"uaa.user",
"zones.read",
Expand Down
64 changes: 50 additions & 14 deletions integration-test/src/test/java/org/cloudfoundry/uaa/UsersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,61 @@

import org.cloudfoundry.AbstractIntegrationTest;
import org.cloudfoundry.uaa.users.ChangeUserPasswordRequest;
import org.cloudfoundry.uaa.users.ChangeUserPasswordResponse;
import org.cloudfoundry.uaa.users.CreateUserRequest;
import org.cloudfoundry.uaa.users.CreateUserResponse;
import org.cloudfoundry.uaa.users.DeleteUserRequest;
import org.cloudfoundry.uaa.users.DeleteUserResponse;
import org.cloudfoundry.uaa.users.Email;
import org.cloudfoundry.uaa.users.GetUserVerificationLinkRequest;
import org.cloudfoundry.uaa.users.GetUserVerificationLinkResponse;
import org.cloudfoundry.uaa.users.Invite;
import org.cloudfoundry.uaa.users.InviteUsersRequest;
import org.cloudfoundry.uaa.users.InviteUsersResponse;
import org.cloudfoundry.uaa.users.ListUsersRequest;
import org.cloudfoundry.uaa.users.ListUsersResponse;
import org.cloudfoundry.uaa.users.LookupUserIdsRequest;
import org.cloudfoundry.uaa.users.LookupUserIdsResponse;
import org.cloudfoundry.uaa.users.Name;
import org.cloudfoundry.uaa.users.UpdateUserRequest;
import org.cloudfoundry.uaa.users.User;
import org.cloudfoundry.uaa.users.UserId;
import org.cloudfoundry.uaa.users.VerifyUserRequest;
import org.cloudfoundry.uaa.users.VerifyUserResponse;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public final class UsersTest extends AbstractIntegrationTest {

@Autowired
private String password;

@Autowired
private UaaClient uaaClient;

@Ignore("TODO: finish story https://www.pivotaltracker.com/projects/816799/stories/122457091 to grant password.write scope")
@Autowired
private String username;

@Test
public void changePassword() {
String userName = getUserName();

createUserId(this.uaaClient, userName)
getUserIdByUsername(this.uaaClient, this.username)
.then(userId -> this.uaaClient.users()
.changePassword(ChangeUserPasswordRequest.builder()
.oldPassword("test-password")
.oldPassword(this.password)
.password("test-new-password")
.userId(userId)
.build()))
.subscribe(this.testSubscriber());
.subscribe(this.<ChangeUserPasswordResponse>testSubscriber()
.assertThat(response -> {
assertEquals("password updated", response.getMessage());
assertEquals("ok", response.getStatus());
}));
}

@Test
Expand Down Expand Up @@ -102,7 +116,6 @@ public void delete() {
.assertEquals(0));
}

@Ignore("TODO: finish story https://www.pivotaltracker.com/projects/816799/stories/122457091 to grant scim.create, zones.uaa.admin scopes")
@Test
public void getVerificationLink() {
String userName = getUserName();
Expand All @@ -113,18 +126,25 @@ public void getVerificationLink() {
.redirectUri("test-redirect-uri")
.userId(userId)
.build()))
.subscribe(this.testSubscriber());
.map(GetUserVerificationLinkResponse::getVerifyLink)
.subscribe(this.<String>testSubscriber()
.assertThat(location -> assertTrue(location.contains("/verify_user?code="))));
}

@Ignore("TODO: finish story https://www.pivotaltracker.com/projects/816799/stories/122457091 to grant scim.invite scope")
@Test
public void invite() {
this.uaaClient.users()
.invite(InviteUsersRequest.builder()
.email("test-email-address")
.redirectUri("test-redirect-uri")
.build())
.subscribe(this.testSubscriber());
.flatMapIterable(InviteUsersResponse::getFailedInvites)
.single()
.subscribe(this.<Invite>testSubscriber()
.assertThat(invite -> {
assertEquals("test-email-address", invite.getEmail());
assertEquals("provider.ambiguous", invite.getErrorCode());
}));
}

@Test
Expand All @@ -136,14 +156,12 @@ public void list() {
.list(ListUsersRequest.builder()
.filter(String.format("id eq \"%s\"", userId))
.build()))
.map(ListUsersResponse::getResources)
.flatMap(Flux::fromIterable)
.flatMapIterable(ListUsersResponse::getResources)
.map(User::getUserName)
.subscribe(this.testSubscriber()
.assertEquals(userName));
}

@Ignore("TODO: finish story https://www.pivotaltracker.com/projects/816799/stories/122457091 to grant scim.userids scope")
@Test
public void lookup() {
String userName = getUserName();
Expand All @@ -153,7 +171,10 @@ public void lookup() {
.lookup(LookupUserIdsRequest.builder()
.filter(String.format("id eq \"%s\"", userId))
.build()))
.subscribe(this.testSubscriber());
.flatMapIterable(LookupUserIdsResponse::getResources)
.map(UserId::getUserName)
.subscribe(this.testSubscriber()
.assertEquals(userName));
}

@Test
Expand Down Expand Up @@ -200,6 +221,13 @@ private static Mono<String> createUserId(UaaClient uaaClient, String userName) {
.map(CreateUserResponse::getId);
}

private static Mono<String> getUserIdByUsername(UaaClient uaaClient, String username) {
return requestLookupByUsername(uaaClient, username)
.flatMapIterable(LookupUserIdsResponse::getResources)
.map(UserId::getId)
.single();
}

private static Mono<CreateUserResponse> requestCreateUser(UaaClient uaaClient, String userName) {
return uaaClient.users()
.create(CreateUserRequest.builder()
Expand All @@ -212,6 +240,7 @@ private static Mono<CreateUserResponse> requestCreateUser(UaaClient uaaClient, S
.givenName("test-given-name")
.build())
.password("test-password")
.verified(false)
.userName(userName)
.build());
}
Expand All @@ -223,4 +252,11 @@ private static Mono<ListUsersResponse> requestListUsers(UaaClient uaaClient, Str
.build());
}

private static Mono<LookupUserIdsResponse> requestLookupByUsername(UaaClient uaaClient, String username) {
return uaaClient.users()
.lookup(LookupUserIdsRequest.builder()
.filter(String.format("userName eq \"%s\"", username))
.build());
}

}

0 comments on commit 23f8255

Please sign in to comment.