usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [1/4] usergrid git commit: Fix app delete logic to include delete protection parameter and adjust tests.
Date Mon, 23 May 2016 14:05:57 GMT
Repository: usergrid
Updated Branches:
  refs/heads/master 886e837c1 -> 337c94c58


Fix app delete logic to include delete protection parameter and adjust tests.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/48c12ae9
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/48c12ae9
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/48c12ae9

Branch: refs/heads/master
Commit: 48c12ae950261784f4c35ecc4e8c84197a6b8cc0
Parents: ce34a04
Author: Dave Johnson <snoopdave@apache.org>
Authored: Tue Mar 8 12:36:04 2016 -0500
Committer: Dave Johnson <snoopdave@apache.org>
Committed: Tue Mar 8 12:36:04 2016 -0500

----------------------------------------------------------------------
 .../applications/ApplicationResource.java       | 19 +++----
 .../rest/applications/ApplicationDeleteIT.java  | 57 +++++++++++---------
 2 files changed, 37 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/48c12ae9/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
index c353959..21e173a 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
@@ -482,24 +482,17 @@ public class ApplicationResource extends AbstractContextResource {
     @Produces({MediaType.APPLICATION_JSON, "application/javascript"})
     public ApiResponse executeDelete(  @Context UriInfo ui,
         @QueryParam("callback") @DefaultValue("callback") String callback,
-        @QueryParam("application_identifier") String applicationConfirmedDelete) throws Exception
{
-
-        //If the path uses name then expect name, otherwise if they use uuid then expect
uuid.
-        if(application==null){
-            if(!applicationId.toString().equals( applicationConfirmedDelete )){
-                throw new IllegalArgumentException(
-                    "Cannot delete application without supplying correct application id.");
-            }
-        }
-        else if (!application.getName().equals( applicationConfirmedDelete ) ) {
-            throw new IllegalArgumentException(
-                "Cannot delete application without supplying correct application name");
-        }
+        @QueryParam("app_delete_confirm") String confirmDelete) throws Exception {
 
         if ( applicationId == null ) {
             throw new IllegalArgumentException("Application ID not specified in request");
         }
 
+        if (!"confirm_delete_of_application_and_data".equals( confirmDelete ) ) {
+            throw new IllegalArgumentException(
+                "Cannot delete application without app_delete_confirm parameter");
+        }
+
         management.deleteApplication( applicationId );
 
         if (logger.isTraceEnabled()) {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/48c12ae9/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java
index 7b4751d..54a11b4 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteIT.java
@@ -76,37 +76,13 @@ public class ApplicationDeleteIT extends AbstractRestIT {
         final Response response = clientSetup.getRestClient().management().orgs()
             .org( orgName ).apps().app( appToDeleteId.toString() ).getTarget()
             .queryParam( "access_token", orgAdminToken.getAccessToken() )
-            .request()
-            .delete();
-
-        Assert.assertEquals("Error must be 400", 400, response.getStatus() );
-
-        clientSetup.getRestClient().management().orgs()
-            .org(orgName).apps().app(appToDeleteId.toString() ).getTarget()
-            .queryParam("access_token", orgAdminToken.getAccessToken() )
-            .queryParam("application_identifier", appToDeleteId)
+            .queryParam( "app_delete_confirm", "confirm_delete_of_application_and_data" )
             .request()
             .delete();
 
         // test that we can no longer get the app
 
         try {
-            clientSetup.getRestClient().management().orgs()
-                .org(orgName).apps().app(appToDeleteName).getTarget()
-                .queryParam("access_token", orgAdminToken.getAccessToken())
-                .request()
-                .get(ApiResponse.class);
-
-            fail("Must not be able to get deleted app");
-
-        } catch ( ClientErrorException expected ) {
-            Assert.assertEquals("Error must be 404", 404, expected.getResponse().getStatus()
);
-            JsonNode node = mapper.readTree( expected.getResponse().readEntity( String.class
));
-            Assert.assertEquals("entity_not_found", node.get("error").textValue());
-        }
-
-
-        try {
             clientSetup.getRestClient().org( orgName ).app( appToDeleteName ).getTarget()
                        .queryParam( "access_token", orgAdminToken.getAccessToken() ).request()
                        .get( ApiResponse.class );
@@ -119,7 +95,6 @@ public class ApplicationDeleteIT extends AbstractRestIT {
             Assert.assertEquals( "organization_application_not_found", node.get( "error"
).textValue() );
         }
 
-
         // test that we can no longer get deleted app's collection
 
         try {
@@ -176,6 +151,7 @@ public class ApplicationDeleteIT extends AbstractRestIT {
             .orgs().org( orgName ).apps().app( appToDeleteId.toString() )
             .getTarget().queryParam( "access_token", orgAdminToken.getAccessToken() )
             .queryParam( "application_identifier", appToDeleteId )
+            .queryParam( "app_delete_confirm", "confirm_delete_of_application_and_data" )
             .request()
             .delete();
         Assert.assertEquals( "Error must be 404", 404, response1.getStatus() );
@@ -194,6 +170,31 @@ public class ApplicationDeleteIT extends AbstractRestIT {
     }
 
 
+    @Test
+    public void testDeleteProtection() throws Exception {
+
+        // create app with a collection of "things"
+
+        String orgName = clientSetup.getOrganization().getName();
+        String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
+        Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername()
);
+
+        List<Entity> entities = new ArrayList<>();
+
+        UUID appToDeleteId = createAppWithCollection( orgName, appToDeleteName, orgAdminToken,
entities );
+
+        // delete the app without confirm parameter, should fail
+
+        clientSetup.getRestClient().management().orgs()
+            .org( orgName ).apps().app( appToDeleteName ).getTarget()
+            .queryParam( "access_token", orgAdminToken.getAccessToken() )
+            .queryParam( "application_identifier", appToDeleteName )
+            .request()
+            .delete();
+
+    }
+
+
     /**
      * Test restore of deleted app.
      * <pre>
@@ -224,6 +225,7 @@ public class ApplicationDeleteIT extends AbstractRestIT {
             .org( orgName ).apps().app( appToDeleteName ).getTarget()
             .queryParam( "access_token", orgAdminToken.getAccessToken() )
             .queryParam("application_identifier", appToDeleteName)
+            .queryParam( "app_delete_confirm", "confirm_delete_of_application_and_data" )
             .request()
             .delete();
 
@@ -304,6 +306,7 @@ public class ApplicationDeleteIT extends AbstractRestIT {
             .org( orgName ).apps().app( appToDeleteId.toString() ).getTarget()
             .queryParam( "access_token", orgAdminToken.getAccessToken() )
             .queryParam("application_identifier", appToDeleteId)
+            .queryParam( "app_delete_confirm", "confirm_delete_of_application_and_data" )
             .request()
             .delete();
 
@@ -346,6 +349,7 @@ public class ApplicationDeleteIT extends AbstractRestIT {
             .orgs().org( orgName ).apps().app( appToDeleteId.toString() ).getTarget()
             .queryParam( "access_token", orgAdminToken.getAccessToken() )
             .queryParam( "application_identifier", appToDeleteId )
+            .queryParam( "app_delete_confirm", "confirm_delete_of_application_and_data" )
             .request()
             .delete();
 
@@ -359,6 +363,7 @@ public class ApplicationDeleteIT extends AbstractRestIT {
             .orgs().org( orgName ).apps().app( newAppId.toString() ).getTarget()
             .queryParam( "access_token", orgAdminToken.getAccessToken() )
             .queryParam( "application_identifier", newAppId )
+            .queryParam( "app_delete_confirm", "confirm_delete_of_application_and_data" )
             .request()
             .delete();
 


Mime
View raw message