You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/02/26 18:27:05 UTC
[03/16] incubator-usergrid git commit: [USERGRID-331] Updating
AdminEmailEncodingIT
[USERGRID-331] Updating AdminEmailEncodingIT
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/3ad37356
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/3ad37356
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/3ad37356
Branch: refs/heads/USERGRID-273-indexbuffer
Commit: 3ad37356bf7f27920b39294e3fc3981318f06c2c
Parents: 6dc62ed
Author: ryan bridges <rb...@apigee.com>
Authored: Thu Jan 22 14:40:52 2015 -0500
Committer: ryan bridges <rb...@apigee.com>
Committed: Thu Jan 22 14:40:52 2015 -0500
----------------------------------------------------------------------
.../organizations/AdminEmailEncodingIT.java | 138 +++++++++++--------
.../endpoints/mgmt/ManagementResource.java | 7 +-
2 files changed, 84 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3ad37356/stack/rest/src/test/java/org/apache/usergrid/rest/management/organizations/AdminEmailEncodingIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/organizations/AdminEmailEncodingIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/organizations/AdminEmailEncodingIT.java
index 145ccd3..22dafdc 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/organizations/AdminEmailEncodingIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/organizations/AdminEmailEncodingIT.java
@@ -17,14 +17,20 @@
package org.apache.usergrid.rest.management.organizations;
-import com.fasterxml.jackson.databind.JsonNode;
-import java.io.IOException;
-import org.junit.Rule;
-import org.junit.Test;
+import com.sun.jersey.api.client.UniformInterfaceException;
import org.apache.usergrid.cassandra.Concurrent;
-import org.apache.usergrid.rest.AbstractRestIT;
-import org.apache.usergrid.rest.TestContextSetup;
-import org.apache.usergrid.rest.test.security.TestAdminUser;
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.model.Application;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
+import org.apache.usergrid.rest.test.resource2point0.model.Organization;
+import org.apache.usergrid.rest.test.resource2point0.model.Token;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -38,82 +44,94 @@ import static org.junit.Assert.assertNotNull;
*/
@Concurrent()
public class AdminEmailEncodingIT extends AbstractRestIT {
+ private static Logger log = LoggerFactory.getLogger(AdminEmailEncodingIT.class);
- @Rule
- public TestContextSetup context = new TestContextSetup( this );
-
-
+ /**
+ * Ensure that '+' characters in email addresses are handled properly
+ *
+ * @throws Exception
+ */
@Test
public void getTokenPlus() throws Exception {
- String org = "AdminEmailEncodingTestgetTokenPlus";
- String app = "Plus";
-
- doTest( "+", org, app );
+ doTest("+");
}
-
+ /**
+ * Ensure that '_' characters in email addresses are handled properly
+ *
+ * @throws Exception
+ */
@Test
public void getTokenUnderscore() throws Exception {
- String org = "AdminEmailEncodingTestgetTokenUnderscore";
- String app = "Underscore";
-
- doTest( "_", org, app );
+ doTest("_");
}
-
+ /**
+ * Ensure that '-' characters in email addresses are handled properly
+ *
+ * @throws Exception
+ */
@Test
public void getTokenDash() throws Exception {
- String org = "AdminEmailEncodingTestgetTokenDash";
- String app = "Dash";
-
- doTest( "-", org, app );
+ doTest("-");
}
+ /**
+ * Ensure that "'" characters in email addresses are handled properly
+ *
+ * @throws Exception
+ */
+ @Test
+ @Ignore //This fails. I'm not sure if it is by design, but a single quote is valid in an email address
+ public void getTokenQuote() throws Exception {
+ doTest("'");
+ }
- private void doTest( String symbol, String org, String app ) throws IOException {
-
+ /**
+ * Given an organization name and an arbitrary character or string,
+ * ensure that an organization and admin user can be created when
+ * the given string is a part of the admin email address
+ *
+ * @param symbol
+ * @throws IOException
+ */
+ private void doTest(String symbol) throws UniformInterfaceException {
+
+ String unique = UUID.randomUUID().toString();
+ String org = "org_getTokenDash" + unique;
+ String app = "app_getTokenDash" + unique;
org = org.toLowerCase();
app = app.toLowerCase();
- String email = String.format( "admin%sname@adminemailencodingtest.org", symbol );
- String user = email;
- String password = "password";
-
- TestAdminUser adminUser = new TestAdminUser( user, password, email );
-
- context.withApp( app ).withOrg( org ).withUser( adminUser );
-
- // create the org and app
- context.createNewOrgAndUser();
-
- // no need for refresh here as Service module does an index refresh when org/app created
-
- // now log in via a GET
-
- String getToken = context.management().tokenGet( email, password );
-
- assertNotNull( getToken );
-
- String postToken = context.management().tokenPost( email, password );
-
- assertNotNull( postToken );
-
- // not log in with our admin
- context.withUser( adminUser ).loginUser();
+ //Username and password
+ String username = "testuser" + unique;
+ String password = "password" + unique;
+ //create an email address containing 'symbol'
+ String email = String.format("test%suser%s@usergrid.com", symbol, unique);
- //now get the "me" and ensure it's correct
+ //create the organization entity
+ Organization orgPayload = new Organization(org, username, email, username, password, null);
- JsonNode data = context.management().me().get();
+ //post the organization entity
+ Organization organization = clientSetup.getRestClient().management().orgs().post(orgPayload);
+ assertNotNull(organization);
- assertNotNull( data.get( "access_token" ).asText() );
+ //Retrieve an authorization token using the credentials created above
+ Token tokenReturned = clientSetup.getRestClient().management().token().post(new Token("password", username, password));
+ assertNotNull(tokenReturned);
- data = context.management().users().user( email ).get();
+ //Instruct the test framework to use the new token
+ this.app().token().setToken(tokenReturned);
+ //Create an application within the organization
+ clientSetup.getRestClient().management().orgs().organization(organization.getName()).app().post(new Application(app));
- JsonNode admin = data.get( "data" ).get( "organizations" ).get( org ).get( "users" ).get( email );
+ //retrieve the new management user by username and ensure the email address matches the input
+ Entity me = clientSetup.getRestClient().management().users().entity(username).get();
+ assertEquals(email, me.get("email"));
- assertNotNull( admin );
+ //retrieve the new management user by email and ensure the email address matches the input
+ me = clientSetup.getRestClient().management().users().entity(email).get();
+ assertEquals(email, me.get("email"));
- assertEquals( email, admin.get( "email" ).asText() );
- assertEquals( user, admin.get( "username" ).asText() );
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3ad37356/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResource.java
index 0443695..0ab260c 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResource.java
@@ -41,4 +41,9 @@ public class ManagementResource extends NamedResource {
public UsersResource users() {
return new UsersResource( context, this );
}
-}
\ No newline at end of file
+
+ public EntityEndpoint get(final String identifier){
+ return new EntityEndpoint(identifier, context, this);
+ }
+
+}