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:09 UTC
[7/9] incubator-usergrid git commit: Fixed another test that uses the
superuser token,
and added a different endpoint to facilitate using the superuser token or the
default endpoint.
Fixed another test that uses the superuser token, and added a different endpoint to facilitate using the superuser token or the default endpoint.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/ff7b1a4a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/ff7b1a4a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/ff7b1a4a
Branch: refs/heads/two-dot-o
Commit: ff7b1a4a4e244310152ba698334a6e568b351e9d
Parents: 760a09c
Author: grey <gr...@apigee.com>
Authored: Tue Feb 3 15:56:08 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Tue Feb 3 15:56:08 2015 -0800
----------------------------------------------------------------------
.../usergrid/rest/management/AdminUsersIT.java | 34 ++++++++------------
.../rest/test/resource2point0/ClientSetup.java | 14 ++++++--
.../endpoints/mgmt/PasswordResource.java | 17 ++++++++--
3 files changed, 38 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ff7b1a4a/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 d9a250d..c5ca4d5 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
@@ -177,39 +177,31 @@ public class AdminUsersIT extends AbstractRestIT {
String username = clientSetup.getUsername();
String password = clientSetup.getPassword();
- String superToken = superAdminToken();
-
- String newPassword = "foo";
Map<String, Object> passwordPayload = new HashMap<String, Object>();
- data.put( "newpassword", newPassword );
+ passwordPayload.put( "newpassword", "testPassword" );
// change the password as admin. The old password isn't required
- management.users().user( username ).password().post( passwordPayload );
+ //management.users().user( username ).password().
+ management.users().user( username ).password().post( clientSetup.getSuperuserToken(), passwordPayload );
+
+ this.refreshIndex();
// 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();
-
- // log in with the new password
- String token = mgmtToken( "test", newPassword );
-
- assertNotNull( token );
-
- data.put( "newpassword", "test" );
+ assertNotNull( management.token().post( new Token( username, "testPassword" ) ) );
- // 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 ) );
+ //Check that we cannot get the token using the old password
+ try {
+ management.token().post( new Token( username, password ) );
+ fail( "We shouldn't be able to get a token using the old password" );
+ }catch(UniformInterfaceException uie) {
+ errorParse( 400,"invalid_grant",uie );
+ }
}
//
// @Test
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ff7b1a4a/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 45c9976..819cd85 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
@@ -42,7 +42,12 @@ public class ClientSetup implements TestRule {
RestClient restClient;
- protected String username, password,orgName, appName, superuserToken;
+ protected String username;
+ protected String password;
+ protected String orgName;
+ protected String appName;
+ protected Token superuserToken;
+
protected Organization organization;
protected Application application;
@@ -84,8 +89,7 @@ public class ClientSetup implements TestRule {
String name = testClass + "." + methodName;
restClient.superuserSetup();
- Token superuserResponse = restClient.management().token().post( new Token("superuser","superpassword") );
- superuserToken=superuserResponse.getAccessToken();
+ superuserToken = restClient.management().token().post( new Token( "superuser", "superpassword" ) );
username = "user_"+name + UUIDUtils.newTimeUUID();
password = username;
@@ -110,6 +114,10 @@ public class ClientSetup implements TestRule {
public String getAppName() {return appName;}
+ public Token getSuperuserToken() {
+ return superuserToken;
+ }
+
public void refreshIndex() {
this.restClient.refreshIndex(getOrganizationName(),getAppName());
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ff7b1a4a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.java
index 779e057..c901022 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.java
@@ -25,6 +25,7 @@ import org.apache.usergrid.rest.test.resource2point0.endpoints.NamedResource;
import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
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.Token;
import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
import com.sun.jersey.api.client.WebResource;
@@ -41,10 +42,20 @@ public class PasswordResource extends NamedResource {
super( "password", context, parent );
}
- public Entity post(Map<String, Object> payload){
- WebResource resource = getResource(true);
+ public Entity post(Token token, Map<String,Object> payload){
+ WebResource resource;
+
+ if(token != null) {
+ resource = getResource( true, token );
+ }
+ else
+ resource = getResource( true );
return resource.type( MediaType.APPLICATION_JSON_TYPE )
- .accept( MediaType.APPLICATION_JSON ).post( Entity.class, payload );
+ .accept( MediaType.APPLICATION_JSON ).post( Entity.class, payload );
+ }
+
+ public Entity post(Map<String, Object> payload){
+ return post( null, payload );
}
}