You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by ro...@apache.org on 2015/03/03 02:26:04 UTC
[2/9] incubator-usergrid git commit: Adding some test outlines for
admin users tests. Also added in a password and a non working call in the
before that shows we can't get the super user.
Adding some test outlines for admin users tests. Also added in a password and a non working call in the before that shows we can't get the super user.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/17c439b2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/17c439b2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/17c439b2
Branch: refs/heads/two-dot-o
Commit: 17c439b21bec1efc77ef0635a7ac135dad78990d
Parents: 0f893ff
Author: grey <gr...@apigee.com>
Authored: Fri Jan 9 13:35:47 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Fri Jan 9 13:35:47 2015 -0800
----------------------------------------------------------------------
.../usergrid/rest/management/AdminUsersIT.java | 113 +++++++++++--------
.../rest/test/resource2point0/ClientSetup.java | 7 +-
2 files changed, 75 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/17c439b2/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 271c013..1db0aa3 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
@@ -54,6 +54,8 @@ 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.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;
@@ -61,6 +63,7 @@ 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;
@@ -92,67 +95,89 @@ public class AdminUsersIT extends AbstractRestIT {
}
/**
- * Test if we can reset our password as an admin
+ * Test if we can reset an admin's password by using that same admins credentials.
*/
- @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 setSelfAdminPasswordAsAdmin() throws IOException {
+//
+// String username = clientSetup.getUsername();
+// String password = clientSetup.getPassword();
+//
+//
+// Map<String, String> passwordPayload = new HashMap<String, String>();
+// passwordPayload.put( "newpassword", "testPassword" );
+// passwordPayload.put( "oldpassword", password );
+//
+// // 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, passwordPayload ));
//
+//
+//
+// this.refreshIndex();
+//
+//
+// assertNull( getError( node ) );
+//
+// //Get the token using the new password
+// Token tokenPayload = this.app().token().post(new Token(username, "testPassword"));
+//
+// //Check that we cannot get the token using the old password
+// try {
+// this.app().token().post( new Token( username, password ) );
+// fail( "We shouldn't be able to get a token using the old password" );
+// }catch(UniformInterfaceException uie) {
+// errorParse( 500,"BadPeople",uie );
+// }
+// }
+//
+//
+// /**
+// * Check that we cannot change the password by using an older password
+// */
// @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 );
+// String username = clientSetup.getUsername();
+// String password = clientSetup.getPassword();
//
-// ClientResponse.Status responseStatus = null;
//
+// Map<String, String> passwordPayload = new HashMap<String, String>();
+// passwordPayload.put( "newpassword", "testPassword" );
+// passwordPayload.put( "oldpassword", password );
+//
+// // 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, passwordPayload ));
+//
+//
+//
+// this.refreshIndex();
+//
+//
+// //Get the token using the new password
+// Token tokenPayload = this.app().token().post(new Token(username, "testPassword"));
+//
+//
+// // Check that we can't change the password using the old password.
// try {
// resource().path( "/management/users/test/password" ).accept( MediaType.APPLICATION_JSON )
-// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, data );
+// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, passwordPayload );
+// fail("We shouldn't be able to change the password with the same payload");
// }
// catch ( UniformInterfaceException uie ) {
-// responseStatus = uie.getResponse().getClientResponseStatus();
+// errorParse( ClientResponse.Status.BAD_REQUEST.getStatusCode(),ClientResponse.Status.BAD_REQUEST.getReasonPhrase(),uie );
// }
//
-// assertNotNull( responseStatus );
-//
-// assertEquals( ClientResponse.Status.BAD_REQUEST, responseStatus );
// }
//
//
+// /**
+// * Checks that as a superuser (i.e with a superuser token ) we can change the password of a admin.
+// * @throws IOException
+// */
// @Test
// public void setAdminPasswordAsSysAdmin() throws IOException {
//
@@ -794,6 +819,6 @@ public class AdminUsersIT extends AbstractRestIT {
// }
// catch ( Exception ex ) {
// }
- }
+// }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/17c439b2/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
index b644030..1ec767f 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
@@ -41,7 +41,7 @@ import javax.ws.rs.core.MediaType;
public class ClientSetup implements TestRule {
RestClient restClient;
- protected String username, orgName, appName;
+ protected String username, password,orgName, appName;
protected Organization organization;
protected Application application;
@@ -82,7 +82,10 @@ public class ClientSetup implements TestRule {
String methodName = description.getMethodName();
String name = testClass + "." + methodName;
+ Token test = restClient.management().token().post( new Token("superuser","superpassword") );
+
username = "user_"+name + UUIDUtils.newTimeUUID();
+ password = username;
orgName = "org_"+name+UUIDUtils.newTimeUUID();
appName = "app_"+name+UUIDUtils.newTimeUUID();
@@ -96,6 +99,8 @@ public class ClientSetup implements TestRule {
public String getUsername(){return username;}
+ public String getPassword(){return password;}
+
public Organization getOrganization(){return organization;}
public String getOrganizationName(){return orgName;}