You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by gr...@apache.org on 2015/02/28 02:05:31 UTC
[1/7] incubator-usergrid git commit: Added testProperties RTF files.
Repository: incubator-usergrid
Updated Branches:
refs/heads/USERGRID-280 06d156084 -> 8585558f3
Added testProperties RTF files.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/635b1836
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/635b1836
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/635b1836
Branch: refs/heads/USERGRID-280
Commit: 635b183618899efcb246093afc4ac1698739e264
Parents: 06d1560
Author: grey <gr...@apigee.com>
Authored: Thu Feb 26 14:19:45 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Thu Feb 26 14:19:45 2015 -0800
----------------------------------------------------------------------
.../rest/test/resource2point0/RestClient.java | 4 +-
.../resource2point0/TestPropertiesResource.java | 47 ++++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/635b1836/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 9349ae6..f697509 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
@@ -74,7 +74,9 @@ public class RestClient implements UrlResource {
return context;
}
-
+ public TestPropertiesResource testPropertiesResource() {
+ return new TestPropertiesResource( context, this );
+ }
/**
* Get the management resource
*/
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/635b1836/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/TestPropertiesResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/TestPropertiesResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/TestPropertiesResource.java
new file mode 100644
index 0000000..2650c29
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/TestPropertiesResource.java
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+
+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;
+
+
+/**
+ *Adds support for changing the management properties in the rest testing framework.
+ */
+public class TestPropertiesResource extends NamedResource {
+ public TestPropertiesResource( final ClientContext context, final UrlResource parent ) {
+ super( "testproperties", context, parent );
+ }
+
+ public ApiResponse post(Entity testProperties){
+
+ return getResource(true).type( MediaType.APPLICATION_JSON_TYPE )
+ .accept( MediaType.APPLICATION_JSON ).post( ApiResponse.class, testProperties );
+ }
+
+ public ApiResponse get(){
+ return getResource(true).type( MediaType.APPLICATION_JSON_TYPE )
+ .accept( MediaType.APPLICATION_JSON ).get(ApiResponse.class );
+ }
+}
[3/7] incubator-usergrid git commit: Added fix for
unconfirmedAdminUsersTest
Posted by gr...@apache.org.
Added fix for unconfirmedAdminUsersTest
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/88fe9063
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/88fe9063
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/88fe9063
Branch: refs/heads/USERGRID-280
Commit: 88fe906353655252f7788d79ce1d72315626b4c6
Parents: 454cf61
Author: grey <gr...@apigee.com>
Authored: Fri Feb 27 11:43:22 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Fri Feb 27 11:43:22 2015 -0800
----------------------------------------------------------------------
.../usergrid/rest/management/AdminUsersIT.java | 219 ++++++-------------
.../endpoints/mgmt/ConfirmResource.java | 46 ++++
.../endpoints/mgmt/UserResource.java | 4 +
3 files changed, 121 insertions(+), 148 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/88fe9063/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 ac3cc10..d2c86a9 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
@@ -41,6 +41,7 @@ import org.jvnet.mock_javamail.Mailbox;
import org.apache.usergrid.management.MockImapClient;
+import org.apache.usergrid.persistence.index.utils.StringUtils;
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.*;
@@ -205,176 +206,98 @@ public class AdminUsersIT extends AbstractRestIT {
}
+
+ /**
+ * Test that a unconfirmed admin cannot log in.
+ * TODO:test for parallel test that changing the properties here won't affect other tests
+ * @throws Exception
+ */
@Test
- public void testUnconfirmedAdminLoginRET() throws Exception{
+ public void testUnconfirmedAdminLogin() throws Exception{
- Map<String,Object> testPropertiesMap = new HashMap<>( );
+ ApiResponse originalTestPropertiesResponse = clientSetup.getRestClient().testPropertiesResource().get();
+ Entity originalTestProperties = new Entity( originalTestPropertiesResponse );
+ try {
+ //Set runtime enviroment to the following settings
+ 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" );
+ testPropertiesMap.put( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
+ testPropertiesMap.put( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
+ //Requires admins to do email confirmation before they can log in.
+ testPropertiesMap.put( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" );
+ testPropertiesMap.put( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
- Entity testPropertiesPayload = new Entity( testPropertiesMap );
+ Entity testPropertiesPayload = new Entity( testPropertiesMap );
- clientSetup.getRestClient().testPropertiesResource().post(testPropertiesPayload);
+ //Send rest call to the /testProperties endpoint to persist property changes
+ clientSetup.getRestClient().testPropertiesResource().post( testPropertiesPayload );
- refreshIndex();
+ refreshIndex();
- ApiResponse apiResponse = clientSetup.getRestClient().testPropertiesResource().get();
+ //Retrieve properties and ensure that they are set correctly.
+ ApiResponse apiResponse = clientSetup.getRestClient().testPropertiesResource().get();
- 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 ) );
+ 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 );
+ //Create organization for the admin user to be confirmed
+ Organization organization = createOrgPayload( "testUnconfirmedAdminLogin", null );
- Organization organizationResponse = clientSetup.getRestClient().management().orgs().post( organization );
+ Organization organizationResponse = clientSetup.getRestClient().management().orgs().post( organization );
- assertNotNull( organizationResponse );
+ assertNotNull( organizationResponse );
- User adminUser = organizationResponse.getOwner();
+ //Ensure that adminUser has the correct properties set.
+ User adminUser = organizationResponse.getOwner();
- assertNotNull( adminUser );
- assertFalse( "adminUser should not be activated yet", adminUser.getActivated());
- assertFalse( "adminUser should not be confirmed yet", adminUser.getConfirmed());
+ assertNotNull( adminUser );
+ assertFalse( "adminUser should not be activated yet", adminUser.getActivated() );
+ assertFalse( "adminUser should not be confirmed yet", adminUser.getConfirmed() );
- QueryParameters queryParameters = new QueryParameters();
- queryParameters.addParam( "grant_type","password").addParam( "username",adminUser.getUsername() )
- .addParam( "password",organization.getPassword() );
+ 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() );
+ //Check that the adminUser cannot log in and fails with a 403
+ try {
+ management().token().get( queryParameters );
+ fail( "Admin user should not be able to log in." );
+ }
+ catch ( UniformInterfaceException uie ) {
+ assertEquals( "Admin user should have failed with 403", 403, uie.getResponse().getStatus() );
+ }
- try {
+ //Create mocked inbox
+ List<Message> inbox = Mailbox.get( organization.getEmail() );
+ assertFalse( inbox.isEmpty() );
- Token tokenReturned = management().token().get( queryParameters );
- }
- catch(Exception e){
- //catch forbbiedn here
- }
+ MockImapClient client = new MockImapClient( "mockserver.com", "test-user-46", "somepassword" );
+ client.processMail();
- List<Message> inbox = Mailbox.get( organization.getEmail() );
- assertFalse( inbox.isEmpty() );
+ //Get email with confirmation token and extract token
+ Message confirmation = inbox.get( 0 );
+ assertEquals( "User Account Confirmation: " + organization.getEmail(), confirmation.getSubject() );
+ String token = getTokenFromMessage( confirmation );
- MockImapClient client = new MockImapClient( "mockserver.com", "test-user-46", "somepassword" );
- client.processMail();
+ //Make rest call with extracted token to confirm the admin user.
+ management().users().user( adminUser.getUuid().toString() ).confirm()
+ .get( new QueryParameters().addParam( "token", token ) );
- Message confirmation = inbox.get( 0 );
- assertEquals( "User Account Confirmation: " + organization.getEmail(), confirmation.getSubject() );
- //String token = getTokenFromMessage(confirmation);
+ //Try the previous call and verify that the admin user can retrieve login token
+ Token retToken = management().token().get( queryParameters );
+ assertNotNull( retToken );
+ assertNotNull( retToken.getAccessToken() );
+ }finally {
+ clientSetup.getRestClient().testPropertiesResource().post( originalTestProperties );
+ }
}
-
-// @Test
-// public void testUnconfirmedAdminLogin() throws Exception {
-//
-// // Setup properties to require confirmation of users
-// // -------------------------------------------
-//
-// Map<String, String> originalProperties = getRemoteTestProperties();
-//
-// try {
-// setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
-// setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
-// setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" );
-// setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
-// setTestProperty( PROPERTIES_NOTIFY_ADMIN_OF_ACTIVATION, "true" );
-//
-// assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() );
-// assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() );
-//
-// // Setup org/app/user variables and create them
-// // -------------------------------------------
-// String orgName = this.getClass().getName();
-// String appName = "testUnconfirmedAdminLogin";
-// String userName = "TestUser";
-// String email = "test-user-46@mockserver.com";
-// String passwd = "testpassword";
-// OrganizationOwnerInfo orgOwner;
-//
-// orgOwner = setup.getMgmtSvc().createOwnerAndOrganization(
-// orgName, userName, appName, email, passwd, false, false );
-// assertNotNull( orgOwner );
-// String returnedUsername = orgOwner.getOwner().getUsername();
-// assertEquals( userName, returnedUsername );
-//
-// UserInfo adminUserInfo = setup.getMgmtSvc().getAdminUserByUsername( userName );
-// assertNotNull( adminUserInfo );
-// assertFalse( "adminUser should not be activated yet", adminUserInfo.isActivated() );
-// assertFalse( "adminUser should not be confirmed yet", adminUserInfo.isConfirmed() );
-//
-// // Attempt to authenticate but this should fail
-// // -------------------------------------------
-// JsonNode node;
-// try {
-// node = mapper.readTree( resource().path( "/management/token" )
-// .queryParam( "grant_type", "password" )
-// .queryParam( "username", userName )
-// .queryParam( "password", passwd )
-// .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-//
-// fail( "Unconfirmed users should not be authorized to authenticate." );
-// }
-// catch ( UniformInterfaceException e ) {
-// node = mapper.readTree( e.getResponse().getEntity( String.class ));
-// assertEquals( "invalid_grant", node.get( "error" ).textValue() );
-// assertEquals( "User must be confirmed to authenticate",
-// node.get( "error_description" ).textValue() );
-// LOG.info( "Unconfirmed user was not authorized to authenticate!" );
-// }
-//
-// // Confirm the getting account confirmation email for unconfirmed user
-// // -------------------------------------------
-// List<Message> inbox = Mailbox.get( email );
-// assertFalse( inbox.isEmpty() );
-//
-// MockImapClient client = new MockImapClient( "mockserver.com", "test-user-46", "somepassword" );
-// client.processMail();
-//
-// Message confirmation = inbox.get( 0 );
-// assertEquals( "User Account Confirmation: " + email, confirmation.getSubject() );
-//
-// // Extract the token to confirm the user
-// // -------------------------------------------
-// String token = getTokenFromMessage( confirmation );
-// LOG.info( token );
-//
-// ActivationState state = setup.getMgmtSvc().handleConfirmationTokenForAdminUser(
-// orgOwner.getOwner().getUuid(), token );
-// assertEquals( ActivationState.ACTIVATED, state );
-//
-// Message activation = inbox.get( 1 );
-// assertEquals( "User Account Activated", activation.getSubject() );
-//
-// client = new MockImapClient( "mockserver.com", "test-user-46", "somepassword" );
-// client.processMail();
-//
-// refreshIndex(orgName, appName);
-//
-// // Attempt to authenticate again but this time should pass
-// // -------------------------------------------
-//
-// node = mapper.readTree( resource().path( "/management/token" )
-// .queryParam( "grant_type", "password" )
-// .queryParam( "username", userName )
-// .queryParam( "password", passwd )
-// .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-//
-// assertNotNull( node );
-// LOG.info( "Authentication succeeded after confirmation: {}.", node.toString() );
-// }
-// finally {
-// setTestProperties( originalProperties );
-// }
-// }
-
//
// @Test
// public void testSystemAdminNeedsNoConfirmation() throws Exception {
@@ -452,10 +375,10 @@ public class AdminUsersIT extends AbstractRestIT {
// }
//
//
-// private String getTokenFromMessage( Message msg ) throws IOException, MessagingException {
-// String body = ( ( MimeMultipart ) msg.getContent() ).getBodyPart( 0 ).getContent().toString();
-// return StringUtils.substringAfterLast( body, "token=" );
-// }
+ private String getTokenFromMessage( Message msg ) throws IOException, MessagingException {
+ String body = ( ( MimeMultipart ) msg.getContent() ).getBodyPart( 0 ).getContent().toString();
+ return StringUtils.substringAfterLast( body, "token=" );
+ }
//
//
// @Test
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/88fe9063/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ConfirmResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ConfirmResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ConfirmResource.java
new file mode 100644
index 0000000..5692dfe
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ConfirmResource.java
@@ -0,0 +1,46 @@
+/*
+ * 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 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.QueryParameters;
+import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
+
+import com.sun.jersey.api.client.WebResource;
+
+
+/**
+ * For confirming users
+ */
+public class ConfirmResource extends NamedResource {
+ public ConfirmResource( final ClientContext context, final UrlResource parent ) {
+ super( "confirm", context, parent );
+ }
+
+ public void get(QueryParameters queryParameters){
+ WebResource resource = getResource();
+ resource = addParametersToResource( resource, queryParameters );
+ String obj = resource.type( MediaType.TEXT_HTML_TYPE )
+ .accept( MediaType.TEXT_HTML).get( String.class );
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/88fe9063/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
index 1adcd83..da22594 100644
--- 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
@@ -38,6 +38,10 @@ public class UserResource extends NamedResource {
super( name, context, parent );
}
+ public ConfirmResource confirm() {
+ return new ConfirmResource(context,this);
+ }
+
public PasswordResource password() {
return new PasswordResource( context, this );
}
[6/7] incubator-usergrid git commit: [USERGRID-280]Added a management
user put endpoint to the rest test framework. Created new ticket and added a
test for that ticket .
Posted by gr...@apache.org.
[USERGRID-280]Added a management user put endpoint to the rest test framework.
Created new ticket and added a test for that ticket .
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/e5bd3433
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/e5bd3433
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/e5bd3433
Branch: refs/heads/USERGRID-280
Commit: e5bd3433e368c29b8894a586e27319f81509721f
Parents: a43954d
Author: grey <gr...@apigee.com>
Authored: Fri Feb 27 14:29:59 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Fri Feb 27 14:29:59 2015 -0800
----------------------------------------------------------------------
.../usergrid/rest/management/AdminUsersIT.java | 163 +++++--------------
.../endpoints/mgmt/UserResource.java | 8 +
2 files changed, 52 insertions(+), 119 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e5bd3433/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 2aaf9de..74c5297 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
@@ -40,8 +40,11 @@ import org.junit.Test;
import org.jvnet.mock_javamail.Mailbox;
+import org.apache.commons.collections4.map.LinkedMap;
+
import org.apache.usergrid.management.MockImapClient;
import org.apache.usergrid.persistence.index.utils.StringUtils;
+import org.apache.usergrid.persistence.index.utils.UUIDUtils;
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.*;
@@ -378,125 +381,47 @@ public class AdminUsersIT extends AbstractRestIT {
String body = ( ( MimeMultipart ) msg.getContent() ).getBodyPart( 0 ).getContent().toString();
return StringUtils.substringAfterLast( body, "token=" );
}
-//
-//
-// @Test
-// public void updateManagementUser() throws Exception {
-// Map<String, String> payload =
-// hashMap( "email", "uort-user-1@apigee.com" ).map( "username", "uort-user-1" ).map( "name", "Test User" )
-// .map( "password", "password" ).map( "organization", "uort-org" ).map( "company", "Apigee" );
-//
-// JsonNode node = mapper.readTree( resource().path( "/management/organizations" ).accept( MediaType.APPLICATION_JSON )
-// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, payload ));
-// logNode( node );
-// String userId = node.get( "data" ).get( "owner" ).get( "uuid" ).asText();
-//
-// assertEquals( "Apigee", node.get( "data" ).get( "owner" ).get( "properties" ).get( "company" ).asText() );
-//
-// String token = mgmtToken( "uort-user-1@apigee.com", "password" );
-//
-// node = mapper.readTree( resource().path( String.format( "/management/users/%s", userId ) ).queryParam( "access_token", token )
-// .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
-//
-// logNode( node );
-//
-// payload = hashMap( "company", "Usergrid" );
-// LOG.info( "sending PUT for company update" );
-// node = mapper.readTree( resource().path( String.format( "/management/users/%s", userId ) ).queryParam( "access_token", token )
-// .type( MediaType.APPLICATION_JSON_TYPE ).put( String.class, payload ));
-// assertNotNull( node );
-// node = mapper.readTree( resource().path( String.format( "/management/users/%s", userId ) ).queryParam( "access_token", token )
-// .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
-// assertEquals( "Usergrid", node.get( "data" ).get( "properties" ).get( "company" ).asText() );
-//
-//
-// logNode( node );
-// }
-//
-//
-// @Test
-// public void getUser() throws Exception {
-//
-// // set an organization property
-// HashMap<String, Object> payload = new HashMap<String, Object>();
-// Map<String, Object> properties = new HashMap<String, Object>();
-// properties.put( "securityLevel", 5 );
-// payload.put( OrganizationsResource.ORGANIZATION_PROPERTIES, properties );
-//
-//
-// /**
-// * Get the original org admin before we overwrite the property as a super user
-// */
-// final TestUser orgAdmin = context.getActiveUser();
-// final String orgName = context.getOrgName();
-// final String superAdminToken = superAdminToken();
-//
-// TestAdminUser superAdmin = new TestAdminUser( "super", "super", "superuser@usergrid.com" );
-// superAdmin.setToken( superAdminToken );
-//
-// Organization org = context.withUser( superAdmin ).management().orgs().organization( orgName );
-//
-// org.put( payload );
-//
-//
-// //now get the org
-// JsonNode node = context.withUser( orgAdmin ).management().users().user( orgAdmin.getUser() ).get();
-//
-// logNode( node );
-//
-// JsonNode applications = node.findValue( "applications" );
-// assertNotNull( applications );
-// JsonNode users = node.findValue( "users" );
-// assertNotNull( users );
-//
-// JsonNode securityLevel = node.findValue( "securityLevel" );
-// assertNotNull( securityLevel );
-// assertEquals( 5L, securityLevel.asLong() );
-// }
-//
-//
-// @Test
-// public void getUserShallow() throws Exception {
-//
-//
-// // set an organization property
-// HashMap<String, Object> payload = new HashMap<String, Object>();
-// Map<String, Object> properties = new HashMap<String, Object>();
-// properties.put( "securityLevel", 5 );
-// payload.put( OrganizationsResource.ORGANIZATION_PROPERTIES, properties );
-//
-//
-// /**
-// * Get the original org admin before we overwrite the property as a super user
-// */
-// final TestUser orgAdmin = context.getActiveUser();
-// final String orgName = context.getOrgName();
-// final String superAdminToken = superAdminToken();
-//
-// TestAdminUser superAdmin = new TestAdminUser( "super", "super", "superuser@usergrid.com" );
-// superAdmin.setToken( superAdminToken );
-//
-// Organization org = context.withUser( superAdmin ).management().orgs().organization( orgName );
-//
-// org.put( payload );
-//
-//
-// //now get the org
-// JsonNode node = context.withUser( orgAdmin ).management().users().user( orgAdmin.getUser() ).withParam(
-// "shallow", "true" ).get();
-//
-// logNode( node );
-//
-// JsonNode applications = node.findValue( "applications" );
-// assertNull( applications );
-// JsonNode users = node.findValue( "users" );
-// assertNull( users );
-//
-// JsonNode securityLevel = node.findValue( "securityLevel" );
-// assertNotNull( securityLevel );
-// assertEquals( 5L, securityLevel.asLong() );
-// }
-//
+
+
+ /**
+ * Update the current management user and make sure the change persists
+ * @throws Exception
+ */
+ @Ignore("Fails because we cannot get a single management user without a Admin level token, but"
+ + "we can put without any of those permissions. This test will work once that issue has been resolved.")
+ @Test
+ public void updateManagementUser() throws Exception {
+
+ Organization newOrg = createOrgPayload( "updateManagementUser", null );
+
+
+ Organization orgReturned = clientSetup.getRestClient().management().orgs().post( newOrg );
+
+ assertNotNull( orgReturned.getOwner() );
+
+ //Add a property to management user
+ Entity userProperty = new Entity( ).chainPut( "company","usergrid" );
+ management().users().user( newOrg.getUsername() ).put( userProperty );
+
+ Entity userUpdated = updateAdminUser( userProperty, orgReturned );
+
+ assertEquals( "usergrid",userUpdated.getAsString( "company" ) );
+
+ //Update property with new management value.
+ userProperty = new Entity( ).chainPut( "company","Apigee" );
+
+ userUpdated = updateAdminUser( userProperty, orgReturned);
+
+ assertEquals( "Apigee",userUpdated.getAsString( "company" ) );
+ }
+
+ public Entity updateAdminUser(Entity userProperty, Organization organization){
+ management().users().user( organization.getUsername() ).put( userProperty );
+
+ return management().users().user( organization.getUsername() ).get();
+
+ }
+
//
// @Test
// public void reactivateMultipleSend() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e5bd3433/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
index da22594..b320e6b 100644
--- 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
@@ -56,4 +56,12 @@ public class UserResource extends NamedResource {
.accept( MediaType.APPLICATION_JSON ).get( ApiResponse.class );
return new Entity(response);
}
+
+ public Entity put(Entity userPayload){
+ WebResource resource = getResource(true);
+
+ ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE )
+ .accept( MediaType.APPLICATION_JSON ).put( ApiResponse.class, userPayload);
+ return new Entity(response);
+ }
}
[5/7] incubator-usergrid git commit: [USERGRID-280] Added
testTestUserNeedsNoConfirmation,
this test currently does not pass but due to test account issues
Posted by gr...@apache.org.
[USERGRID-280] Added testTestUserNeedsNoConfirmation, this test currently does not pass but due to test account issues
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/a43954d1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/a43954d1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/a43954d1
Branch: refs/heads/USERGRID-280
Commit: a43954d11f180ca8d2790c91595593957b63e771
Parents: 5bdbc29
Author: grey <gr...@apigee.com>
Authored: Fri Feb 27 12:26:31 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Fri Feb 27 12:26:31 2015 -0800
----------------------------------------------------------------------
.../usergrid/rest/management/AdminUsersIT.java | 83 ++++++++++----------
1 file changed, 42 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a43954d1/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 130a1da..2aaf9de 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
@@ -60,6 +60,8 @@ import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_NOT
import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS;
import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS;
import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_SYSADMIN_EMAIL;
+import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_TEST_ACCOUNT_ADMIN_USER_EMAIL;
+import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_TEST_ACCOUNT_ADMIN_USER_PASSWORD;
import static org.apache.usergrid.utils.MapUtils.hashMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -326,53 +328,52 @@ public class AdminUsersIT extends AbstractRestIT {
Token superuserToken = management().token().post(
new Token( clientSetup.getSuperuserName(), clientSetup.getSuperuserPassword() ) );
+
+
assertNotNull( "We should have gotten a valid token back" ,superuserToken );
}finally{
clientSetup.getRestClient().testPropertiesResource().post( originalTestProperties );
}
}
-
-//
-// @Test
-// public void testTestUserNeedsNoConfirmation() throws Exception {
-//
-// Map<String, String> originalProperties = getRemoteTestProperties();
-//
-// try {
-// // require comfirmation of new admin users
-// setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
-// setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
-// setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" );
-//
-// assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() );
-// assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() );
-//
-// String testUserUsername = ( String ) setup.getMgmtSvc().getProperties()
-// .get( AccountCreationProps
-// .PROPERTIES_TEST_ACCOUNT_ADMIN_USER_EMAIL );
-//
-// String testUserPassword = ( String ) setup.getMgmtSvc().getProperties()
-// .get( AccountCreationProps
-// .PROPERTIES_TEST_ACCOUNT_ADMIN_USER_PASSWORD );
-//
-// // test user login should suceed despite confirmation setting
-// JsonNode node;
-// try {
-// node = mapper.readTree( resource().path( "/management/token" ).queryParam( "grant_type", "password" )
-// .queryParam( "username", testUserUsername ).queryParam( "password", testUserPassword )
-// .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-// }
-// catch ( UniformInterfaceException e ) {
-// fail( "Test User should need no confirmation" );
-// }
-// }
-// finally {
-// setTestProperties( originalProperties );
-// }
-// }
-//
-//
+
+ /**
+ * Test that the test account doesn't need confirmation and is created automatically.
+ * @throws Exception
+ */
+ @Ignore("Test doesn't pass because the test account isn't getting correct instantiated")
+ @Test
+ public void testTestUserNeedsNoConfirmation() throws Exception{
+ //Save original properties to return them to normal at the end of the test
+ ApiResponse originalTestPropertiesResponse = clientSetup.getRestClient().testPropertiesResource().get();
+ Entity originalTestProperties = new Entity( originalTestPropertiesResponse );
+ try {
+ //Set runtime enviroment to the following settings
+ Map<String, Object> testPropertiesMap = new HashMap<>();
+
+ testPropertiesMap.put( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
+ testPropertiesMap.put( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
+ //Requires admins to do email confirmation before they can log in.
+ testPropertiesMap.put( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" );
+
+ Entity testPropertiesPayload = new Entity( testPropertiesMap );
+
+ //Send rest call to the /testProperties endpoint to persist property changes
+ clientSetup.getRestClient().testPropertiesResource().post( testPropertiesPayload );
+ refreshIndex();
+
+ Token testToken = management().token().post(
+ new Token( originalTestProperties.getAsString( PROPERTIES_TEST_ACCOUNT_ADMIN_USER_EMAIL ),
+ originalTestProperties.getAsString( PROPERTIES_TEST_ACCOUNT_ADMIN_USER_PASSWORD ) ));
+
+ assertNotNull( "We should have gotten a valid token back" ,testToken );
+ }finally{
+ clientSetup.getRestClient().testPropertiesResource().post( originalTestProperties );
+
+ }
+ }
+
+
private String getTokenFromMessage( Message msg ) throws IOException, MessagingException {
String body = ( ( MimeMultipart ) msg.getContent() ).getBodyPart( 0 ).getContent().toString();
return StringUtils.substringAfterLast( body, "token=" );
[2/7] incubator-usergrid git commit: Added additional admin
confirmation tests and fixes for the token resource.
Posted by gr...@apache.org.
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/USERGRID-280
Commit: 454cf6195e00763f132e91bff2bf0b76df1e3d01
Parents: 635b183
Author: grey <gr...@apigee.com>
Authored: Thu Feb 26 17:24:21 2015 -0800
Committer: grey <gr...@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;
[4/7] incubator-usergrid git commit: Added testSystemAdmin needs no
confirmation test
Posted by gr...@apache.org.
Added testSystemAdmin needs no confirmation test
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/5bdbc297
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/5bdbc297
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/5bdbc297
Branch: refs/heads/USERGRID-280
Commit: 5bdbc297a0bcc9f7c0bb247dc41b99f240a8ced5
Parents: 88fe906
Author: grey <gr...@apigee.com>
Authored: Fri Feb 27 11:56:09 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Fri Feb 27 11:56:09 2015 -0800
----------------------------------------------------------------------
.../usergrid/rest/management/AdminUsersIT.java | 72 ++++++++++----------
.../rest/test/resource2point0/ClientSetup.java | 13 +++-
2 files changed, 47 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5bdbc297/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 d2c86a9..130a1da 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
@@ -298,43 +298,41 @@ public class AdminUsersIT extends AbstractRestIT {
}
}
-//
-// @Test
-// public void testSystemAdminNeedsNoConfirmation() throws Exception {
-//
-// Map<String, String> originalProperties = getRemoteTestProperties();
-//
-// try {
-// // require comfirmation of new admin users
-// setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
-// setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
-// setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" );
-//
-// assertTrue( setup.getMgmtSvc().newAdminUsersRequireConfirmation() );
-// assertFalse( setup.getMgmtSvc().newAdminUsersNeedSysAdminApproval() );
-//
-// String sysadminUsername = ( String ) setup.getMgmtSvc().getProperties()
-// .get( AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_EMAIL );
-//
-// String sysadminPassword = ( String ) setup.getMgmtSvc().getProperties()
-// .get( AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_PASSWORD );
-//
-// // sysadmin login should suceed despite confirmation setting
-// JsonNode node;
-// try {
-// node = mapper.readTree( resource().path( "/management/token" ).queryParam( "grant_type", "password" )
-// .queryParam( "username", sysadminUsername ).queryParam( "password", sysadminPassword )
-// .accept( MediaType.APPLICATION_JSON ).get( String.class ));
-// }
-// catch ( UniformInterfaceException e ) {
-// fail( "Sysadmin should need no confirmation" );
-// }
-// }
-// finally {
-// setTestProperties( originalProperties );
-// }
-// }
-//
+
+ /**
+ * Test that the system admin doesn't need a confirmation email
+ * @throws Exception
+ */
+ @Test
+ public void testSystemAdminNeedsNoConfirmation() throws Exception{
+ //Save original properties to return them to normal at the end of the test
+ ApiResponse originalTestPropertiesResponse = clientSetup.getRestClient().testPropertiesResource().get();
+ Entity originalTestProperties = new Entity( originalTestPropertiesResponse );
+ try {
+ //Set runtime enviroment to the following settings
+ Map<String, Object> testPropertiesMap = new HashMap<>();
+
+ testPropertiesMap.put( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
+ testPropertiesMap.put( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
+ //Requires admins to do email confirmation before they can log in.
+ testPropertiesMap.put( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true" );
+
+ Entity testPropertiesPayload = new Entity( testPropertiesMap );
+
+ //Send rest call to the /testProperties endpoint to persist property changes
+ clientSetup.getRestClient().testPropertiesResource().post( testPropertiesPayload );
+ refreshIndex();
+
+ Token superuserToken = management().token().post(
+ new Token( clientSetup.getSuperuserName(), clientSetup.getSuperuserPassword() ) );
+
+ assertNotNull( "We should have gotten a valid token back" ,superuserToken );
+ }finally{
+ clientSetup.getRestClient().testPropertiesResource().post( originalTestProperties );
+
+ }
+ }
+
//
// @Test
// public void testTestUserNeedsNoConfirmation() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5bdbc297/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 819cd85..55c10a3 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
@@ -47,6 +47,8 @@ public class ClientSetup implements TestRule {
protected String orgName;
protected String appName;
protected Token superuserToken;
+ protected String superuserName = "superuser";
+ protected String superuserPassword = "superpassword";
protected Organization organization;
protected Application application;
@@ -89,7 +91,7 @@ public class ClientSetup implements TestRule {
String name = testClass + "." + methodName;
restClient.superuserSetup();
- superuserToken = restClient.management().token().post( new Token( "superuser", "superpassword" ) );
+ superuserToken = restClient.management().token().post( new Token( superuserName, superuserPassword ) );
username = "user_"+name + UUIDUtils.newTimeUUID();
password = username;
@@ -118,6 +120,15 @@ public class ClientSetup implements TestRule {
return superuserToken;
}
+ public String getSuperuserName() {
+ return superuserName;
+ }
+
+
+ public String getSuperuserPassword() {
+ return superuserPassword;
+ }
+
public void refreshIndex() {
this.restClient.refreshIndex(getOrganizationName(),getAppName());
}
[7/7] incubator-usergrid git commit: Added reactivate endpoint to
users in rest test framework. Added test to prove that reactivate endpoint
still works.
Posted by gr...@apache.org.
Added reactivate endpoint to users in rest test framework.
Added test to prove that reactivate endpoint still works.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/8585558f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/8585558f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/8585558f
Branch: refs/heads/USERGRID-280
Commit: 8585558f313d040c011d0e79ffb860f0254144ef
Parents: e5bd343
Author: grey <gr...@apigee.com>
Authored: Fri Feb 27 17:05:23 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Fri Feb 27 17:05:23 2015 -0800
----------------------------------------------------------------------
.../usergrid/rest/management/AdminUsersIT.java | 54 ++++++--------------
.../rest/test/resource2point0/ClientSetup.java | 2 +
.../endpoints/mgmt/ReactivateResource.java | 46 +++++++++++++++++
.../endpoints/mgmt/UserResource.java | 5 ++
4 files changed, 69 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8585558f/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 74c5297..c5950f6 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
@@ -421,46 +421,24 @@ public class AdminUsersIT extends AbstractRestIT {
return management().users().user( organization.getUsername() ).get();
}
+
+
+ /**
+ * Check that we send the reactivate email after calling the reactivate endpoint.
+ * @throws Exception
+ */
+ @Test
+ public void reactivateTest() throws Exception {
+ //call reactivate endpoint on default user
+ clientSetup.getRestClient().management().users().user( clientSetup.getUsername() ).reactivate();
+ refreshIndex();
+
+ //Create mocked inbox
+ List<Message> inbox = Mailbox.get( clientSetup.getEmail());
+ assertFalse( inbox.isEmpty() );
+ }
//
-// @Test
-// public void reactivateMultipleSend() throws Exception {
-//
-// JsonNode node = mapper.readTree( resource().path( "/management/organizations" ).accept( MediaType.APPLICATION_JSON )
-// .type( MediaType.APPLICATION_JSON_TYPE ).post( String.class, buildOrgUserPayload( "reactivate" ) ));
-//
-// logNode( node );
-// String email = node.get( "data" ).get( "owner" ).get( "email" ).asText();
-// String uuid = node.get( "data" ).get( "owner" ).get( "uuid" ).asText();
-// assertNotNull( email );
-// assertEquals( "MUUserResourceIT-reactivate@apigee.com", email );
-//
-// refreshIndex(context.getOrgName(), context.getAppName());
-//
-// // reactivate should send activation email
-//
-// node = mapper.readTree( resource().path( String.format( "/management/users/%s/reactivate", uuid ) )
-// .queryParam( "access_token", adminAccessToken ).accept( MediaType.APPLICATION_JSON )
-// .type( MediaType.APPLICATION_JSON_TYPE ).get( String.class ));
-//
-// refreshIndex(context.getOrgName(), context.getAppName());
-//
-// List<Message> inbox = org.jvnet.mock_javamail.Mailbox.get( email );
-//
-// assertFalse( inbox.isEmpty() );
-// logNode( node );
-// }
-//
-//
-// private Map<String, String> buildOrgUserPayload( String caller ) {
-// String className = this.getClass().getSimpleName();
-// Map<String, String> payload = hashMap( "email", String.format( "%s-%s@apigee.com", className, caller ) )
-// .map( "username", String.format( "%s-%s-user", className, caller ) )
-// .map( "name", String.format( "%s %s", className, caller ) ).map( "password", "password" )
-// .map( "organization", String.format( "%s-%s-org", className, caller ) );
-// return payload;
-// }
-//
//
// @Test
// public void checkPasswordReset() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8585558f/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 55c10a3..63c420f 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
@@ -108,6 +108,8 @@ public class ClientSetup implements TestRule {
public String getUsername(){return username;}
+ public String getEmail(){return username+"@usergrid.com";}
+
public String getPassword(){return password;}
public Organization getOrganization(){return organization;}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8585558f/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ReactivateResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ReactivateResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ReactivateResource.java
new file mode 100644
index 0000000..25dc95e
--- /dev/null
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ReactivateResource.java
@@ -0,0 +1,46 @@
+/*
+ * 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 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;
+
+
+/**
+ * handles the * /reactivate endpoints
+ */
+public class ReactivateResource extends NamedResource {
+ public ReactivateResource(final ClientContext context, final UrlResource parent) {
+ super("reactivate",context, parent);
+ }
+
+ public Entity get(){
+ WebResource resource = getResource(true);
+ ApiResponse response = resource.type( MediaType.APPLICATION_JSON_TYPE )
+ .accept( MediaType.APPLICATION_JSON ).get( ApiResponse.class);
+ return new Entity(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8585558f/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
index b320e6b..bb70509 100644
--- 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
@@ -38,6 +38,10 @@ public class UserResource extends NamedResource {
super( name, context, parent );
}
+ public ReactivateResource reactivate() {
+ return new ReactivateResource( context, this );
+ }
+
public ConfirmResource confirm() {
return new ConfirmResource(context,this);
}
@@ -64,4 +68,5 @@ public class UserResource extends NamedResource {
.accept( MediaType.APPLICATION_JSON ).put( ApiResponse.class, userPayload);
return new Entity(response);
}
+
}