Return-Path: X-Original-To: apmail-usergrid-commits-archive@minotaur.apache.org Delivered-To: apmail-usergrid-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7974217836 for ; Tue, 3 Mar 2015 01:26:04 +0000 (UTC) Received: (qmail 413 invoked by uid 500); 3 Mar 2015 01:26:04 -0000 Delivered-To: apmail-usergrid-commits-archive@usergrid.apache.org Received: (qmail 349 invoked by uid 500); 3 Mar 2015 01:26:04 -0000 Mailing-List: contact commits-help@usergrid.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@usergrid.incubator.apache.org Delivered-To: mailing list commits@usergrid.incubator.apache.org Received: (qmail 264 invoked by uid 99); 3 Mar 2015 01:26:04 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Mar 2015 01:26:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EFD86E0FCB; Tue, 3 Mar 2015 01:26:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rockerston@apache.org To: commits@usergrid.apache.org Date: Tue, 03 Mar 2015 01:26:06 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [4/9] incubator-usergrid git commit: Added admin user tests and also added in User and Password Resources to extend the rest test framework. Added additional string to keep track of the superuserToken. Added httpBasicAuthFilter so we can login and setup Added admin user tests and also added in User and Password Resources to extend the rest test framework. Added additional string to keep track of the superuserToken. Added httpBasicAuthFilter so we can login and setup superadmin user. Added superuser properties to the rest test properties. Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/cbbb8bf8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/cbbb8bf8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/cbbb8bf8 Branch: refs/heads/two-dot-o Commit: cbbb8bf8f824b1ab86bdf76eb5c164e9545aa109 Parents: 21cdfe1 Author: grey Authored: Mon Jan 12 16:58:35 2015 -0800 Committer: grey Committed: Mon Jan 12 16:58:35 2015 -0800 ---------------------------------------------------------------------- .../usergrid/rest/management/AdminUsersIT.java | 145 +++++++++---------- .../rest/test/resource2point0/ClientSetup.java | 6 +- .../rest/test/resource2point0/RestClient.java | 11 ++ .../endpoints/mgmt/PasswordResource.java | 50 +++++++ .../endpoints/mgmt/UserResource.java | 39 +++++ .../endpoints/mgmt/UsersResource.java | 5 + .../resources/usergrid-custom-test.properties | 10 +- 7 files changed, 189 insertions(+), 77 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbbb8bf8/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 1db0aa3..e576a6d 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,7 @@ 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.Entity; 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; @@ -97,81 +98,79 @@ public class AdminUsersIT extends AbstractRestIT { /** * Test if we can reset an admin's password by using that same admins credentials. */ -// @Test -// public void setSelfAdminPasswordAsAdmin() throws IOException { -// -// String username = clientSetup.getUsername(); -// String password = clientSetup.getPassword(); -// -// -// Map passwordPayload = new HashMap(); -// 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 username = clientSetup.getUsername(); -// String password = clientSetup.getPassword(); -// -// -// Map passwordPayload = new HashMap(); -// passwordPayload.put( "newpassword", "testPassword" ); -// passwordPayload.put( "oldpassword", password ); -// -// // change the password as admin. The old password isn't required + @Test + public void setSelfAdminPasswordAsAdmin() throws IOException { + + String username = clientSetup.getUsername(); + String password = clientSetup.getPassword(); + + + Map passwordPayload = new HashMap(); + passwordPayload.put( "newpassword", "testPassword" ); + passwordPayload.put( "oldpassword", password ); + + // change the password as admin. The old password isn't required + management.users().user( username ).password().post(passwordPayload); //entity( username ).password().post; + + this.refreshIndex(); + + + //assertNull( getError( node ) ); + + //Get the token using the new password + management.token().post( new Token( username, "testPassword" ) ); + //this.app().token().post(new Token(username, "testPassword")); + + //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 ); + } + } + + + /** + * Check that we cannot change the password by using an older password + */ + @Test + public void passwordMismatchErrorAdmin() { + + + + String username = clientSetup.getUsername(); + String password = clientSetup.getPassword(); + + + Map passwordPayload = new HashMap(); + passwordPayload.put( "newpassword", "testPassword" ); + passwordPayload.put( "oldpassword", password ); + + // change the password as admin. The old password isn't required + management.users().user( username ).password().post( passwordPayload ); // 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, passwordPayload ); -// fail("We shouldn't be able to change the password with the same payload"); -// } -// catch ( UniformInterfaceException uie ) { -// errorParse( ClientResponse.Status.BAD_REQUEST.getStatusCode(),ClientResponse.Status.BAD_REQUEST.getReasonPhrase(),uie ); -// } -// -// } + + + + this.refreshIndex(); + + + //Get the token using the new password + management.token().post( new Token( username, "testPassword" ) ); + + + // Check that we can't change the password using the old password. + try { + management.users().user( username ).password().post( passwordPayload ); + fail("We shouldn't be able to change the password with the same payload"); + } + catch ( UniformInterfaceException uie ) { + errorParse( ClientResponse.Status.BAD_REQUEST.getStatusCode(),"auth_invalid_username_or_password",uie ); + } + + } // // // /** http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbbb8bf8/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 91dbb16..45c9976 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,7 @@ public class ClientSetup implements TestRule { RestClient restClient; - protected String username, password,orgName, appName; + protected String username, password,orgName, appName, superuserToken; protected Organization organization; protected Application application; @@ -83,7 +83,9 @@ public class ClientSetup implements TestRule { String methodName = description.getMethodName(); String name = testClass + "." + methodName; - Token test = restClient.management().token().post( new Token("superuser","superpassword") ); + restClient.superuserSetup(); + Token superuserResponse = restClient.management().token().post( new Token("superuser","superpassword") ); + superuserToken=superuserResponse.getAccessToken(); username = "user_"+name + UUIDUtils.newTimeUUID(); password = username; http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbbb8bf8/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java index ebd1e35..9349ae6 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java @@ -22,10 +22,12 @@ import org.apache.usergrid.rest.test.resource2point0.endpoints.OrganizationResou import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource; import org.apache.usergrid.rest.test.resource2point0.state.ClientContext; +import com.fasterxml.jackson.databind.JsonNode; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.config.ClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; import javax.ws.rs.core.MediaType; @@ -99,6 +101,15 @@ public class RestClient implements UrlResource { .accept( MediaType.APPLICATION_JSON ).post(); } + public void superuserSetup() { + //TODO: change this when we upgrade to new version of jersey + HTTPBasicAuthFilter httpBasicAuthFilter = new HTTPBasicAuthFilter( "superuser","superpassword" ); + client.addFilter( httpBasicAuthFilter ); + + this.getResource().path( "system/superuser/setup" ) + .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON ).get( JsonNode.class ); + } + //todo:fix this method for the client. // public void loginAdminUser( final String username, final String password ) { // //Post isn't implemented yet, but using the method below we should be able to get a superuser password as well. http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbbb8bf8/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 new file mode 100644 index 0000000..779e057 --- /dev/null +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/PasswordResource.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt; + + +import java.util.Map; + +import javax.ws.rs.core.MediaType; + +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.state.ClientContext; + +import com.sun.jersey.api.client.WebResource; + + +/** + * Relations to the following endpoint + * /management/users/"username"/password + * Allows admin users to change their passwords + */ +public class PasswordResource extends NamedResource { + + public PasswordResource( final ClientContext context, final UrlResource parent ) { + super( "password", context, parent ); + } + + public Entity post(Map payload){ + WebResource resource = getResource(true); + + return resource.type( MediaType.APPLICATION_JSON_TYPE ) + .accept( MediaType.APPLICATION_JSON ).post( Entity.class, payload ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbbb8bf8/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java new file mode 100644 index 0000000..c5a823e --- /dev/null +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UserResource.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt; + +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.state.ClientContext; + + +/** + * Relations to the following endpoint + * /management/users/"username" + * Store endpoints relating to specific users + */ +public class UserResource extends NamedResource { + + public UserResource( final String name, final ClientContext context, final UrlResource parent ) { + super( name, context, parent ); + } + + public PasswordResource password() { + return new PasswordResource( context, this ); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbbb8bf8/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UsersResource.java ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UsersResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UsersResource.java index df3f3c1..7a9e5dd 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UsersResource.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/UsersResource.java @@ -50,6 +50,11 @@ public class UsersResource extends NamedResource { return new EntityEndpoint(identifier, context, this); } + public UserResource user(String identifier) { + return new UserResource( identifier, context, this ); + } + + public Entity post(Entity userPayload){ WebResource resource = getResource(true); //TODO: need to parse the specific response gotten for admin entities. It is different from regular entities. http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cbbb8bf8/stack/rest/src/test/resources/usergrid-custom-test.properties ---------------------------------------------------------------------- diff --git a/stack/rest/src/test/resources/usergrid-custom-test.properties b/stack/rest/src/test/resources/usergrid-custom-test.properties index d9688c4..58cb831 100644 --- a/stack/rest/src/test/resources/usergrid-custom-test.properties +++ b/stack/rest/src/test/resources/usergrid-custom-test.properties @@ -12,8 +12,8 @@ # REST module test properties -# these settings allow tests to run and consistently pass on 16GB MacBook Pro -# with ug.heapmax=5000m and ug.heapmin=3000m (set in Maven settings.xml) +# these settings allow tests to run and consistently pass on 16GB MacBook Pro +# with ug.heapmax=5000m and ug.heapmin=3000m (set in Maven settings.xml) tomcat.startup=embedded tomcat.threads=200 @@ -38,3 +38,9 @@ usergrid.counter.batch.size=1 swagger.basepath=http://sometestvalue usergrid.notifications.listener.run=false + +usergrid.sysadmin.login.name=superuser +usergrid.sysadmin.login.email=superuser@usergrid.com +usergrid.sysadmin.login.password=superpassword +usergrid.sysadmin.login.allowed=true +