Return-Path: X-Original-To: apmail-usergrid-commits-archive@minotaur.apache.org Delivered-To: apmail-usergrid-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6A80210931 for ; Tue, 3 Mar 2015 20:00:41 +0000 (UTC) Received: (qmail 44730 invoked by uid 500); 3 Mar 2015 20:00:41 -0000 Delivered-To: apmail-usergrid-commits-archive@usergrid.apache.org Received: (qmail 44698 invoked by uid 500); 3 Mar 2015 20:00:41 -0000 Mailing-List: contact commits-help@usergrid.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@usergrid.incubator.apache.org Delivered-To: mailing list commits@usergrid.incubator.apache.org Received: (qmail 44689 invoked by uid 99); 3 Mar 2015 20:00:41 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Mar 2015 20:00:41 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F301BE03B9; Tue, 3 Mar 2015 20:00:40 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: grey@apache.org To: commits@usergrid.apache.org Date: Tue, 03 Mar 2015 20:00:40 -0000 Message-Id: <31613d817b9b4e14abf7adb913ddece6@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [01/37] incubator-usergrid git commit: Commented out failures to do tests one at a time. Repository: incubator-usergrid Updated Branches: refs/heads/USERGRID-422 efb6e72de -> 19e73d66d Commented out failures to do tests one at a time. Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/0f893ffc Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/0f893ffc Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/0f893ffc Branch: refs/heads/USERGRID-422 Commit: 0f893ffcbf7e6afaab87654cd794a9ba59893227 Parents: 231a449 Author: grey Authored: Thu Jan 8 15:46:41 2015 -0800 Committer: grey Committed: Thu Jan 8 15:46:41 2015 -0800 ---------------------------------------------------------------------- .../usergrid/rest/management/AdminUsersIT.java | 1362 +++++++++--------- 1 file changed, 680 insertions(+), 682 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0f893ffc/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java index 91ea270..271c013 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java @@ -31,6 +31,7 @@ import javax.mail.MessagingException; import javax.mail.internet.MimeMultipart; import javax.ws.rs.core.MediaType; +import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -46,10 +47,13 @@ import org.apache.usergrid.management.MockImapClient; import org.apache.usergrid.management.OrganizationInfo; import org.apache.usergrid.management.OrganizationOwnerInfo; import org.apache.usergrid.management.UserInfo; -import org.apache.usergrid.rest.AbstractRestIT; import org.apache.usergrid.rest.TestContextSetup; import org.apache.usergrid.rest.management.organizations.OrganizationsResource; import org.apache.usergrid.rest.test.resource.mgmt.Organization; +import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT; +import org.apache.usergrid.rest.test.resource2point0.RestClient; +import org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt.*; +import org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt.ManagementResource; import org.apache.usergrid.rest.test.security.TestAdminUser; import org.apache.usergrid.rest.test.security.TestUser; import org.apache.usergrid.security.AuthPrincipalInfo; @@ -80,19 +84,13 @@ import static org.junit.Assert.fail; */ public class AdminUsersIT extends AbstractRestIT { - //Used for all MUUserResourceITTests - private Logger LOG = LoggerFactory.getLogger( AdminUsersIT.class ); - - @Rule - public TestContextSetup context = new TestContextSetup( this ); - - public AdminUsersIT() throws Exception { + ManagementResource management; + @Before + public void setup() { + management= clientSetup.getRestClient().management(); } - - - /** * Test if we can reset our password as an admin */ @@ -125,677 +123,677 @@ public class AdminUsersIT extends AbstractRestIT { assertNull( getError( node ) ); } - - @Test - public void passwordMismatchErrorAdmin() { - String origPassword = "foo"; - String newPassword = "bar"; - - Map data = new HashMap(); - data.put( "newpassword", origPassword ); - - // now change the password, with an incorrect old password - - data.put( "oldpassword", origPassword ); - data.put( "newpassword", newPassword ); - - ClientResponse.Status responseStatus = null; - - try { - resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data ); - } - catch ( UniformInterfaceException uie ) { - responseStatus = uie.getResponse().getClientResponseStatus(); - } - - assertNotNull( responseStatus ); - - assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); - } - - - @Test - public void setAdminPasswordAsSysAdmin() throws IOException { - - String superToken = superAdminToken(); - - String newPassword = "foo"; - - Map data = new HashMap(); - data.put( "newpassword", newPassword ); - - // change the password as admin. The old password isn't required - JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) - .post( String.class, data )); - - assertNull( getError( node ) ); - - refreshIndex("test-organization", "test-app"); - - // log in with the new password - String token = mgmtToken( "test", newPassword ); - - assertNotNull( token ); - - data.put( "newpassword", "test" ); - - // now change the password back - node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) - .post( String.class, data )); - - assertNull( getError( node ) ); - } - - @Test - public void mgmtUserFeed() throws Exception { - JsonNode userdata = mapper.readTree( resource().path( "/management/users/test@usergrid.com/feed" ) - .queryParam( "access_token", adminAccessToken ) - .accept( MediaType.APPLICATION_JSON ).get( String.class )); - assertTrue( StringUtils.contains( this.getEntity( userdata, 0 ).get( "title" ).asText(), - "" ) ); - } - - //everything below is MUUserResourceIT - - @Test - public void testCaseSensitivityAdminUser() throws Exception { - - LOG.info( "Starting testCaseSensitivityAdminUser()" ); - - UserInfo mixcaseUser = setup.getMgmtSvc() - .createAdminUser( "AKarasulu", "Alex Karasulu", "AKarasulu@Apache.org", "test", true, false ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - AuthPrincipalInfo adminPrincipal = new AuthPrincipalInfo( - AuthPrincipalType.ADMIN_USER, mixcaseUser.getUuid(), UUIDUtils.newTimeUUID() ); - OrganizationInfo organizationInfo = - setup.getMgmtSvc().createOrganization( "MixedCaseOrg", mixcaseUser, true ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - String tokenStr = mgmtToken( "akarasulu@apache.org", "test" ); - - // Should succeed even when we use all lowercase - JsonNode node = mapper.readTree( resource().path( "/management/users/akarasulu@apache.org" ) - .queryParam( "access_token", tokenStr ) - .accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ) - .get( String.class )); - logNode( node ); - } - - - @Test - public void testUnconfirmedAdminLogin() throws Exception { - - // Setup properties to require confirmation of users - // ------------------------------------------- - - Map originalProperties = getRemoteTestProperties(); - - try { - setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" ); - setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" ); - setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" ); - setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" ); - setTestProperty( PROPERTIES_NOTIFY_ADMIN_OF_ACTIVATION, "true" ); - - assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() ); - assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() ); - - // Setup org/app/user variables and create them - // ------------------------------------------- - String orgName = this.getClass().getName(); - String appName = "testUnconfirmedAdminLogin"; - String userName = "TestUser"; - String email = "test-user-46@mockserver.com"; - String passwd = "testpassword"; - OrganizationOwnerInfo orgOwner; - - orgOwner = setup.getMgmtSvc().createOwnerAndOrganization( - orgName, userName, appName, email, passwd, false, false ); - assertNotNull( orgOwner ); - String returnedUsername = orgOwner.getOwner().getUsername(); - assertEquals( userName, returnedUsername ); - - UserInfo adminUserInfo = setup.getMgmtSvc().getAdminUserByUsername( userName ); - assertNotNull( adminUserInfo ); - assertFalse( "adminUser should not be activated yet", adminUserInfo.isActivated() ); - assertFalse( "adminUser should not be confirmed yet", adminUserInfo.isConfirmed() ); - - // Attempt to authenticate but this should fail - // ------------------------------------------- - JsonNode node; - try { - node = mapper.readTree( resource().path( "/management/token" ) - .queryParam( "grant_type", "password" ) - .queryParam( "username", userName ) - .queryParam( "password", passwd ) - .accept( MediaType.APPLICATION_JSON ).get( String.class )); - - fail( "Unconfirmed users should not be authorized to authenticate." ); - } - catch ( UniformInterfaceException e ) { - node = mapper.readTree( e.getResponse().getEntity( String.class )); - assertEquals( "invalid_grant", node.get( "error" ).textValue() ); - assertEquals( "User must be confirmed to authenticate", - node.get( "error_description" ).textValue() ); - LOG.info( "Unconfirmed user was not authorized to authenticate!" ); - } - - // Confirm the getting account confirmation email for unconfirmed user - // ------------------------------------------- - List inbox = Mailbox.get( email ); - assertFalse( inbox.isEmpty() ); - - MockImapClient client = new MockImapClient( "mockserver.com", "test-user-46", "somepassword" ); - client.processMail(); - - Message confirmation = inbox.get( 0 ); - assertEquals( "User Account Confirmation: " + email, confirmation.getSubject() ); - - // Extract the token to confirm the user - // ------------------------------------------- - String token = getTokenFromMessage( confirmation ); - LOG.info( token ); - - ActivationState state = setup.getMgmtSvc().handleConfirmationTokenForAdminUser( - orgOwner.getOwner().getUuid(), token ); - assertEquals( ActivationState.ACTIVATED, state ); - - Message activation = inbox.get( 1 ); - assertEquals( "User Account Activated", activation.getSubject() ); - - client = new MockImapClient( "mockserver.com", "test-user-46", "somepassword" ); - client.processMail(); - - refreshIndex(orgName, appName); - - // Attempt to authenticate again but this time should pass - // ------------------------------------------- - - node = mapper.readTree( resource().path( "/management/token" ) - .queryParam( "grant_type", "password" ) - .queryParam( "username", userName ) - .queryParam( "password", passwd ) - .accept( MediaType.APPLICATION_JSON ).get( String.class )); - - assertNotNull( node ); - LOG.info( "Authentication succeeded after confirmation: {}.", node.toString() ); - } - finally { - setTestProperties( originalProperties ); - } - } - - - @Test - public void testSystemAdminNeedsNoConfirmation() throws Exception { - - Map originalProperties = getRemoteTestProperties(); - - try { - // require comfirmation of new admin users - setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" ); - setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" ); - setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" ); - - assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() ); - assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() ); - - String sysadminUsername = ( String ) setup.getMgmtSvc().getProperties() - .get( AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_EMAIL ); - - String sysadminPassword = ( String ) setup.getMgmtSvc().getProperties() - .get( AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_PASSWORD ); - - // sysadmin login should suceed despite confirmation setting - JsonNode node; - try { - node = mapper.readTree( resource().path( "/management/token" ).queryParam( "grant_type", "password" ) - .queryParam( "username", sysadminUsername ).queryParam( "password", sysadminPassword ) - .accept( MediaType.APPLICATION_JSON ).get( String.class )); - } - catch ( UniformInterfaceException e ) { - fail( "Sysadmin should need no confirmation" ); - } - } - finally { - setTestProperties( originalProperties ); - } - } - - - @Test - public void testTestUserNeedsNoConfirmation() throws Exception { - - Map originalProperties = getRemoteTestProperties(); - - try { - // require comfirmation of new admin users - setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" ); - setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" ); - setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" ); - - assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() ); - assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() ); - - String testUserUsername = ( String ) setup.getMgmtSvc().getProperties() - .get( AccountCreationProps - .PROPERTIES_TEST_ACCOUNT_ADMIN_USER_EMAIL ); - - String testUserPassword = ( String ) setup.getMgmtSvc().getProperties() - .get( AccountCreationProps - .PROPERTIES_TEST_ACCOUNT_ADMIN_USER_PASSWORD ); - - // test user login should suceed despite confirmation setting - JsonNode node; - try { - node = mapper.readTree( resource().path( "/management/token" ).queryParam( "grant_type", "password" ) - .queryParam( "username", testUserUsername ).queryParam( "password", testUserPassword ) - .accept( MediaType.APPLICATION_JSON ).get( String.class )); - } - catch ( UniformInterfaceException e ) { - fail( "Test User should need no confirmation" ); - } - } - finally { - setTestProperties( originalProperties ); - } - } - - - private String getTokenFromMessage( Message msg ) throws IOException, MessagingException { - String body = ( ( MimeMultipart ) msg.getContent() ).getBodyPart( 0 ).getContent().toString(); - return StringUtils.substringAfterLast( body, "token=" ); - } - - - @Test - public void updateManagementUser() throws Exception { - Map payload = - hashMap( "email", "uort-user-1@apigee.com" ).map( "username", "uort-user-1" ).map( "name", "Test User" ) - .map( "password", "password" ).map( "organization", "uort-org" ).map( "company", "Apigee" ); - - JsonNode node = mapper.readTree( resource().path( "/management/organizations" ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); - logNode( node ); - String userId = node.get( "data" ).get( "owner" ).get( "uuid" ).asText(); - - assertEquals( "Apigee", node.get( "data" ).get( "owner" ).get( "properties" ).get( "company" ).asText() ); - - String token = mgmtToken( "uort-user-1@apigee.com", "password" ); - - node = mapper.readTree( resource().path( String.format( "/management/users/%s", userId ) ).queryParam( "access_token", token ) - .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class )); - - logNode( node ); - - payload = hashMap( "company", "Usergrid" ); - LOG.info( "sending PUT for company update" ); - node = mapper.readTree( resource().path( String.format( "/management/users/%s", userId ) ).queryParam( "access_token", token ) - .type( MediaType.APPLICATION_JSON_TYPE ).put( String.class, payload )); - assertNotNull( node ); - node = mapper.readTree( resource().path( String.format( "/management/users/%s", userId ) ).queryParam( "access_token", token ) - .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class )); - assertEquals( "Usergrid", node.get( "data" ).get( "properties" ).get( "company" ).asText() ); - - - logNode( node ); - } - - - @Test - public void getUser() throws Exception { - - // set an organization property - HashMap payload = new HashMap(); - Map properties = new HashMap(); - properties.put( "securityLevel", 5 ); - payload.put( OrganizationsResource.ORGANIZATION_PROPERTIES, properties ); - - - /** - * Get the original org admin before we overwrite the property as a super user - */ - final TestUser orgAdmin = context.getActiveUser(); - final String orgName = context.getOrgName(); - final String superAdminToken = superAdminToken(); - - TestAdminUser superAdmin = new TestAdminUser( "super", "super", "superuser@usergrid.com" ); - superAdmin.setToken( superAdminToken ); - - Organization org = context.withUser( superAdmin ).management().orgs().organization( orgName ); - - org.put( payload ); - - - //now get the org - JsonNode node = context.withUser( orgAdmin ).management().users().user( orgAdmin.getUser() ).get(); - - logNode( node ); - - JsonNode applications = node.findValue( "applications" ); - assertNotNull( applications ); - JsonNode users = node.findValue( "users" ); - assertNotNull( users ); - - JsonNode securityLevel = node.findValue( "securityLevel" ); - assertNotNull( securityLevel ); - assertEquals( 5L, securityLevel.asLong() ); - } - - - @Test - public void getUserShallow() throws Exception { - - - // set an organization property - HashMap payload = new HashMap(); - Map properties = new HashMap(); - properties.put( "securityLevel", 5 ); - payload.put( OrganizationsResource.ORGANIZATION_PROPERTIES, properties ); - - - /** - * Get the original org admin before we overwrite the property as a super user - */ - final TestUser orgAdmin = context.getActiveUser(); - final String orgName = context.getOrgName(); - final String superAdminToken = superAdminToken(); - - TestAdminUser superAdmin = new TestAdminUser( "super", "super", "superuser@usergrid.com" ); - superAdmin.setToken( superAdminToken ); - - Organization org = context.withUser( superAdmin ).management().orgs().organization( orgName ); - - org.put( payload ); - - - //now get the org - JsonNode node = context.withUser( orgAdmin ).management().users().user( orgAdmin.getUser() ).withParam( - "shallow", "true" ).get(); - - logNode( node ); - - JsonNode applications = node.findValue( "applications" ); - assertNull( applications ); - JsonNode users = node.findValue( "users" ); - assertNull( users ); - - JsonNode securityLevel = node.findValue( "securityLevel" ); - assertNotNull( securityLevel ); - assertEquals( 5L, securityLevel.asLong() ); - } - - - @Test - public void reactivateMultipleSend() throws Exception { - - JsonNode node = mapper.readTree( resource().path( "/management/organizations" ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, buildOrgUserPayload( "reactivate" ) )); - - logNode( node ); - String email = node.get( "data" ).get( "owner" ).get( "email" ).asText(); - String uuid = node.get( "data" ).get( "owner" ).get( "uuid" ).asText(); - assertNotNull( email ); - assertEquals( "MUUserResourceIT-reactivate@apigee.com", email ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - // reactivate should send activation email - - node = mapper.readTree( resource().path( String.format( "/management/users/%s/reactivate", uuid ) ) - .queryParam( "access_token", adminAccessToken ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class )); - - refreshIndex(context.getOrgName(), context.getAppName()); - - List inbox = org.jvnet.mock_javamail.Mailbox.get( email ); - - assertFalse( inbox.isEmpty() ); - logNode( node ); - } - - - private Map buildOrgUserPayload( String caller ) { - String className = this.getClass().getSimpleName(); - Map payload = hashMap( "email", String.format( "%s-%s@apigee.com", className, caller ) ) - .map( "username", String.format( "%s-%s-user", className, caller ) ) - .map( "name", String.format( "%s %s", className, caller ) ).map( "password", "password" ) - .map( "organization", String.format( "%s-%s-org", className, caller ) ); - return payload; - } - - - @Test - public void checkPasswordReset() throws Exception { - - refreshIndex(context.getOrgName(), context.getAppName()); - - TestUser user = context.getActiveUser(); - - String email = user.getEmail(); - UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( email ); - String resetToken = setup.getMgmtSvc().getPasswordResetTokenForAdminUser( userInfo.getUuid(), 15000 ); - - assertTrue( setup.getMgmtSvc().checkPasswordResetTokenForAdminUser( userInfo.getUuid(), resetToken ) ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - Form formData = new Form(); - formData.add( "token", resetToken ); - formData.add( "password1", "sesame" ); - formData.add( "password2", "sesame" ); - - String html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" ) - .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData ); - - assertTrue( html.contains( "password set" ) ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - assertFalse( setup.getMgmtSvc().checkPasswordResetTokenForAdminUser( userInfo.getUuid(), resetToken ) ); - - html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" ) - .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData ); - - assertTrue( html.contains( "invalid token" ) ); - } - - - @Test - @Ignore( "causes problems in build" ) - public void passwordResetIncorrectUserName() throws Exception { - - String email = "test2@usergrid.com"; - setup.getMgmtSvc().createAdminUser( "test2", "test2", "test2@usergrid.com", "sesa2me", false, false ); - UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( email ); - String resetToken = setup.getMgmtSvc().getPasswordResetTokenForAdminUser( userInfo.getUuid(), 15000 ); - - assertTrue( setup.getMgmtSvc().checkPasswordResetTokenForAdminUser( userInfo.getUuid(), resetToken ) ); - - Form formData = new Form(); - formData.add( "token", resetToken ); - formData.add( "password1", "sesa2me" ); - formData.add( "password2", "sesa2me" ); - - String html = resource().path( "/management/users/" + "noodle" + userInfo.getUsername() + "/resetpw" ) - .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData ); - - assertTrue( html.contains( "Incorrect username entered" ) ); - - html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" ) - .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData ); - - assertTrue( html.contains( "password set" ) ); - } - - - @Test - public void checkPasswordHistoryConflict() throws Exception { - - String[] passwords = new String[] { "password1", "password2", "password3", "password4" }; - - UserInfo user = - setup.getMgmtSvc().createAdminUser( "edanuff", "Ed Anuff", "ed@anuff.com", passwords[0], true, false ); - assertNotNull( user ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - OrganizationInfo organization = setup.getMgmtSvc().createOrganization( "ed-organization", user, true ); - assertNotNull( organization ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - // set history to 1 - Map props = new HashMap(); - props.put( OrganizationInfo.PASSWORD_HISTORY_SIZE_KEY, 1 ); - organization.setProperties( props ); - setup.getMgmtSvc().updateOrganization( organization ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( "ed@anuff.com" ); - - Map payload = hashMap( "oldpassword", passwords[0] ).map( "newpassword", passwords[0] ); // fail - - try { - JsonNode node = mapper.readTree( resource().path( "/management/users/edanuff/password" ) - .accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); - fail( "should fail with conflict" ); - } - catch ( UniformInterfaceException e ) { - assertEquals( 409, e.getResponse().getStatus() ); - } - - payload.put( "newpassword", passwords[1] ); // ok - JsonNode node = mapper.readTree( resource().path( "/management/users/edanuff/password" ) - .accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); - payload.put( "oldpassword", passwords[1] ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - payload.put( "newpassword", passwords[0] ); // fail - try { - node = mapper.readTree( resource().path( "/management/users/edanuff/password" ) - .accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); - fail( "should fail with conflict" ); - } - catch ( UniformInterfaceException e ) { - assertEquals( 409, e.getResponse().getStatus() ); - } - } - - - @Test - public void checkPasswordChangeTime() throws Exception { - - final TestUser user = context.getActiveUser(); - String email = user.getEmail(); - UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( email ); - String resetToken = setup.getMgmtSvc().getPasswordResetTokenForAdminUser( userInfo.getUuid(), 15000 ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - Form formData = new Form(); - formData.add( "token", resetToken ); - formData.add( "password1", "sesame" ); - formData.add( "password2", "sesame" ); - - String html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" ) - .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData ); - assertTrue( html.contains( "password set" ) ); - - refreshIndex(context.getOrgName(), context.getAppName()); - - JsonNode node = mapper.readTree( resource().path( "/management/token" ) - .queryParam( "grant_type", "password" ) - .queryParam( "username", email ).queryParam( "password", "sesame" ) - .accept( MediaType.APPLICATION_JSON ) - .get( String.class )); - - Long changeTime = node.get( "passwordChanged" ).longValue(); - assertTrue( System.currentTimeMillis() - changeTime < 2000 ); - - Map payload = hashMap( "oldpassword", "sesame" ).map( "newpassword", "test" ); - node = mapper.readTree( resource().path( "/management/users/" + userInfo.getUsername() + "/password" ) - .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) - .post( String.class, payload )); - - refreshIndex(context.getOrgName(), context.getAppName()); - - node = mapper.readTree( resource().path( "/management/token" ) - .queryParam( "grant_type", "password" ) - .queryParam( "username", email ) - .queryParam( "password", "test" ) - .accept( MediaType.APPLICATION_JSON ) - .get( String.class )); - - Long changeTime2 = node.get( "passwordChanged" ).longValue(); - assertTrue( changeTime < changeTime2 ); - assertTrue( System.currentTimeMillis() - changeTime2 < 2000 ); - - node = mapper.readTree( resource().path( "/management/me" ).queryParam( "grant_type", "password" ) - .queryParam( "username", email ).queryParam( "password", "test" ).accept( MediaType.APPLICATION_JSON ) - .get( String.class )); - - Long changeTime3 = node.get( "passwordChanged" ).longValue(); - assertEquals( changeTime2, changeTime3 ); - } - - - /** USERGRID-1960 */ - @Test - @Ignore( "Depends on other tests" ) - public void listOrgUsersByName() { - JsonNode response = context.management().orgs().organization( context.getOrgName() ).users().get(); - - //get the response and verify our user is there - JsonNode adminNode = response.get( "data" ).get( 0 ); - assertEquals( context.getActiveUser().getEmail(), adminNode.get( "email" ).asText() ); - assertEquals( context.getActiveUser().getUser(), adminNode.get( "username" ).asText() ); - } - - @Test - public void createOrgFromUserConnectionFail() throws Exception { - - - Map payload = hashMap( "email", "orgfromuserconn@apigee.com" ).map( "password", "password" ) - .map( "organization", "orgfromuserconn" ); - - JsonNode node = mapper.readTree( resource().path( "/management/organizations" ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); - - String userId = node.get( "data" ).get( "owner" ).get( "uuid" ).asText(); - - assertNotNull( node ); - - String token = mgmtToken( "orgfromuserconn@apigee.com", "password" ); - - node = mapper.readTree( resource().path( String.format( "/management/users/%s/", userId ) ).queryParam( "access_token", token ) - .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class )); - - logNode( node ); - - payload = hashMap( "organization", "Orgfromuserconn" ); - - // try to create the same org again off the connection - try { - node = mapper.readTree( resource().path( String.format( "/management/users/%s/organizations", userId ) ) - .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) - .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); - fail( "Should have thrown unique exception on org name" ); - } - catch ( Exception ex ) { - } +// +// @Test +// public void passwordMismatchErrorAdmin() { +// String origPassword = "foo"; +// String newPassword = "bar"; +// +// Map data = new HashMap(); +// data.put( "newpassword", origPassword ); +// +// // now change the password, with an incorrect old password +// +// data.put( "oldpassword", origPassword ); +// data.put( "newpassword", newPassword ); +// +// ClientResponse.Status responseStatus = null; +// +// try { +// resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data ); +// } +// catch ( UniformInterfaceException uie ) { +// responseStatus = uie.getResponse().getClientResponseStatus(); +// } +// +// assertNotNull( responseStatus ); +// +// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus ); +// } +// +// +// @Test +// public void setAdminPasswordAsSysAdmin() throws IOException { +// +// String superToken = superAdminToken(); +// +// String newPassword = "foo"; +// +// Map data = new HashMap(); +// data.put( "newpassword", newPassword ); +// +// // change the password as admin. The old password isn't required +// JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken ) +// .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) +// .post( String.class, data )); +// +// assertNull( getError( node ) ); +// +// refreshIndex("test-organization", "test-app"); +// +// // log in with the new password +// String token = mgmtToken( "test", newPassword ); +// +// assertNotNull( token ); +// +// data.put( "newpassword", "test" ); +// +// // now change the password back +// node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", superToken ) +// .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) +// .post( String.class, data )); +// +// assertNull( getError( node ) ); +// } +// +// @Test +// public void mgmtUserFeed() throws Exception { +// JsonNode userdata = mapper.readTree( resource().path( "/management/users/test@usergrid.com/feed" ) +// .queryParam( "access_token", adminAccessToken ) +// .accept( MediaType.APPLICATION_JSON ).get( String.class )); +// assertTrue( StringUtils.contains( this.getEntity( userdata, 0 ).get( "title" ).asText(), +// "" ) ); +// } +// +// //everything below is MUUserResourceIT +// +// @Test +// public void testCaseSensitivityAdminUser() throws Exception { +// +// LOG.info( "Starting testCaseSensitivityAdminUser()" ); +// +// UserInfo mixcaseUser = setup.getMgmtSvc() +// .createAdminUser( "AKarasulu", "Alex Karasulu", "AKarasulu@Apache.org", "test", true, false ); +// +// refreshIndex(context.getOrgName(), context.getAppName()); +// +// AuthPrincipalInfo adminPrincipal = new AuthPrincipalInfo( +// AuthPrincipalType.ADMIN_USER, mixcaseUser.getUuid(), UUIDUtils.newTimeUUID() ); +// OrganizationInfo organizationInfo = +// setup.getMgmtSvc().createOrganization( "MixedCaseOrg", mixcaseUser, true ); +// +// refreshIndex(context.getOrgName(), context.getAppName()); +// +// String tokenStr = mgmtToken( "akarasulu@apache.org", "test" ); +// +// // Should succeed even when we use all lowercase +// JsonNode node = mapper.readTree( resource().path( "/management/users/akarasulu@apache.org" ) +// .queryParam( "access_token", tokenStr ) +// .accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ) +// .get( String.class )); +// logNode( node ); +// } +// +// +// @Test +// public void testUnconfirmedAdminLogin() throws Exception { +// +// // Setup properties to require confirmation of users +// // ------------------------------------------- +// +// Map originalProperties = getRemoteTestProperties(); +// +// try { +// setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" ); +// setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" ); +// setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" ); +// setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" ); +// setTestProperty( PROPERTIES_NOTIFY_ADMIN_OF_ACTIVATION, "true" ); +// +// assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() ); +// assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() ); +// +// // Setup org/app/user variables and create them +// // ------------------------------------------- +// String orgName = this.getClass().getName(); +// String appName = "testUnconfirmedAdminLogin"; +// String userName = "TestUser"; +// String email = "test-user-46@mockserver.com"; +// String passwd = "testpassword"; +// OrganizationOwnerInfo orgOwner; +// +// orgOwner = setup.getMgmtSvc().createOwnerAndOrganization( +// orgName, userName, appName, email, passwd, false, false ); +// assertNotNull( orgOwner ); +// String returnedUsername = orgOwner.getOwner().getUsername(); +// assertEquals( userName, returnedUsername ); +// +// UserInfo adminUserInfo = setup.getMgmtSvc().getAdminUserByUsername( userName ); +// assertNotNull( adminUserInfo ); +// assertFalse( "adminUser should not be activated yet", adminUserInfo.isActivated() ); +// assertFalse( "adminUser should not be confirmed yet", adminUserInfo.isConfirmed() ); +// +// // Attempt to authenticate but this should fail +// // ------------------------------------------- +// JsonNode node; +// try { +// node = mapper.readTree( resource().path( "/management/token" ) +// .queryParam( "grant_type", "password" ) +// .queryParam( "username", userName ) +// .queryParam( "password", passwd ) +// .accept( MediaType.APPLICATION_JSON ).get( String.class )); +// +// fail( "Unconfirmed users should not be authorized to authenticate." ); +// } +// catch ( UniformInterfaceException e ) { +// node = mapper.readTree( e.getResponse().getEntity( String.class )); +// assertEquals( "invalid_grant", node.get( "error" ).textValue() ); +// assertEquals( "User must be confirmed to authenticate", +// node.get( "error_description" ).textValue() ); +// LOG.info( "Unconfirmed user was not authorized to authenticate!" ); +// } +// +// // Confirm the getting account confirmation email for unconfirmed user +// // ------------------------------------------- +// List inbox = Mailbox.get( email ); +// assertFalse( inbox.isEmpty() ); +// +// MockImapClient client = new MockImapClient( "mockserver.com", "test-user-46", "somepassword" ); +// client.processMail(); +// +// Message confirmation = inbox.get( 0 ); +// assertEquals( "User Account Confirmation: " + email, confirmation.getSubject() ); +// +// // Extract the token to confirm the user +// // ------------------------------------------- +// String token = getTokenFromMessage( confirmation ); +// LOG.info( token ); +// +// ActivationState state = setup.getMgmtSvc().handleConfirmationTokenForAdminUser( +// orgOwner.getOwner().getUuid(), token ); +// assertEquals( ActivationState.ACTIVATED, state ); +// +// Message activation = inbox.get( 1 ); +// assertEquals( "User Account Activated", activation.getSubject() ); +// +// client = new MockImapClient( "mockserver.com", "test-user-46", "somepassword" ); +// client.processMail(); +// +// refreshIndex(orgName, appName); +// +// // Attempt to authenticate again but this time should pass +// // ------------------------------------------- +// +// node = mapper.readTree( resource().path( "/management/token" ) +// .queryParam( "grant_type", "password" ) +// .queryParam( "username", userName ) +// .queryParam( "password", passwd ) +// .accept( MediaType.APPLICATION_JSON ).get( String.class )); +// +// assertNotNull( node ); +// LOG.info( "Authentication succeeded after confirmation: {}.", node.toString() ); +// } +// finally { +// setTestProperties( originalProperties ); +// } +// } +// +// +// @Test +// public void testSystemAdminNeedsNoConfirmation() throws Exception { +// +// Map originalProperties = getRemoteTestProperties(); +// +// try { +// // require comfirmation of new admin users +// setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" ); +// setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" ); +// setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" ); +// +// assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() ); +// assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() ); +// +// String sysadminUsername = ( String ) setup.getMgmtSvc().getProperties() +// .get( AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_EMAIL ); +// +// String sysadminPassword = ( String ) setup.getMgmtSvc().getProperties() +// .get( AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_PASSWORD ); +// +// // sysadmin login should suceed despite confirmation setting +// JsonNode node; +// try { +// node = mapper.readTree( resource().path( "/management/token" ).queryParam( "grant_type", "password" ) +// .queryParam( "username", sysadminUsername ).queryParam( "password", sysadminPassword ) +// .accept( MediaType.APPLICATION_JSON ).get( String.class )); +// } +// catch ( UniformInterfaceException e ) { +// fail( "Sysadmin should need no confirmation" ); +// } +// } +// finally { +// setTestProperties( originalProperties ); +// } +// } +// +// +// @Test +// public void testTestUserNeedsNoConfirmation() throws Exception { +// +// Map originalProperties = getRemoteTestProperties(); +// +// try { +// // require comfirmation of new admin users +// setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" ); +// setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" ); +// setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" ); +// +// assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() ); +// assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() ); +// +// String testUserUsername = ( String ) setup.getMgmtSvc().getProperties() +// .get( AccountCreationProps +// .PROPERTIES_TEST_ACCOUNT_ADMIN_USER_EMAIL ); +// +// String testUserPassword = ( String ) setup.getMgmtSvc().getProperties() +// .get( AccountCreationProps +// .PROPERTIES_TEST_ACCOUNT_ADMIN_USER_PASSWORD ); +// +// // test user login should suceed despite confirmation setting +// JsonNode node; +// try { +// node = mapper.readTree( resource().path( "/management/token" ).queryParam( "grant_type", "password" ) +// .queryParam( "username", testUserUsername ).queryParam( "password", testUserPassword ) +// .accept( MediaType.APPLICATION_JSON ).get( String.class )); +// } +// catch ( UniformInterfaceException e ) { +// fail( "Test User should need no confirmation" ); +// } +// } +// finally { +// setTestProperties( originalProperties ); +// } +// } +// +// +// private String getTokenFromMessage( Message msg ) throws IOException, MessagingException { +// String body = ( ( MimeMultipart ) msg.getContent() ).getBodyPart( 0 ).getContent().toString(); +// return StringUtils.substringAfterLast( body, "token=" ); +// } +// +// +// @Test +// public void updateManagementUser() throws Exception { +// Map payload = +// hashMap( "email", "uort-user-1@apigee.com" ).map( "username", "uort-user-1" ).map( "name", "Test User" ) +// .map( "password", "password" ).map( "organization", "uort-org" ).map( "company", "Apigee" ); +// +// JsonNode node = mapper.readTree( resource().path( "/management/organizations" ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); +// logNode( node ); +// String userId = node.get( "data" ).get( "owner" ).get( "uuid" ).asText(); +// +// assertEquals( "Apigee", node.get( "data" ).get( "owner" ).get( "properties" ).get( "company" ).asText() ); +// +// String token = mgmtToken( "uort-user-1@apigee.com", "password" ); +// +// node = mapper.readTree( resource().path( String.format( "/management/users/%s", userId ) ).queryParam( "access_token", token ) +// .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class )); +// +// logNode( node ); +// +// payload = hashMap( "company", "Usergrid" ); +// LOG.info( "sending PUT for company update" ); +// node = mapper.readTree( resource().path( String.format( "/management/users/%s", userId ) ).queryParam( "access_token", token ) +// .type( MediaType.APPLICATION_JSON_TYPE ).put( String.class, payload )); +// assertNotNull( node ); +// node = mapper.readTree( resource().path( String.format( "/management/users/%s", userId ) ).queryParam( "access_token", token ) +// .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class )); +// assertEquals( "Usergrid", node.get( "data" ).get( "properties" ).get( "company" ).asText() ); +// +// +// logNode( node ); +// } +// +// +// @Test +// public void getUser() throws Exception { +// +// // set an organization property +// HashMap payload = new HashMap(); +// Map properties = new HashMap(); +// properties.put( "securityLevel", 5 ); +// payload.put( OrganizationsResource.ORGANIZATION_PROPERTIES, properties ); +// +// +// /** +// * Get the original org admin before we overwrite the property as a super user +// */ +// final TestUser orgAdmin = context.getActiveUser(); +// final String orgName = context.getOrgName(); +// final String superAdminToken = superAdminToken(); +// +// TestAdminUser superAdmin = new TestAdminUser( "super", "super", "superuser@usergrid.com" ); +// superAdmin.setToken( superAdminToken ); +// +// Organization org = context.withUser( superAdmin ).management().orgs().organization( orgName ); +// +// org.put( payload ); +// +// +// //now get the org +// JsonNode node = context.withUser( orgAdmin ).management().users().user( orgAdmin.getUser() ).get(); +// +// logNode( node ); +// +// JsonNode applications = node.findValue( "applications" ); +// assertNotNull( applications ); +// JsonNode users = node.findValue( "users" ); +// assertNotNull( users ); +// +// JsonNode securityLevel = node.findValue( "securityLevel" ); +// assertNotNull( securityLevel ); +// assertEquals( 5L, securityLevel.asLong() ); +// } +// +// +// @Test +// public void getUserShallow() throws Exception { +// +// +// // set an organization property +// HashMap payload = new HashMap(); +// Map properties = new HashMap(); +// properties.put( "securityLevel", 5 ); +// payload.put( OrganizationsResource.ORGANIZATION_PROPERTIES, properties ); +// +// +// /** +// * Get the original org admin before we overwrite the property as a super user +// */ +// final TestUser orgAdmin = context.getActiveUser(); +// final String orgName = context.getOrgName(); +// final String superAdminToken = superAdminToken(); +// +// TestAdminUser superAdmin = new TestAdminUser( "super", "super", "superuser@usergrid.com" ); +// superAdmin.setToken( superAdminToken ); +// +// Organization org = context.withUser( superAdmin ).management().orgs().organization( orgName ); +// +// org.put( payload ); +// +// +// //now get the org +// JsonNode node = context.withUser( orgAdmin ).management().users().user( orgAdmin.getUser() ).withParam( +// "shallow", "true" ).get(); +// +// logNode( node ); +// +// JsonNode applications = node.findValue( "applications" ); +// assertNull( applications ); +// JsonNode users = node.findValue( "users" ); +// assertNull( users ); +// +// JsonNode securityLevel = node.findValue( "securityLevel" ); +// assertNotNull( securityLevel ); +// assertEquals( 5L, securityLevel.asLong() ); +// } +// +// +// @Test +// public void reactivateMultipleSend() throws Exception { +// +// JsonNode node = mapper.readTree( resource().path( "/management/organizations" ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, buildOrgUserPayload( "reactivate" ) )); +// +// logNode( node ); +// String email = node.get( "data" ).get( "owner" ).get( "email" ).asText(); +// String uuid = node.get( "data" ).get( "owner" ).get( "uuid" ).asText(); +// assertNotNull( email ); +// assertEquals( "MUUserResourceIT-reactivate@apigee.com", email ); +// +// refreshIndex(context.getOrgName(), context.getAppName()); +// +// // reactivate should send activation email +// +// node = mapper.readTree( resource().path( String.format( "/management/users/%s/reactivate", uuid ) ) +// .queryParam( "access_token", adminAccessToken ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class )); +// +// refreshIndex(context.getOrgName(), context.getAppName()); +// +// List inbox = org.jvnet.mock_javamail.Mailbox.get( email ); +// +// assertFalse( inbox.isEmpty() ); +// logNode( node ); +// } +// +// +// private Map buildOrgUserPayload( String caller ) { +// String className = this.getClass().getSimpleName(); +// Map payload = hashMap( "email", String.format( "%s-%s@apigee.com", className, caller ) ) +// .map( "username", String.format( "%s-%s-user", className, caller ) ) +// .map( "name", String.format( "%s %s", className, caller ) ).map( "password", "password" ) +// .map( "organization", String.format( "%s-%s-org", className, caller ) ); +// return payload; +// } +// +// +// @Test +// public void checkPasswordReset() throws Exception { +// +// refreshIndex(context.getOrgName(), context.getAppName()); +// +// TestUser user = context.getActiveUser(); +// +// String email = user.getEmail(); +// UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( email ); +// String resetToken = setup.getMgmtSvc().getPasswordResetTokenForAdminUser( userInfo.getUuid(), 15000 ); +// +// assertTrue( setup.getMgmtSvc().checkPasswordResetTokenForAdminUser( userInfo.getUuid(), resetToken ) ); +// +// refreshIndex(context.getOrgName(), context.getAppName()); +// +// Form formData = new Form(); +// formData.add( "token", resetToken ); +// formData.add( "password1", "sesame" ); +// formData.add( "password2", "sesame" ); +// +// String html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" ) +// .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData ); +// +// assertTrue( html.contains( "password set" ) ); +// +// refreshIndex(context.getOrgName(), context.getAppName()); +// +// assertFalse( setup.getMgmtSvc().checkPasswordResetTokenForAdminUser( userInfo.getUuid(), resetToken ) ); +// +// html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" ) +// .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData ); +// +// assertTrue( html.contains( "invalid token" ) ); +// } +// +// +// @Test +// @Ignore( "causes problems in build" ) +// public void passwordResetIncorrectUserName() throws Exception { +// +// String email = "test2@usergrid.com"; +// setup.getMgmtSvc().createAdminUser( "test2", "test2", "test2@usergrid.com", "sesa2me", false, false ); +// UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( email ); +// String resetToken = setup.getMgmtSvc().getPasswordResetTokenForAdminUser( userInfo.getUuid(), 15000 ); +// +// assertTrue( setup.getMgmtSvc().checkPasswordResetTokenForAdminUser( userInfo.getUuid(), resetToken ) ); +// +// Form formData = new Form(); +// formData.add( "token", resetToken ); +// formData.add( "password1", "sesa2me" ); +// formData.add( "password2", "sesa2me" ); +// +// String html = resource().path( "/management/users/" + "noodle" + userInfo.getUsername() + "/resetpw" ) +// .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData ); +// +// assertTrue( html.contains( "Incorrect username entered" ) ); +// +// html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" ) +// .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData ); +// +// assertTrue( html.contains( "password set" ) ); +// } +// +// +// @Test +// public void checkPasswordHistoryConflict() throws Exception { +// +// String[] passwords = new String[] { "password1", "password2", "password3", "password4" }; +// +// UserInfo user = +// setup.getMgmtSvc().createAdminUser( "edanuff", "Ed Anuff", "ed@anuff.com", passwords[0], true, false ); +// assertNotNull( user ); +// +// refreshIndex(context.getOrgName(), context.getAppName()); +// +// OrganizationInfo organization = setup.getMgmtSvc().createOrganization( "ed-organization", user, true ); +// assertNotNull( organization ); +// +// refreshIndex(context.getOrgName(), context.getAppName()); +// +// // set history to 1 +// Map props = new HashMap(); +// props.put( OrganizationInfo.PASSWORD_HISTORY_SIZE_KEY, 1 ); +// organization.setProperties( props ); +// setup.getMgmtSvc().updateOrganization( organization ); +// +// refreshIndex(context.getOrgName(), context.getAppName()); +// +// UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( "ed@anuff.com" ); +// +// Map payload = hashMap( "oldpassword", passwords[0] ).map( "newpassword", passwords[0] ); // fail +// +// try { +// JsonNode node = mapper.readTree( resource().path( "/management/users/edanuff/password" ) +// .accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); +// fail( "should fail with conflict" ); +// } +// catch ( UniformInterfaceException e ) { +// assertEquals( 409, e.getResponse().getStatus() ); +// } +// +// payload.put( "newpassword", passwords[1] ); // ok +// JsonNode node = mapper.readTree( resource().path( "/management/users/edanuff/password" ) +// .accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); +// payload.put( "oldpassword", passwords[1] ); +// +// refreshIndex(context.getOrgName(), context.getAppName()); +// +// payload.put( "newpassword", passwords[0] ); // fail +// try { +// node = mapper.readTree( resource().path( "/management/users/edanuff/password" ) +// .accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); +// fail( "should fail with conflict" ); +// } +// catch ( UniformInterfaceException e ) { +// assertEquals( 409, e.getResponse().getStatus() ); +// } +// } +// +// +// @Test +// public void checkPasswordChangeTime() throws Exception { +// +// final TestUser user = context.getActiveUser(); +// String email = user.getEmail(); +// UserInfo userInfo = setup.getMgmtSvc().getAdminUserByEmail( email ); +// String resetToken = setup.getMgmtSvc().getPasswordResetTokenForAdminUser( userInfo.getUuid(), 15000 ); +// +// refreshIndex(context.getOrgName(), context.getAppName()); +// +// Form formData = new Form(); +// formData.add( "token", resetToken ); +// formData.add( "password1", "sesame" ); +// formData.add( "password2", "sesame" ); +// +// String html = resource().path( "/management/users/" + userInfo.getUsername() + "/resetpw" ) +// .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class, formData ); +// assertTrue( html.contains( "password set" ) ); +// +// refreshIndex(context.getOrgName(), context.getAppName()); +// +// JsonNode node = mapper.readTree( resource().path( "/management/token" ) +// .queryParam( "grant_type", "password" ) +// .queryParam( "username", email ).queryParam( "password", "sesame" ) +// .accept( MediaType.APPLICATION_JSON ) +// .get( String.class )); +// +// Long changeTime = node.get( "passwordChanged" ).longValue(); +// assertTrue( System.currentTimeMillis() - changeTime < 2000 ); +// +// Map payload = hashMap( "oldpassword", "sesame" ).map( "newpassword", "test" ); +// node = mapper.readTree( resource().path( "/management/users/" + userInfo.getUsername() + "/password" ) +// .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE ) +// .post( String.class, payload )); +// +// refreshIndex(context.getOrgName(), context.getAppName()); +// +// node = mapper.readTree( resource().path( "/management/token" ) +// .queryParam( "grant_type", "password" ) +// .queryParam( "username", email ) +// .queryParam( "password", "test" ) +// .accept( MediaType.APPLICATION_JSON ) +// .get( String.class )); +// +// Long changeTime2 = node.get( "passwordChanged" ).longValue(); +// assertTrue( changeTime < changeTime2 ); +// assertTrue( System.currentTimeMillis() - changeTime2 < 2000 ); +// +// node = mapper.readTree( resource().path( "/management/me" ).queryParam( "grant_type", "password" ) +// .queryParam( "username", email ).queryParam( "password", "test" ).accept( MediaType.APPLICATION_JSON ) +// .get( String.class )); +// +// Long changeTime3 = node.get( "passwordChanged" ).longValue(); +// assertEquals( changeTime2, changeTime3 ); +// } +// +// +// /** USERGRID-1960 */ +// @Test +// @Ignore( "Depends on other tests" ) +// public void listOrgUsersByName() { +// JsonNode response = context.management().orgs().organization( context.getOrgName() ).users().get(); +// +// //get the response and verify our user is there +// JsonNode adminNode = response.get( "data" ).get( 0 ); +// assertEquals( context.getActiveUser().getEmail(), adminNode.get( "email" ).asText() ); +// assertEquals( context.getActiveUser().getUser(), adminNode.get( "username" ).asText() ); +// } +// +// @Test +// public void createOrgFromUserConnectionFail() throws Exception { +// +// +// Map payload = hashMap( "email", "orgfromuserconn@apigee.com" ).map( "password", "password" ) +// .map( "organization", "orgfromuserconn" ); +// +// JsonNode node = mapper.readTree( resource().path( "/management/organizations" ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); +// +// String userId = node.get( "data" ).get( "owner" ).get( "uuid" ).asText(); +// +// assertNotNull( node ); +// +// String token = mgmtToken( "orgfromuserconn@apigee.com", "password" ); +// +// node = mapper.readTree( resource().path( String.format( "/management/users/%s/", userId ) ).queryParam( "access_token", token ) +// .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class )); +// +// logNode( node ); +// +// payload = hashMap( "organization", "Orgfromuserconn" ); +// +// // try to create the same org again off the connection +// try { +// node = mapper.readTree( resource().path( String.format( "/management/users/%s/organizations", userId ) ) +// .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON ) +// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload )); +// fail( "Should have thrown unique exception on org name" ); +// } +// catch ( Exception ex ) { +// } } }