usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rockers...@apache.org
Subject [03/18] incubator-usergrid git commit: Added additional admin confirmation tests and fixes for the token resource.
Date Tue, 03 Mar 2015 20:38:25 GMT
Added additional admin confirmation tests and fixes for the token resource.


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

Branch: refs/heads/two-dot-o
Commit: 454cf6195e00763f132e91bff2bf0b76df1e3d01
Parents: 635b183
Author: grey <greyes@apigee.com>
Authored: Thu Feb 26 17:24:21 2015 -0800
Committer: grey <greyes@apigee.com>
Committed: Thu Feb 26 17:24:21 2015 -0800

----------------------------------------------------------------------
 .../usergrid/rest/test/PropertiesResource.java  |   2 +-
 .../usergrid/rest/management/AdminUsersIT.java  | 139 +++++++++++--------
 .../endpoints/mgmt/TokenResource.java           |   4 +-
 3 files changed, 81 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/454cf619/stack/rest/src/main/java/org/apache/usergrid/rest/test/PropertiesResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/test/PropertiesResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/test/PropertiesResource.java
index 691ea46..c414b5f 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/test/PropertiesResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/test/PropertiesResource.java
@@ -37,7 +37,7 @@ import org.springframework.stereotype.Component;
 import org.apache.usergrid.rest.AbstractContextResource;
 
 
-/** 
+/**
  * Set properties at runtime, for testing purposes only and only works with usergrid.test=true.
  */
 @Component

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/454cf619/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 005c4ad..ac3cc10 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
@@ -38,35 +38,18 @@ 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.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.resource2point0.model.ApiResponse;
 import org.apache.usergrid.rest.test.resource2point0.model.Entity;
+import org.apache.usergrid.rest.test.resource2point0.model.QueryParameters;
 import org.apache.usergrid.rest.test.resource2point0.model.Token;
-import org.apache.usergrid.rest.test.resource2point0.model.User;
-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.deploy.util.SessionState;
+
 import com.sun.jersey.api.client.ClientResponse;
 import com.sun.jersey.api.client.UniformInterfaceException;
 import com.sun.jersey.api.representation.Form;
