usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [2/2] git commit: Refactoring management tests into 3 main categories based on what they query against.
Date Wed, 17 Sep 2014 19:22:18 GMT
Refactoring management tests into 3 main categories based on what they query against.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f42ebde4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f42ebde4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f42ebde4

Branch: refs/heads/two-dot-o-rest-refactor
Commit: f42ebde4e75b29343f5e3570534dbed099b0f050
Parents: 0cc97c6
Author: grey <greyes@apigee.com>
Authored: Wed Sep 17 12:22:13 2014 -0700
Committer: grey <greyes@apigee.com>
Committed: Wed Sep 17 12:22:13 2014 -0700

----------------------------------------------------------------------
 .../usergrid/rest/ConcurrentRestITSuite.java    |   3 -
 .../org/apache/usergrid/rest/RestITSuite.java   |   2 -
 .../usergrid/rest/management/AccessTokenIT.java | 333 ++++++++
 .../usergrid/rest/management/AdminUsersIT.java  | 792 +++++++++++++++++++
 .../rest/management/ManagementResourceIT.java   | 397 +---------
 .../rest/management/OrganizationsIT.java        | 362 +++++++++
 .../organizations/OrganizationResourceIT.java   |  90 ---
 .../organizations/OrganizationsResourceIT.java  | 322 --------
 .../rest/management/users/MUUserResourceIT.java | 654 ---------------
 .../UsersOrganizationsResourceIT.java           |  72 --
 10 files changed, 1488 insertions(+), 1539 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f42ebde4/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java b/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java
index efc3901..4456054 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/ConcurrentRestITSuite.java
@@ -39,9 +39,6 @@ import org.apache.usergrid.rest.filters.ContentTypeResourceIT;
 import org.apache.usergrid.rest.management.ManagementResourceIT;
 import org.apache.usergrid.rest.management.RegistrationIT;
 import org.apache.usergrid.rest.management.organizations.AdminEmailEncodingIT;
-import org.apache.usergrid.rest.management.organizations.OrganizationResourceIT;
-import org.apache.usergrid.rest.management.organizations.OrganizationsResourceIT;
-import org.apache.usergrid.rest.management.users.MUUserResourceIT;
 import org.apache.usergrid.rest.management.users.organizations.UsersOrganizationsResourceIT;
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f42ebde4/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java b/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java
index d34f8e4..dbf8834 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/RestITSuite.java
@@ -35,8 +35,6 @@ import org.apache.usergrid.rest.applications.users.PermissionsResourceIT;
 import org.apache.usergrid.rest.applications.users.UserResourceIT;
 import org.apache.usergrid.rest.filters.ContentTypeResourceIT;
 import org.apache.usergrid.rest.management.organizations.AdminEmailEncodingIT;
