Query userGroupQuery = Query.Builder.create().addFieldClause(UserState.FIELD_NAME_EMAIL, email).build(); String userGroupLink = authsetupHelper.createUserGroup(this.host, email, userGroupQuery); UserState patchState = new UserState(); patchState.userGroupLinks = Collections.singleton(userGroupLink); this.host.sendAndWaitExpectSuccess(
UserState userState = new UserState(); userState.userGroupLinks = new HashSet<>(); userState.userGroupLinks.add("foo");
UserState userState = new UserState(); userState.userGroupLinks = new HashSet<>(); userState.userGroupLinks.add("foo");
String email = "foo@foo.com"; String fooUserLink = authHelperForFoo.createUserService(this.host, email); UserState patchState = new UserState(); patchState.userGroupLinks = new HashSet<String>(); patchState.userGroupLinks.add(UriUtils.buildUriPath(
String email = "foo@foo.com"; String fooUserLink = authHelperForFoo.createUserService(this.host, email); UserState patchState = new UserState(); patchState.userGroupLinks = new HashSet<String>(); patchState.userGroupLinks.add(UriUtils.buildUriPath(
Query userGroupQuery = Query.Builder.create().addFieldClause(UserState.FIELD_NAME_EMAIL, email).build(); String userGroupLink = authsetupHelper.createUserGroup(this.host, email, userGroupQuery); UserState patchState = new UserState(); patchState.userGroupLinks = Collections.singleton(userGroupLink); this.host.sendAndWaitExpectSuccess(
private void provisionUser(String user, String serviceLink) throws Throwable { UserState userState = new UserState(); userState.email = user; userState.documentSelfLink = user;
private void provisionUser(String user, String serviceLink) throws Throwable { UserState userState = new UserState(); userState.email = user; userState.documentSelfLink = user;
if (pair.right != null) { if (pair.right.getCause() instanceof ServiceNotFoundException) { UserState userState = new UserState(); userState.email = decode(user); userState.documentSelfLink = encodedUser;
UserState state = new UserState(); state.email = USER; state.documentSelfLink = USER;
UserState state = new UserState(); state.email = USER; state.documentSelfLink = USER;
UserState user = new UserState(); user.email = this.userEmail; if (this.userSelfLink != null) {
@Test public void testFactoryIdempotentPost() throws Throwable { String email = "jane@doe.com"; String servicePath = UriUtils.buildUriPath(UserService.FACTORY_LINK, email); UserState state = new UserState(); state.email = email; state.documentSelfLink = servicePath; UserState responseState = this.host.verifyPost(UserState.class, ServiceUriPaths.CORE_AUTHZ_USERS, state, Operation.STATUS_CODE_OK); assertEquals(state.email,responseState.email); long initialVersion = responseState.documentVersion; // sending same document, this post/put should not persist(increment) the document responseState = this.host.verifyPost(UserState.class, ServiceUriPaths.CORE_AUTHZ_USERS, state, Operation.STATUS_CODE_OK); assertEquals(state.email,responseState.email); UserState getState = this.sender.sendAndWait(Operation.createGet(this.host, servicePath), UserState.class); assertEquals("version should not increase", initialVersion, getState.documentVersion); state.email = "john@doe.com"; responseState = this.host.verifyPost(UserState.class, ServiceUriPaths.CORE_AUTHZ_USERS, state, Operation.STATUS_CODE_OK); assertEquals(state.email, responseState.email); assertTrue("version should increase", initialVersion < responseState.documentVersion); }
/** * Patch a user with the link of the userGroup that was just created */ private void updateUserGroupForUser() { if (!this.updateUserGroupForUser) { this.currentStep = UserCreationStep.MAKE_RESOURCE_GROUP; setupUser(); return; } UserState userState = new UserState(); userState.userGroupLinks = Collections.singleton(this.userGroupSelfLink); Operation patchUser = Operation.createPatch(AuthUtils .buildAuthProviderHostUri(this.host, this.userSelfLink)) .setBody(userState) .setReferer(this.referer) .setCompletion((op, ex) -> { if (ex != null) { this.failureMessage = String.format( "Could not patch user %s: %s", this.userSelfLink, ex); this.currentStep = UserCreationStep.FAILURE; setupUser(); return; } this.currentStep = UserCreationStep.MAKE_RESOURCE_GROUP; setupUser(); }); addReplicationFactor(patchUser); this.host.sendRequest(patchUser); }
@Test public void testFactoryIdempotentPost() throws Throwable { String email = "jane@doe.com"; String servicePath = UriUtils.buildUriPath(UserService.FACTORY_LINK, email); UserState state = new UserState(); state.email = email; state.documentSelfLink = servicePath; UserState responseState = this.host.verifyPost(UserState.class, ServiceUriPaths.CORE_AUTHZ_USERS, state, Operation.STATUS_CODE_OK); assertEquals(state.email,responseState.email); long initialVersion = responseState.documentVersion; // sending same document, this post/put should not persist(increment) the document responseState = this.host.verifyPost(UserState.class, ServiceUriPaths.CORE_AUTHZ_USERS, state, Operation.STATUS_CODE_OK); assertEquals(state.email,responseState.email); UserState getState = this.sender.sendAndWait(Operation.createGet(this.host, servicePath), UserState.class); assertEquals("version should not increase", initialVersion, getState.documentVersion); state.email = "john@doe.com"; responseState = this.host.verifyPost(UserState.class, ServiceUriPaths.CORE_AUTHZ_USERS, state, Operation.STATUS_CODE_OK); assertEquals(state.email, responseState.email); assertTrue("version should increase", initialVersion < responseState.documentVersion); }
UserState userState = new UserState(); userState.email = userName; userState.userGroupLinks = Collections.singleton(groupState.documentSelfLink);
@Test public void testInvalidUserAndResourceGroup() throws Throwable { OperationContext.setAuthorizationContext(this.host.getSystemAuthorizationContext()); AuthorizationHelper authsetupHelper = new AuthorizationHelper(this.host); String email = "foo@foo.com"; String userLink = authsetupHelper.createUserService(this.host, email); Query userGroupQuery = Query.Builder.create().addFieldClause(UserState.FIELD_NAME_EMAIL, email).build(); String userGroupLink = authsetupHelper.createUserGroup(this.host, email, userGroupQuery); authsetupHelper.createRole(this.host, userGroupLink, "foo", EnumSet.allOf(Action.class)); // Assume identity this.host.assumeIdentity(userLink); this.host.sendAndWaitExpectSuccess( Operation.createGet(UriUtils.buildUri(this.host, ExampleService.FACTORY_LINK))); // set an invalid userGroupLink for the user OperationContext.setAuthorizationContext(this.host.getSystemAuthorizationContext()); UserState patchUserState = new UserState(); patchUserState.userGroupLinks = Collections.singleton("foo"); this.host.sendAndWaitExpectSuccess( Operation.createPatch(UriUtils.buildUri(this.host, userLink)).setBody(patchUserState)); this.host.assumeIdentity(userLink); this.host.sendAndWaitExpectSuccess( Operation.createGet(UriUtils.buildUri(this.host, ExampleService.FACTORY_LINK))); }
@Test public void testPatch() throws Throwable { UserState state = new UserState(); state.email = "jane@doe.com"; state.documentSelfLink = UUID.randomUUID().toString(); state.userGroupLinks = new HashSet<String>(); state.userGroupLinks.add("link1"); state.userGroupLinks.add("link2"); UserState responseState = this.host.verifyPost(UserState.class, ServiceUriPaths.CORE_AUTHZ_USERS, state, Operation.STATUS_CODE_OK); assertEquals(state.email, responseState.email); assertEquals(state.userGroupLinks.size(), state.userGroupLinks.size()); state.email = "john@doe.com"; state.userGroupLinks.clear(); state.userGroupLinks.add("link2"); state.userGroupLinks.add("link3"); String path = UriUtils.buildUriPath(ServiceUriPaths.CORE_AUTHZ_USERS, state.documentSelfLink); Operation op = Operation.createPatch(this.host, path).setBody(state); UserState patchedState = this.sender.sendAndWait(op, UserState.class); assertEquals(state.email, patchedState.email); assertEquals(3, patchedState.userGroupLinks.size()); }
public static String createUserService(VerificationHost host, ServiceHost target, String email) throws Throwable { final String[] userUriPath = new String[1]; UserState userState = new UserState(); userState.documentSelfLink = email; userState.email = email; URI postUserUri = UriUtils.buildUri(target, ServiceUriPaths.CORE_AUTHZ_USERS); host.testStart(1); host.send(Operation .createPost(postUserUri) .setBody(userState) .setCompletion((o, e) -> { if (e != null) { host.failIteration(e); return; } UserState state = o.getBody(UserState.class); userUriPath[0] = state.documentSelfLink; host.completeIteration(); })); host.testWait(); return userUriPath[0]; }
public static String createUserService(VerificationHost host, ServiceHost target, String email) throws Throwable { final String[] userUriPath = new String[1]; UserState userState = new UserState(); userState.documentSelfLink = email; userState.email = email; URI postUserUri = UriUtils.buildUri(target, ServiceUriPaths.CORE_AUTHZ_USERS); host.testStart(1); host.send(Operation .createPost(postUserUri) .setBody(userState) .setCompletion((o, e) -> { if (e != null) { host.failIteration(e); return; } UserState state = o.getBody(UserState.class); userUriPath[0] = state.documentSelfLink; host.completeIteration(); })); host.testWait(); return userUriPath[0]; }