@@ -84,6 +67,9 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import org.apache.usergrid.rest.test.resource2point0.model.Organization;
+import org.apache.usergrid.rest.test.resource2point0.model.User;
+
 
 /**
  * Contains all tests relating to Admin Users
@@ -219,54 +205,73 @@ public class AdminUsersIT extends AbstractRestIT {
 
     }
 
-    //everything below is MUUserResourceIT
-
     @Test
-    public void testCaseSensitivityAdminUser() throws Exception {
-
-        //Create adminUser values
-        Entity adminUserPayload = new Entity();
-        String username = "testCaseSensitivityAdminUser"+ org.apache.usergrid.persistence.index.utils
-            .UUIDUtils
-            .newTimeUUID();
-        adminUserPayload.put( "username", username );
-        adminUserPayload.put( "name", username );
-        adminUserPayload.put( "email", username+"@usergrid.com" );
-        adminUserPayload.put( "password", username );
-
-        //create adminUser
-        //Entity adminUserResponse = restClient.management().orgs().organization( clientSetup.getOrganizationName()
).users().post( adminUserPayload );
-        management.users().post( adminUserPayload );
+    public void testUnconfirmedAdminLoginRET()  throws Exception{
+
+        Map<String,Object> testPropertiesMap = new HashMap<>(  );
+
+        testPropertiesMap.put( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
+        testPropertiesMap.put( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
+        testPropertiesMap.put( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" );
+        testPropertiesMap.put( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
+        testPropertiesMap.put( PROPERTIES_NOTIFY_ADMIN_OF_ACTIVATION, "true" );
+
+        Entity testPropertiesPayload = new Entity( testPropertiesMap );
+
+        clientSetup.getRestClient().testPropertiesResource().post(testPropertiesPayload);
 
         refreshIndex();
 
-        Entity adminUserResponse = management.users().user( username.toLowerCase() ).get();
-        assertNotNull( adminUserResponse );
+        ApiResponse apiResponse = clientSetup.getRestClient().testPropertiesResource().get();
 
-//        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" );
+        assertEquals( "true" ,apiResponse.getProperties().get( PROPERTIES_NOTIFY_ADMIN_OF_ACTIVATION
) );
+        assertEquals( "sysadmin-1@mockserver.com" ,apiResponse.getProperties().get(PROPERTIES_SYSADMIN_EMAIL));
+        assertEquals( "true" ,apiResponse.getProperties().get( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION
) );
+        assertEquals( "false" ,apiResponse.getProperties().get( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS
) );
+        assertEquals( "false" ,apiResponse.getProperties().get( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS
) );
+
+        Organization organization = createOrgPayload( "testUnconfirmedAdminLogin", null );
+
+        Organization organizationResponse = clientSetup.getRestClient().management().orgs().post(
organization );
+
+        assertNotNull( organizationResponse );
+
+        User adminUser = organizationResponse.getOwner();
+
+        assertNotNull( adminUser );
+        assertFalse( "adminUser should not be activated yet", adminUser.getActivated());
+        assertFalse( "adminUser should not be confirmed yet", adminUser.getConfirmed());
 
-        // 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 ));
+
+        QueryParameters queryParameters = new QueryParameters();
+        queryParameters.addParam( "grant_type","password").addParam( "username",adminUser.getUsername()
)
+                       .addParam( "password",organization.getPassword() );
+
+        //Token adminToken = new Token( "password",adminUser.getUsername(),organization.getName()
);
+
+
+        try {
+
+            Token tokenReturned = management().token().get( queryParameters );
+        }
+        catch(Exception e){
+            //catch forbbiedn here
+        }
+
+        List<Message> inbox = Mailbox.get( organization.getEmail() );
+        assertFalse( inbox.isEmpty() );
+
+        MockImapClient client = new MockImapClient( "mockserver.com", "test-user-46", "somepassword"
);
+        client.processMail();
+
+        Message confirmation = inbox.get( 0 );
+        assertEquals( "User Account Confirmation: " + organization.getEmail(), confirmation.getSubject()
);
+
+        //String token = getTokenFromMessage(confirmation);
 
     }
-//
-//
+
+
 //    @Test
 //    public void testUnconfirmedAdminLogin() throws Exception {
 //
@@ -369,7 +374,7 @@ public class AdminUsersIT extends AbstractRestIT {
 //            setTestProperties( originalProperties );
 //        }
 //    }
-//
+
 //
 //    @Test
 //    public void testSystemAdminNeedsNoConfirmation() throws Exception {
@@ -836,4 +841,16 @@ public class AdminUsersIT extends AbstractRestIT {
 //        }
 //    }
 
+    /**
+     * Create an organization payload with almost the same value for everyfield.
+     * @param baseName
+     * @param properties
+     * @return
+     */
+    public Organization createOrgPayload(String baseName,Map properties){
+        String orgName = baseName + org.apache.usergrid.persistence.index.utils.UUIDUtils.newTimeUUID();
+        return new Organization( orgName,
+            orgName,orgName+"@usergrid",orgName,orgName, properties);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/454cf619/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/TokenResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/TokenResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/TokenResource.java
index ca90ab1..cb4d286 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/TokenResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/TokenResource.java
@@ -53,11 +53,11 @@ public class TokenResource extends NamedResource {
      *
      * @return
      */
-    public Token post(QueryParameters params) {
+    public Token get(QueryParameters params) {
         WebResource resource = getResource();
         resource = addParametersToResource(resource, params);
         Token token = resource.type(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON)
-            .get(Token.class);
+                              .get(Token.class);
 
         this.context.setToken(token);
         return token;


Mime
View raw message