-import org.apache.usergrid.rest.management.organizations.OrganizationResourceIT;
-import org.apache.usergrid.rest.management.organizations.OrganizationsResourceIT;
 import org.apache.usergrid.rest.management.users.organizations.UsersOrganizationsResourceIT;
 
 @RunWith(Suite.class)

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f42ebde4/stack/rest/src/test/java/org/apache/usergrid/rest/management/AccessTokenIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/AccessTokenIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/AccessTokenIT.java
new file mode 100644
index 0000000..75743cb
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/AccessTokenIT.java
@@ -0,0 +1,333 @@
+package org.apache.usergrid.rest.management;
+
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+
+import org.junit.Test;
+
+import org.apache.usergrid.rest.AbstractRestIT;
+import org.apache.usergrid.rest.management.organizations.OrganizationsResource;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import com.sun.jersey.api.representation.Form;
+
+import static org.apache.usergrid.utils.MapUtils.hashMap;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+
+/**
+ * Created by ApigeeCorporation on 9/17/14.
+ */
+
+
+/**
+ * Contains all tests that related to the Access Tokens on the management endpoint.
+ */
+public class AccessTokenIT extends AbstractRestIT {
+
+    public AccessTokenIT() throws Exception{
+
+    }
+
+    @Test
+    public void tokenTtl() throws Exception {
+
+        long ttl = 2000;
+
+        JsonNode node = mapper.readTree( resource().path( "/management/token" ).queryParam( "grant_type", "password" )
+                                                   .queryParam( "username", "test@usergrid.com" ).queryParam( "password", "test" )
+                                                   .queryParam( "ttl", String.valueOf( ttl ) ).accept( MediaType.APPLICATION_JSON )
+                                                   .get( String.class ));
+
+        long startTime = System.currentTimeMillis();
+
+        String token = node.get( "access_token" ).textValue();
+
+        assertNotNull( token );
+
+        JsonNode userdata = mapper.readTree( resource().path( "/management/users/test@usergrid.com" ).queryParam( "access_token", token )
+                                                       .accept( MediaType.APPLICATION_JSON ).get( String.class ));
+
+        assertEquals( "test@usergrid.com", userdata.get( "data" ).get( "email" ).asText() );
+
+        // wait for the token to expire
+        Thread.sleep( ttl - ( System.currentTimeMillis() - startTime ) + 1000 );
+
+        ClientResponse.Status responseStatus = null;
+        try {
+            userdata = mapper.readTree( resource().path( "/management/users/test@usergrid.com" ).accept( MediaType.APPLICATION_JSON )
+                                                  .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
+        }
+        catch ( UniformInterfaceException uie ) {
+            responseStatus = uie.getResponse().getClientResponseStatus();
+        }
+
+        assertEquals( ClientResponse.Status.UNAUTHORIZED, responseStatus );
+    }
+
+
+    @Test
+    public void token() throws Exception {
+        JsonNode node = mapper.readTree( resource().path( "/management/token" ).queryParam( "grant_type", "password" )
+                                                   .queryParam( "username", "test@usergrid.com" ).queryParam( "password", "test" )
+                                                   .accept( MediaType.APPLICATION_JSON ).get( String.class ));
+
+        logNode( node );
+        String token = node.get( "access_token" ).textValue();
+        assertNotNull( token );
+
+        // set an organization property
+        HashMap<String, Object> payload = new HashMap<String, Object>();
+        Map<String, Object> properties = new HashMap<String, Object>();
+        properties.put( "securityLevel", 5 );
+        payload.put( OrganizationsResource.ORGANIZATION_PROPERTIES, properties );
+        node = mapper.readTree( resource().path( "/management/organizations/test-organization" )
+                                          .queryParam( "access_token", superAdminToken() ).accept( MediaType.APPLICATION_JSON )
+                                          .type( MediaType.APPLICATION_JSON_TYPE ).put( String.class, payload ));
+
+        refreshIndex("test-organization", "test-app");
+
+        // ensure the organization property is included
+        node = mapper.readTree( resource().path( "/management/token" ).queryParam( "access_token", token )
+                                          .accept( MediaType.APPLICATION_JSON ).get( String.class ));
+        logNode( node );
+
+        JsonNode securityLevel = node.findValue( "securityLevel" );
+        assertNotNull( securityLevel );
+        assertEquals( 5L, securityLevel.asLong() );
+    }
+
+
+    @Test
+    public void meToken() throws Exception {
+        JsonNode node = mapper.readTree( resource().path( "/management/me" ).queryParam( "grant_type", "password" )
+                                                   .queryParam( "username", "test@usergrid.com" ).queryParam( "password", "test" )
+                                                   .accept( MediaType.APPLICATION_JSON ).get( String.class ));
+
+        logNode( node );
+        String token = node.get( "access_token" ).textValue();
+        assertNotNull( token );
+
+        node = mapper.readTree( resource().path( "/management/me" ).queryParam( "access_token", token )
+                                          .accept( MediaType.APPLICATION_JSON ).get( String.class ));
+        logNode( node );
+
+        assertNotNull( node.get( "passwordChanged" ) );
+        assertNotNull( node.get( "access_token" ) );
+        assertNotNull( node.get( "expires_in" ) );
+        JsonNode userNode = node.get( "user" );
+        assertNotNull( userNode );
+        assertNotNull( userNode.get( "uuid" ) );
+        assertNotNull( userNode.get( "username" ) );
+        assertNotNull( userNode.get( "email" ) );
+        assertNotNull( userNode.get( "name" ) );
+        assertNotNull( userNode.get( "properties" ) );
+        JsonNode orgsNode = userNode.get( "organizations" );
+        assertNotNull( orgsNode );
+        JsonNode orgNode = orgsNode.get( "test-organization" );
+        assertNotNull( orgNode );
+        assertNotNull( orgNode.get( "name" ) );
+        assertNotNull( orgNode.get( "properties" ) );
+    }
+
+
+    @Test
+    public void meTokenPost() throws Exception {
+        Map<String, String> payload =
+                hashMap( "grant_type", "password" ).map( "username", "test@usergrid.com" ).map( "password", "test" );
+
+        JsonNode node = mapper.readTree( resource().path( "/management/me" ).accept( MediaType.APPLICATION_JSON )
+                                                   .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
+
+        logNode( node );
+        String token = node.get( "access_token" ).textValue();
+
+        assertNotNull( token );
+
+        refreshIndex("test-organization", "test-app");
+
+        node = mapper.readTree( resource().path( "/management/me" ).queryParam( "access_token", token )
+                                          .accept( MediaType.APPLICATION_JSON ).get( String.class ));
+        logNode( node );
+    }
+
+
+    @Test
+    public void meTokenPostForm() throws IOException {
+
+        Form form = new Form();
+        form.add( "grant_type", "password" );
+        form.add( "username", "test@usergrid.com" );
+        form.add( "password", "test" );
+
+        JsonNode node = mapper.readTree( resource().path( "/management/me" ).accept( MediaType.APPLICATION_JSON )
+                                                   .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE )
+                                                   .entity( form, MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class ));
+
+        logNode( node );
+        String token = node.get( "access_token" ).textValue();
+
+        assertNotNull( token );
+
+        refreshIndex("test-organization", "test-app");
+
+        node = mapper.readTree( resource().path( "/management/me" ).queryParam( "access_token", token )
+                                          .accept( MediaType.APPLICATION_JSON ).get( String.class ));
+        logNode( node );
+    }
+
+
+    @Test
+    public void ttlNan() throws Exception {
+
+        Map<String, String> payload =
+                hashMap( "grant_type", "password" ).map( "username", "test@usergrid.com" ).map( "password", "test" )
+                                                   .map( "ttl", "derp" );
+
+        ClientResponse.Status responseStatus = null;
+        try {
+            resource().path( "/management/token" ).accept( MediaType.APPLICATION_JSON )
+                      .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload );
+        }
+        catch ( UniformInterfaceException uie ) {
+            responseStatus = uie.getResponse().getClientResponseStatus();
+        }
+
+        assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus );
+    }
+
+
+    @Test
+    public void ttlOverMax() throws Exception {
+
+        Map<String, String> payload =
+                hashMap( "grant_type", "password" ).map( "username", "test@usergrid.com" ).map( "password", "test" )
+                                                   .map( "ttl", Long.MAX_VALUE + "" );
+
+        ClientResponse.Status responseStatus = null;
+
+        try {
+            resource().path( "/management/token" ).accept( MediaType.APPLICATION_JSON )
+                      .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload );
+        }
+        catch ( UniformInterfaceException uie ) {
+            responseStatus = uie.getResponse().getClientResponseStatus();
+        }
+
+        assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus );
+    }
+
+
+    @Test
+    public void revokeToken() throws Exception {
+        String token1 = super.adminToken();
+        String token2 = super.adminToken();
+
+        JsonNode response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token1 )
+                                                       .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                                                       .get( String.class ));
+
+        assertEquals( "test@usergrid.com", response.get( "data" ).get( "email" ).asText() );
+
+        response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token2 )
+                                              .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                                              .get( String.class ));
+
+        assertEquals( "test@usergrid.com", response.get( "data" ).get( "email" ).asText() );
+
+        // now revoke the tokens
+        response = mapper.readTree( resource().path( "/management/users/test/revoketokens" ).queryParam( "access_token", superAdminToken() )
+                                              .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                                              .post( String.class ));
+
+        refreshIndex("test-organization", "test-app");
+
+        // the tokens shouldn't work
+
+        ClientResponse.Status status = null;
+
+        try {
+            response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token1 )
+                                                  .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                                                  .get( String.class ));
+        }
+        catch ( UniformInterfaceException uie ) {
+            status = uie.getResponse().getClientResponseStatus();
+        }
+
+        assertEquals( ClientResponse.Status.UNAUTHORIZED, status );
+
+        status = null;
+
+        try {
+            response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token2 )
+                                                  .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                                                  .get( String.class ));
+        }
+        catch ( UniformInterfaceException uie ) {
+            status = uie.getResponse().getClientResponseStatus();
+        }
+
+        assertEquals( ClientResponse.Status.UNAUTHORIZED, status );
+
+        String token3 = super.adminToken();
+        String token4 = super.adminToken();
+
+        response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token3 )
+                                              .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                                              .get( String.class ));
+
+        assertEquals( "test@usergrid.com", response.get( "data" ).get( "email" ).asText() );
+
+        response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token4 )
+                                              .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                                              .get( String.class ));
+
+        assertEquals( "test@usergrid.com", response.get( "data" ).get( "email" ).asText() );
+
+        // now revoke the token3
+        response = mapper.readTree( resource().path( "/management/users/test/revoketoken" ).queryParam( "access_token", token3 )
+                                              .queryParam( "token", token3 ).accept( MediaType.APPLICATION_JSON )
+                                              .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
+
+        // the token3 shouldn't work
+
+        status = null;
+
+        try {
+            response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token3 )
+                                                  .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                                                  .get( String.class ));
+        }
+        catch ( UniformInterfaceException uie ) {
+            status = uie.getResponse().getClientResponseStatus();
+        }
+
+        assertEquals( ClientResponse.Status.UNAUTHORIZED, status );
+
+        status = null;
+
+        try {
+            response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token4 )
+                                                  .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                                                  .get( String.class ));
+
+            status = ClientResponse.Status.OK;
+        }
+        catch ( UniformInterfaceException uie ) {
+            status = uie.getResponse().getClientResponseStatus();
+        }
+
+        assertEquals( ClientResponse.Status.OK, status );
+    }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f42ebde4/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
new file mode 100644
index 0000000..46f7d32
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/AdminUsersIT.java
@@ -0,0 +1,792 @@
+package org.apache.usergrid.rest.management;
+
+
+/**
+ * Created by ApigeeCorporation on 9/17/14.
+ */
+
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMultipart;
+import javax.ws.rs.core.MediaType;
+
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.jvnet.mock_javamail.Mailbox;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.commons.lang.StringUtils;
+
+import org.apache.usergrid.management.AccountCreationProps;
+import org.apache.usergrid.management.ActivationState;
+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.security.TestAdminUser;
+import org.apache.usergrid.rest.test.security.TestUser;
+import org.apache.usergrid.security.AuthPrincipalInfo;
+import org.apache.usergrid.security.AuthPrincipalType;
+import org.apache.usergrid.utils.UUIDUtils;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import com.sun.jersey.api.representation.Form;
+
+import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION;
+import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_NOTIFY_ADMIN_OF_ACTIVATION;
+import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS;
+import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS;
+import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_EMAIL;
+import static org.apache.usergrid.utils.MapUtils.hashMap;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+
+/**
+ * Contains all tests relating to Admin Users
+ */
+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 {
+
+    }
+
+
+
+
+    /**
+     * Test if we can reset our password as an admin
+     */
+    @Test
+    public void setSelfAdminPasswordAsAdmin() throws IOException {
+
+        String newPassword = "foo";
+
+        Map<String, String> data = new HashMap<String, String>();
+        data.put( "newpassword", newPassword );
+        data.put( "oldpassword", "test" );
+
+        // change the password as admin. The old password isn't required
+        JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON )
+                                                   .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data ));
+
+        assertNull( getError( node ) );
+
+        refreshIndex("test-organization", "test-app");
+
+        adminAccessToken = mgmtToken( "test", newPassword );
+
+        data.put( "oldpassword", newPassword );
+        data.put( "newpassword", "test" );
+
+        node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", adminAccessToken )
+                                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
+                                          .post( String.class, data ));
+
+        assertNull( getError( node ) );
+    }
+
+
+    @Test
+    public void passwordMismatchErrorAdmin() {
+        String origPassword = "foo";
+        String newPassword = "bar";
+
+        Map<String, String> data = new HashMap<String, String>();
+        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<String, String> data = new HashMap<String, String>();
+        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(),
+                "<a href=\"mailto:test@usergrid.com\">" ) );
+    }
+
+    //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
+    //@Ignore // Because JSP is broken in test setup, possibly due to JSTL classloader issue
+    // see also: https://issues.apache.org/jira/browse/USERGRID-209
+    public void testUnconfirmedAdminLogin() throws Exception {
+
+        // Setup properties to require confirmation of users
+        // -------------------------------------------
+
+        Map<String, String> 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<Message> 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<String, String> 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<String, String> 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<String, String> 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<String, Object> payload = new HashMap<String, Object>();
+        Map<String, Object> properties = new HashMap<String, Object>();
+        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<String, Object> payload = new HashMap<String, Object>();
+        Map<String, Object> properties = new HashMap<String, Object>();
+        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<Message> inbox = org.jvnet.mock_javamail.Mailbox.get( email );
+
+        assertFalse( inbox.isEmpty() );
+        logNode( node );
+    }
+
+
+    private Map<String, String> buildOrgUserPayload( String caller ) {
+        String className = this.getClass().getSimpleName();
+        Map<String, String> 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
+    @Ignore("Because JSP is broken in test setup, possibly due to JSTL classloader issue. "
+            + "see also: https://issues.apache.org/jira/browse/USERGRID-209")
+    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<String, Object> props = new HashMap<String, Object>();
+        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<String, String> 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
+    @Ignore("Because JSP is broken in test setup, possibly due to JSTL classloader issue. "
+            + "see also: https://issues.apache.org/jira/browse/USERGRID-209")
+    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<String, String> 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<String, String> 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 ) {
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f42ebde4/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
index af02c65..58691a1 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
@@ -60,101 +60,6 @@ public class ManagementResourceIT extends AbstractRestIT {
     }
 
 
-    /**
-     * Test if we can reset our password as an admin
-     */
-    @Test
-    public void setSelfAdminPasswordAsAdmin() throws IOException {
-
-        String newPassword = "foo";
-
-        Map<String, String> data = new HashMap<String, String>();
-        data.put( "newpassword", newPassword );
-        data.put( "oldpassword", "test" );
-
-        // change the password as admin. The old password isn't required
-        JsonNode node = mapper.readTree( resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON )
-                                  .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data ));
-
-        assertNull( getError( node ) );
-
-        refreshIndex("test-organization", "test-app");
-
-        adminAccessToken = mgmtToken( "test", newPassword );
-
-        data.put( "oldpassword", newPassword );
-        data.put( "newpassword", "test" );
-
-        node = mapper.readTree( resource().path( "/management/users/test/password" ).queryParam( "access_token", adminAccessToken )
-                         .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                         .post( String.class, data ));
-
-        assertNull( getError( node ) );
-    }
-
-
-    @Test
-    public void passwordMismatchErrorAdmin() {
-        String origPassword = "foo";
-        String newPassword = "bar";
-
-        Map<String, String> data = new HashMap<String, String>();
-        data.put( "newpassword", origPassword );
-
-        // now change the password, with an incorrect old password
-
-        data.put( "oldpassword", origPassword );
-        data.put( "newpassword", newPassword );
-
-        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( Status.BAD_REQUEST, responseStatus );
-    }
-
-
-    @Test
-    public void setAdminPasswordAsSysAdmin() throws IOException {
-
-        String superToken = superAdminToken();
-
-        String newPassword = "foo";
-
-        Map<String, String> data = new HashMap<String, String>();
-        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 ) );
-    }
 
 
     /**
@@ -227,14 +132,7 @@ public class ManagementResourceIT extends AbstractRestIT {
     }
 
 
-    @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(),
-                "<a href=\"mailto:test@usergrid.com\">" ) );
-    }
+
 
 
     /**
@@ -383,297 +281,4 @@ public class ManagementResourceIT extends AbstractRestIT {
         assertEquals( 3, appdata.get( "metadata" ).get( "collections" ).get( "roles" ).get( "count" ).asInt() );
     }
 
-
-    @Test
-    public void tokenTtl() throws Exception {
-
-        long ttl = 2000;
-
-        JsonNode node = mapper.readTree( resource().path( "/management/token" ).queryParam( "grant_type", "password" )
-                                  .queryParam( "username", "test@usergrid.com" ).queryParam( "password", "test" )
-                                  .queryParam( "ttl", String.valueOf( ttl ) ).accept( MediaType.APPLICATION_JSON )
-                                  .get( String.class ));
-
-        long startTime = System.currentTimeMillis();
-
-        String token = node.get( "access_token" ).textValue();
-
-        assertNotNull( token );
-
-        JsonNode userdata = mapper.readTree( resource().path( "/management/users/test@usergrid.com" ).queryParam( "access_token", token )
-                                      .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-
-        assertEquals( "test@usergrid.com", userdata.get( "data" ).get( "email" ).asText() );
-
-        // wait for the token to expire
-        Thread.sleep( ttl - ( System.currentTimeMillis() - startTime ) + 1000 );
-
-        Status responseStatus = null;
-        try {
-            userdata = mapper.readTree( resource().path( "/management/users/test@usergrid.com" ).accept( MediaType.APPLICATION_JSON )
-                                 .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
-        }
-        catch ( UniformInterfaceException uie ) {
-            responseStatus = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertEquals( Status.UNAUTHORIZED, responseStatus );
-    }
-
-
-    @Test
-    public void token() throws Exception {
-        JsonNode node = mapper.readTree( resource().path( "/management/token" ).queryParam( "grant_type", "password" )
-                                  .queryParam( "username", "test@usergrid.com" ).queryParam( "password", "test" )
-                                  .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-
-        logNode( node );
-        String token = node.get( "access_token" ).textValue();
-        assertNotNull( token );
-
-        // set an organization property
-        HashMap<String, Object> payload = new HashMap<String, Object>();
-        Map<String, Object> properties = new HashMap<String, Object>();
-        properties.put( "securityLevel", 5 );
-        payload.put( OrganizationsResource.ORGANIZATION_PROPERTIES, properties );
-        node = mapper.readTree( resource().path( "/management/organizations/test-organization" )
-                         .queryParam( "access_token", superAdminToken() ).accept( MediaType.APPLICATION_JSON )
-                         .type( MediaType.APPLICATION_JSON_TYPE ).put( String.class, payload ));
-
-        refreshIndex("test-organization", "test-app");
-
-        // ensure the organization property is included
-        node = mapper.readTree( resource().path( "/management/token" ).queryParam( "access_token", token )
-                         .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-        logNode( node );
-
-        JsonNode securityLevel = node.findValue( "securityLevel" );
-        assertNotNull( securityLevel );
-        assertEquals( 5L, securityLevel.asLong() );
-    }
-
-
-    @Test
-    public void meToken() throws Exception {
-        JsonNode node = mapper.readTree( resource().path( "/management/me" ).queryParam( "grant_type", "password" )
-                                  .queryParam( "username", "test@usergrid.com" ).queryParam( "password", "test" )
-                                  .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-
-        logNode( node );
-        String token = node.get( "access_token" ).textValue();
-        assertNotNull( token );
-
-        node = mapper.readTree( resource().path( "/management/me" ).queryParam( "access_token", token )
-                         .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-        logNode( node );
-
-        assertNotNull( node.get( "passwordChanged" ) );
-        assertNotNull( node.get( "access_token" ) );
-        assertNotNull( node.get( "expires_in" ) );
-        JsonNode userNode = node.get( "user" );
-        assertNotNull( userNode );
-        assertNotNull( userNode.get( "uuid" ) );
-        assertNotNull( userNode.get( "username" ) );
-        assertNotNull( userNode.get( "email" ) );
-        assertNotNull( userNode.get( "name" ) );
-        assertNotNull( userNode.get( "properties" ) );
-        JsonNode orgsNode = userNode.get( "organizations" );
-        assertNotNull( orgsNode );
-        JsonNode orgNode = orgsNode.get( "test-organization" );
-        assertNotNull( orgNode );
-        assertNotNull( orgNode.get( "name" ) );
-        assertNotNull( orgNode.get( "properties" ) );
-    }
-
-
-    @Test
-    public void meTokenPost() throws Exception {
-        Map<String, String> payload =
-                hashMap( "grant_type", "password" ).map( "username", "test@usergrid.com" ).map( "password", "test" );
-
-        JsonNode node = mapper.readTree( resource().path( "/management/me" ).accept( MediaType.APPLICATION_JSON )
-                                  .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
-
-        logNode( node );
-        String token = node.get( "access_token" ).textValue();
-
-        assertNotNull( token );
-
-        refreshIndex("test-organization", "test-app");
-
-       node = mapper.readTree( resource().path( "/management/me" ).queryParam( "access_token", token )
-                         .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-        logNode( node );
-    }
-
-
-    @Test
-    public void meTokenPostForm() throws IOException {
-
-        Form form = new Form();
-        form.add( "grant_type", "password" );
-        form.add( "username", "test@usergrid.com" );
-        form.add( "password", "test" );
-
-        JsonNode node = mapper.readTree( resource().path( "/management/me" ).accept( MediaType.APPLICATION_JSON )
-                                  .type( MediaType.APPLICATION_FORM_URLENCODED_TYPE )
-                                  .entity( form, MediaType.APPLICATION_FORM_URLENCODED_TYPE ).post( String.class ));
-
-        logNode( node );
-        String token = node.get( "access_token" ).textValue();
-
-        assertNotNull( token );
-
-        refreshIndex("test-organization", "test-app");
-
-        node = mapper.readTree( resource().path( "/management/me" ).queryParam( "access_token", token )
-                         .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-        logNode( node );
-    }
-
-
-    @Test
-    public void ttlNan() throws Exception {
-
-        Map<String, String> payload =
-                hashMap( "grant_type", "password" ).map( "username", "test@usergrid.com" ).map( "password", "test" )
-                                                   .map( "ttl", "derp" );
-
-        Status responseStatus = null;
-        try {
-            resource().path( "/management/token" ).accept( MediaType.APPLICATION_JSON )
-                      .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload );
-        }
-        catch ( UniformInterfaceException uie ) {
-            responseStatus = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertEquals( Status.BAD_REQUEST, responseStatus );
-    }
-
-
-    @Test
-    public void ttlOverMax() throws Exception {
-
-        Map<String, String> payload =
-                hashMap( "grant_type", "password" ).map( "username", "test@usergrid.com" ).map( "password", "test" )
-                                                   .map( "ttl", Long.MAX_VALUE + "" );
-
-        Status responseStatus = null;
-
-        try {
-            resource().path( "/management/token" ).accept( MediaType.APPLICATION_JSON )
-                      .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload );
-        }
-        catch ( UniformInterfaceException uie ) {
-            responseStatus = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertEquals( Status.BAD_REQUEST, responseStatus );
-    }
-
-
-    @Test
-    public void revokeToken() throws Exception {
-        String token1 = super.adminToken();
-        String token2 = super.adminToken();
-
-        JsonNode response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token1 )
-                                      .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                                      .get( String.class ));
-
-        assertEquals( "test@usergrid.com", response.get( "data" ).get( "email" ).asText() );
-
-        response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token2 )
-                             .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                             .get( String.class ));
-
-        assertEquals( "test@usergrid.com", response.get( "data" ).get( "email" ).asText() );
-
-        // now revoke the tokens
-        response = mapper.readTree( resource().path( "/management/users/test/revoketokens" ).queryParam( "access_token", superAdminToken() )
-                          .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                          .post( String.class ));
-
-        refreshIndex("test-organization", "test-app");
-
-        // the tokens shouldn't work
-
-        Status status = null;
-
-        try {
-            response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token1 )
-                                 .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                                 .get( String.class ));
-        }
-        catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertEquals( Status.UNAUTHORIZED, status );
-
-        status = null;
-
-        try {
-            response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token2 )
-                                 .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                                 .get( String.class ));
-        }
-        catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertEquals( Status.UNAUTHORIZED, status );
-
-        String token3 = super.adminToken();
-        String token4 = super.adminToken();
-
-        response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token3 )
-                             .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                             .get( String.class ));
-
-        assertEquals( "test@usergrid.com", response.get( "data" ).get( "email" ).asText() );
-
-        response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token4 )
-                             .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                             .get( String.class ));
-
-        assertEquals( "test@usergrid.com", response.get( "data" ).get( "email" ).asText() );
-
-        // now revoke the token3
-        response = mapper.readTree( resource().path( "/management/users/test/revoketoken" ).queryParam( "access_token", token3 )
-                             .queryParam( "token", token3 ).accept( MediaType.APPLICATION_JSON )
-                             .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class ));
-
-        // the token3 shouldn't work
-
-        status = null;
-
-        try {
-            response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token3 )
-                                 .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                                 .get( String.class ));
-        }
-        catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertEquals( Status.UNAUTHORIZED, status );
-
-        status = null;
-
-        try {
-            response = mapper.readTree( resource().path( "/management/users/test" ).queryParam( "access_token", token4 )
-                                 .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
-                                 .get( String.class ));
-
-            status = Status.OK;
-        }
-        catch ( UniformInterfaceException uie ) {
-            status = uie.getResponse().getClientResponseStatus();
-        }
-
-        assertEquals( Status.OK, status );
-    }
-
 }


Mime
View raw message