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 1F27710E92 for ; Wed, 4 Mar 2015 22:39:00 +0000 (UTC) Received: (qmail 2950 invoked by uid 500); 4 Mar 2015 22:38:57 -0000 Delivered-To: apmail-usergrid-commits-archive@usergrid.apache.org Received: (qmail 2861 invoked by uid 500); 4 Mar 2015 22:38:57 -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 2522 invoked by uid 99); 4 Mar 2015 22:38:56 -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; Wed, 04 Mar 2015 22:38:56 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8B72BE102F; Wed, 4 Mar 2015 22:38:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sfeldman@apache.org To: commits@usergrid.apache.org Date: Wed, 04 Mar 2015 22:39:09 -0000 Message-Id: In-Reply-To: <9f67f0ff715f46e592508a1b4b84a98f@git.apache.org> References: <9f67f0ff715f46e592508a1b4b84a98f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [14/38] incubator-usergrid git commit: Added testSystemAdmin needs no confirmation test 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-432 Commit: 5bdbc297a0bcc9f7c0bb247dc41b99f240a8ced5 Parents: 88fe906 Author: grey Authored: Fri Feb 27 11:56:09 2015 -0800 Committer: grey 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 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 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()); }