You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2015/05/28 21:42:40 UTC
[04/50] [abbrv] incubator-usergrid git commit: [USERGRID-340]
Updating RegistrationIT
[USERGRID-340] Updating RegistrationIT
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/8eda8bed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/8eda8bed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/8eda8bed
Branch: refs/heads/two-dot-o-dev
Commit: 8eda8bedc8dd23a7a1d39729ae3379933afa5f82
Parents: 2d1c8b8
Author: ryan bridges <ry...@apache.org>
Authored: Thu Apr 2 02:29:50 2015 -0400
Committer: ryan bridges <ry...@apache.org>
Committed: Fri Apr 17 10:05:17 2015 -0400
----------------------------------------------------------------------
.../rest/management/RegistrationIT.java | 440 +++++++++----------
1 file changed, 204 insertions(+), 236 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8eda8bed/stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java
index f949da3..1e94a2d 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/RegistrationIT.java
@@ -17,212 +17,193 @@
package org.apache.usergrid.rest.management;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.UUID;
-
-import javax.mail.Folder;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.Store;
-import javax.mail.internet.MimeMultipart;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-
-import com.eaio.uuid.UUIDGen;
-import com.fasterxml.jackson.databind.JsonNode;
-
-import org.junit.Rule;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import com.sun.jersey.api.representation.Form;
+import org.apache.commons.lang.StringUtils;
+import org.apache.usergrid.management.AccountCreationProps;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
+import org.apache.usergrid.rest.test.resource2point0.model.*;
import org.junit.Test;
import org.jvnet.mock_javamail.Mailbox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.management.UserInfo;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-import org.apache.usergrid.rest.AbstractRestIT;
-import org.apache.usergrid.rest.ITSetup;
-import org.apache.usergrid.rest.TestContextSetup;
-import org.apache.usergrid.rest.test.security.TestAppUser;
-import org.apache.usergrid.rest.test.security.TestUser;
-import org.apache.commons.lang.StringUtils;
+import javax.mail.*;
+import javax.mail.internet.MimeMultipart;
+import javax.ws.rs.core.MediaType;
+import java.io.IOException;
+import java.util.*;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_ADMIN_RESETPW_URL;
-import static org.apache.usergrid.management.AccountCreationProps.PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION;
-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.utils.MapUtils.hashMap;
+import static org.apache.usergrid.management.AccountCreationProps.*;
+import static org.junit.Assert.*;
public class RegistrationIT extends AbstractRestIT {
- private static final Logger logger = LoggerFactory.getLogger( RegistrationIT.class );
-
- private static final ITSetup setup = ITSetup.getInstance();
-
- @Rule
- public TestContextSetup context = new TestContextSetup( this );
-
-
- @Test
- public void postCreateOrgAndAdmin() throws Exception {
-
- Map<String, String> originalProperties = getRemoteTestProperties();
+ private static final Logger logger = LoggerFactory.getLogger(RegistrationIT.class);
- try {
- setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
- setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
- setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false" );
- setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
+ public Map<String, Object> getRemoteTestProperties() {
+ return clientSetup.getRestClient().testPropertiesResource().get().getProperties();
+ }
-// JsonNode node = postCreateOrgAndAdmin( "test-org-1", "test-user-1", "Test User",
-// "test-user-1@mockserver.com", "testpassword" );
+ /**
+ * Sets a management service property locally and remotely.
+ */
+ public void setTestProperty(String key, Object value) {
+ // set the value remotely (in the Usergrid instance running in Tomcat classloader)
+ Entity props = new Entity();
+ props.put(key, value);
+ clientSetup.getRestClient().testPropertiesResource().post(props);
+ }
- final String username = "registrationUser"+UUIDGenerator.newTimeUUID();
- final String email = username+"@usergrid.com" ;
- final String password = "password";
+ public void setTestProperties(Map<String, Object> props) {
+ Entity properties = new Entity();
+ // set the values locally (in the Usergrid instance here in the JUnit classloader
+ for (String key : props.keySet()) {
+ properties.put(key, props.get(key));
- final TestUser user1 = new TestAppUser(username , password, email);
+ }
- context.withOrg( "org" + UUIDGenerator.newTimeUUID() ).withApp( "app" + UUIDGenerator.newTimeUUID() ).withUser( user1 ).createNewOrgAndUser();
- context.createAppForOrg();
+ // set the values remotely (in the Usergrid instance running in Tomcat classloader)
+ clientSetup.getRestClient().testPropertiesResource().post(properties);
+ }
- final UUID owner_uuid = context.getActiveUser().getUuid();
+ public String getTokenFromMessage(Message msg) throws IOException, MessagingException {
+ String body = ((MimeMultipart) msg.getContent()).getBodyPart(0).getContent().toString();
+ // TODO better token extraction
+ // this is going to get the wrong string if the first part is not
+ // text/plain and the url isn't the last character in the email
+ return StringUtils.substringAfterLast(body, "token=");
+ }
-// refreshIndex("test-organization", "test-app");
-//
-// UUID owner_uuid =
-// UUID.fromString( node.findPath( "data" ).findPath( "owner" ).findPath( "uuid" ).textValue() );
+ public User postAddAdminToOrg(String organizationName, String email, String password, String token) throws IOException {
- List<Message> inbox = org.jvnet.mock_javamail.Mailbox.get( "test-user-1@mockserver.com" );
+ User user = this
+ .management()
+ .orgs()
+ .organization(organizationName)
+ .users()
+ .getResource(false)
+ .queryParam("access_token", token)
+ .post(User.class, new User().chainPut("email", email).chainPut("password", password));
- assertFalse( inbox.isEmpty() );
+ assertNotNull(user);
+ return user;
+ }
- Message account_confirmation_message = inbox.get( 0 );
- assertEquals( "User Account Confirmation: " + email,
- account_confirmation_message.getSubject() );
+ private Message[] getMessages(String host, String user, String password) throws MessagingException, IOException {
- String token = getTokenFromMessage( account_confirmation_message );
- logger.info( token );
+ Session session = Session.getDefaultInstance(new Properties());
+ Store store = session.getStore("imap");
+ store.connect(host, user, password);
- setup.getMgmtSvc().disableAdminUser( owner_uuid );
+ Folder folder = store.getFolder("inbox");
+ folder.open(Folder.READ_ONLY);
+ Message[] msgs = folder.getMessages();
- refreshIndex(context.getOrgName(), context.getAppName());
+ for (Message m : msgs) {
+ logger.info("Subject: " + m.getSubject());
+ logger.info(
+ "Body content 0 " + ((MimeMultipart) m.getContent()).getBodyPart(0).getContent());
+ logger.info(
+ "Body content 1 " + ((MimeMultipart) m.getContent()).getBodyPart(1).getContent());
+ }
+ return msgs;
+ }
- try {
- resource().path( "/management/token" ).queryParam( "grant_type", "password" )
- .queryParam( "username", username ).queryParam( "password", password )
- .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
- .get( String.class );
- fail( "request for disabled user should fail" );
- }
- catch ( UniformInterfaceException uie ) {
- ClientResponse.Status status = uie.getResponse().getClientResponseStatus();
- JsonNode body = mapper.readTree( uie.getResponse().getEntity( String.class ));
- assertEquals( "user disabled", body.findPath( "error_description" ).textValue() );
- }
+ @Test
+ public void postCreateOrgAndAdmin() throws Exception {
- setup.getMgmtSvc().deactivateUser( setup.getEmf().getManagementAppId(), owner_uuid );
- try {
- resource().path( "/management/token" ).queryParam( "grant_type", "password" )
- .queryParam( "username", username ).queryParam( "password", password)
- .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON_TYPE )
- .get( String.class );
- fail( "request for deactivated user should fail" );
- }
- catch ( UniformInterfaceException uie ) {
- ClientResponse.Status status = uie.getResponse().getClientResponseStatus();
- JsonNode body = mapper.readTree( uie.getResponse().getEntity( String.class ));
- assertEquals( "user not activated", body.findPath( "error_description" ).textValue() );
- }
+ Map<String, Object> originalProperties = getRemoteTestProperties();
- // assertEquals(ActivationState.ACTIVATED,
- // svcSetup.getMgmtSvc().handleConfirmationTokenForAdminUser(
- // owner_uuid, token));
+ try {
+ setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false");
+ setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
+ setTestProperty(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false");
+ setTestProperty(PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com");
- // need to enable JSP usage in the test version of Jetty to make this test run
- // String response = resource()
- // .path("/management/users/" + owner_uuid + "/confirm").get(String.class);
- // logger.info(response);
- // Message account_activation_message = inbox.get(1);
- // assertEquals("User Account Activated", account_activation_message.getSubject());
+ final String username = "registrationUser" + UUIDGenerator.newTimeUUID();
+ final String email = username + "@usergrid.com";
+ final String password = "password";
- }
- finally {
- setTestProperties( originalProperties );
- }
- }
+ Organization organization = this
+ .management()
+ .orgs()
+ .post(new Organization("org" + UUIDGenerator.newTimeUUID(), username, email, username, password, new HashMap<String, Object>()), this.getAdminToken());
+ Application application = new Application("app" + UUIDGenerator.newTimeUUID());
+ this.management().orgs().organization(organization.getName()).app().post(application);
+ List<Message> inbox = org.jvnet.mock_javamail.Mailbox.get("test-user-1@mockserver.com");
- public String getTokenFromMessage( Message msg ) throws IOException, MessagingException {
- String body = ( ( MimeMultipart ) msg.getContent() ).getBodyPart( 0 ).getContent().toString();
- String token = StringUtils.substringAfterLast( body, "token=" );
- // TODO better token extraction
- // this is going to get the wrong string if the first part is not
- // text/plain and the url isn't the last character in the email
- return token;
- }
+ assertFalse(inbox.isEmpty());
+ Message account_confirmation_message = inbox.get(0);
+ assertEquals("User Account Confirmation: " + email,
+ account_confirmation_message.getSubject());
+ String token = getTokenFromMessage(account_confirmation_message);
+ logger.info(token);
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public JsonNode postAddAdminToOrg( String organizationName, String email, String password, String token ) throws IOException {
- JsonNode node = null;
+ setTestProperty(AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_ALLOWED, "false");
- MultivaluedMap formData = new MultivaluedMapImpl();
- formData.add( "email", email );
- formData.add( "password", password );
+ refreshIndex();
- node = mapper.readTree( resource().path( "/management/organizations/" + organizationName + "/users" )
- .queryParam( "access_token", token ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_FORM_URLENCODED ).post( String.class, formData ));
+ try {
+ this.management().orgs().organization(organization.getName()).users().user(username)
+ .getResource(false)
+ .queryParam("username", username)
+ .queryParam("password", password)
+ .get(String.class);
+ fail("request for disabled user should fail");
+ } catch (UniformInterfaceException uie) {
+ assertEquals("user disabled", uie.getMessage());
+ }
+ this.management()
+ .orgs()
+ .organization(organization.getName())
+ .users()
+ .user(username)
+ .put(new Entity().chainPut("activated", false).chainPut("deactivated", System.currentTimeMillis()));
+ try {
+ management()
+ .token()
+ .get(new QueryParameters().addParam("grant_type", "password").addParam("username", username).addParam("password", password));
+ fail("request for deactivated user should fail");
+ } catch (UniformInterfaceException uie) {
+ assertEquals("user not activated", uie.getMessage());
+ }
- assertNotNull( node );
- logNode( node );
- return node;
+ } finally {
+ setTestProperties(originalProperties);
+ }
}
@Test
public void putAddToOrganizationFail() throws Exception {
- Map<String, String> originalProperties = getRemoteTestProperties();
+ Map<String, Object> originalProperties = getRemoteTestProperties();
try {
- setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
- setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
- setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false" );
- setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
-
- String t = adminToken();
- MultivaluedMap formData = new MultivaluedMapImpl();
- formData.add( "foo", "bar" );
+ setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false");
+ setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
+ setTestProperty(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false");
+ setTestProperty(PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com");
+
+ String t = this.getAdminToken().getAccessToken();
+ Form form = new Form();
+ form.add("foo", "bar");
try {
- resource().path( "/management/organizations/test-organization/users/test-admin-null@mockserver.com" )
- .queryParam( "access_token", t ).accept( MediaType.APPLICATION_JSON )
- .type( MediaType.APPLICATION_FORM_URLENCODED ).put( String.class, formData );
+ this.org().getResource(false).path("/users/test-admin-null@mockserver.com")
+ .queryParam("access_token", t).accept(MediaType.APPLICATION_JSON)
+ .type(MediaType.APPLICATION_FORM_URLENCODED).put(String.class, form);
+ } catch (UniformInterfaceException e) {
+ assertEquals("Should receive a 400 Not Found", 400, e.getResponse().getStatus());
}
- catch ( UniformInterfaceException e ) {
- assertEquals( "Should receive a 400 Not Found", 400, e.getResponse().getStatus() );
- }
- }
- finally {
- setTestProperties( originalProperties );
+ } finally {
+ setTestProperties(originalProperties);
}
}
@@ -230,19 +211,18 @@ public class RegistrationIT extends AbstractRestIT {
@Test
public void postAddToOrganization() throws Exception {
- Map<String, String> originalProperties = getRemoteTestProperties();
+ Map<String, Object> originalProperties = getRemoteTestProperties();
try {
- setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
- setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
- setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false" );
- setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
-
- String t = adminToken();
- postAddAdminToOrg( "test-organization", "test-admin@mockserver.com", "password", t );
- }
- finally {
- setTestProperties( originalProperties );
+ setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false");
+ setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
+ setTestProperty(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false");
+ setTestProperty(PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com");
+
+ String t = this.getAdminToken().getAccessToken();
+ postAddAdminToOrg("test-organization", "test-admin@mockserver.com", "password", t);
+ } finally {
+ setTestProperties(originalProperties);
}
}
@@ -250,48 +230,57 @@ public class RegistrationIT extends AbstractRestIT {
@Test
public void addNewAdminUserWithNoPwdToOrganization() throws Exception {
- Map<String, String> originalProperties = getRemoteTestProperties();
+ Map<String, Object> originalProperties = getRemoteTestProperties();
try {
Mailbox.clearAll();
- setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
- setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
- setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false" );
- setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
+ setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false");
+ setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
+ setTestProperty(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false");
+ setTestProperty(PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com");
// this should send resetpwd link in email to newly added org admin user(that did not exist
///in usergrid) and "User Invited To Organization" email
- String adminToken = adminToken();
- JsonNode node = postAddAdminToOrg( "test-organization", "test-admin-nopwd@mockserver.com", "", adminToken );
- String uuid = node.get( "data" ).get( "user" ).get( "uuid" ).textValue();
- UUID userId = UUID.fromString( uuid );
+ String adminToken = getAdminToken().getAccessToken();
+ Entity node = postAddAdminToOrg("test-organization", "test-admin-nopwd@mockserver.com", "", adminToken);
+ UUID userId = (UUID) node.getMap("data").get("user").get("uuid");
- refreshIndex("test-organization", "test-app");
+ refreshIndex();
String subject = "Password Reset";
- String reset_url = String.format( setup.getProps().getProperty( PROPERTIES_ADMIN_RESETPW_URL ), uuid );
+ Map<String, Object> testProperties = this.getRemoteTestProperties();
+ String reset_url = String.format((String) testProperties.get(PROPERTIES_ADMIN_RESETPW_URL), userId.toString());
String invited = "User Invited To Organization";
- Message[] msgs = getMessages( "mockserver.com", "test-admin-nopwd", "password" );
+ Message[] msgs = getMessages("mockserver.com", "test-admin-nopwd", "password");
// 1 Invite and 1 resetpwd
- assertTrue( msgs.length == 2 );
+ assertTrue(msgs.length == 2);
//email subject
- assertEquals( subject, msgs[0].getSubject() );
- assertEquals( invited, msgs[1].getSubject() );
+ assertEquals(subject, msgs[0].getSubject());
+ assertEquals(invited, msgs[1].getSubject());
// reseturl
- String mailContent = ( String ) ( ( MimeMultipart ) msgs[0].getContent() ).getBodyPart( 1 ).getContent();
- logger.info( mailContent );
- assertTrue( StringUtils.contains( mailContent, reset_url ) );
+ String mailContent = (String) ((MimeMultipart) msgs[0].getContent()).getBodyPart(1).getContent();
+ logger.info(mailContent);
+ assertTrue(StringUtils.contains(mailContent, reset_url));
//token
- String token = getTokenFromMessage( msgs[0] );
- assertTrue( setup.getMgmtSvc().checkPasswordResetTokenForAdminUser( userId, token ) );
- }
- finally {
- setTestProperties( originalProperties );
+ String token = getTokenFromMessage(msgs[0]);
+ this
+ .management()
+ .orgs()
+ .organization("test-organization")
+ .users()
+ .getResource(false)
+ .queryParam("access_token", token)
+ .get(String.class);
+ fail("Should not be able to authenticate an admin with no admin access allowed");
+ } catch (UniformInterfaceException uie) {
+ assertEquals(401, uie.getResponse().getStatus());
+ } finally {
+ setTestProperties(originalProperties);
}
}
@@ -299,75 +288,54 @@ public class RegistrationIT extends AbstractRestIT {
@Test
public void addExistingAdminUserToOrganization() throws Exception {
- Map<String, String> originalProperties = getRemoteTestProperties();
+ Map<String, Object> originalProperties = getRemoteTestProperties();
try {
Mailbox.clearAll();
- setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false" );
- setTestProperty( PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false" );
- setTestProperty( PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false" );
- setTestProperty( PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com" );
+ setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false");
+ setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
+ setTestProperty(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false");
+ setTestProperty(PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com");
// svcSetup an admin user
String adminUserName = "AdminUserFromOtherOrg";
String adminUserEmail = "AdminUserFromOtherOrg@otherorg.com";
- UserInfo adminUser = setup.getMgmtSvc().createAdminUser(
- adminUserEmail, adminUserEmail, adminUserEmail, "password1", true, false );
+ User adminUser = (User) management().users().post(new User(adminUserEmail, adminUserEmail, adminUserEmail, "password1"));
- refreshIndex("test-organization", "test-app");
+ refreshIndex();
- assertNotNull( adminUser );
- Message[] msgs = getMessages( "otherorg.com", adminUserName, "password1" );
- assertEquals( 1, msgs.length );
+ assertNotNull(adminUser);
+ Message[] msgs = getMessages("otherorg.com", adminUserName, "password1");
+ assertEquals(1, msgs.length);
// add existing admin user to org
// this should NOT send resetpwd link in email to newly added org admin user(that
// already exists in usergrid) only "User Invited To Organization" email
- String adminToken = adminToken();
- JsonNode node = postAddAdminToOrg( "test-organization",
- adminUserEmail, "password1", adminToken );
- String uuid = node.get( "data" ).get( "user" ).get( "uuid" ).textValue();
- UUID userId = UUID.fromString( uuid );
+ String adminToken = getAdminToken().getAccessToken();
+ User node = postAddAdminToOrg("test-organization",
+ adminUserEmail, "password1", adminToken);
+ String uuid = node.getMap("data").get("user").get("uuid").toString();
+ UUID userId = UUID.fromString(uuid);
- assertEquals( adminUser.getUuid(), userId );
+ assertEquals(adminUser.getUuid(), userId);
- msgs = getMessages( "otherorg.com", adminUserName, "password1" );
+ msgs = getMessages("otherorg.com", adminUserName, "password1");
// only 1 invited msg
- assertEquals( 2, msgs.length );
+ assertEquals(2, msgs.length);
// check email subject
String resetpwd = "Password Reset";
- assertNotSame( resetpwd, msgs[1].getSubject() );
+ assertNotSame(resetpwd, msgs[1].getSubject());
String invited = "User Invited To Organization";
- assertEquals( invited, msgs[1].getSubject() );
- }
- finally {
- setTestProperties( originalProperties );
+ assertEquals(invited, msgs[1].getSubject());
+ } finally {
+ setTestProperties(originalProperties);
}
}
- private Message[] getMessages( String host, String user, String password ) throws MessagingException, IOException {
-
- Session session = Session.getDefaultInstance( new Properties() );
- Store store = session.getStore( "imap" );
- store.connect( host, user, password );
-
- Folder folder = store.getFolder( "inbox" );
- folder.open( Folder.READ_ONLY );
- Message[] msgs = folder.getMessages();
-
- for ( Message m : msgs ) {
- logger.info( "Subject: " + m.getSubject() );
- logger.info(
- "Body content 0 " + ( ( MimeMultipart ) m.getContent() ).getBodyPart( 0 ).getContent());
- logger.info(
- "Body content 1 " + ( ( MimeMultipart ) m.getContent() ).getBodyPart( 1 ).getContent());
- }
- return msgs;
- }
}