usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [2/4] usergrid git commit: Revert "Fix app delete logic to include delete protection parameter and adjust tests."
Date Mon, 23 May 2016 14:05:58 GMT
Revert "Fix app delete logic to include delete protection parameter and adjust tests."

This reverts commit 48c12ae950261784f4c35ecc4e8c84197a6b8cc0.


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

Branch: refs/heads/master
Commit: c5308aeb5560403c0be583a512ff58252859b3cb
Parents: 48c12ae
Author: Dave Johnson <snoopdave@apache.org>
Authored: Tue Mar 8 12:37:17 2016 -0500
Committer: Dave Johnson <snoopdave@apache.org>
Committed: Tue Mar 8 12:37:17 2016 -0500

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


http://git-wip-us.apache.org/repos/asf/usergrid/blob/c5308aeb/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 21e173a..c353959 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,15 +482,22 @@ public class ApplicationResource extends AbstractContextResource {
     @Produces({MediaType.APPLICATION_JSON, "application/javascript"})
     public ApiResponse executeDelete(  @Context UriInfo ui,
         @QueryParam("callback") @DefaultValue("callback") String callback,
-        @QueryParam("app_delete_confirm") String confirmDelete) throws Exception {
+        @QueryParam("application_identifier") String applicationConfirmedDelete) throws Exception
{
 
-        if ( applicationId == null ) {
-            throw new IllegalArgumentException("Application ID not specified in request");
+        //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.");
+            }
         }
-
-        if (!"confirm_delete_of_application_and_data".equals( confirmDelete ) ) {
+        else if (!application.getName().equals( applicationConfirmedDelete ) ) {
             throw new IllegalArgumentException(
-                "Cannot delete application without app_delete_confirm parameter");
+                "Cannot delete application without supplying correct application name");
+        }
+
+        if ( applicationId == null ) {
+            throw new IllegalArgumentException("Application ID not specified in request");
         }
 
         management.deleteApplication( applicationId );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/c5308aeb/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 54a11b4..7b4751d 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,13 +76,37 @@ public class ApplicationDeleteIT extends AbstractRestIT {
         final Response response = clientSetup.getRestClient().management().orgs()
             .org( orgName ).apps().app( appToDeleteId.toString() ).getTarget()
             .queryParam( "access_token", orgAdminToken.getAccessToken() )
-            .queryParam( "app_delete_confirm", "confirm_delete_of_application_and_data" )
+            .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)
             .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 );
@@ -95,6 +119,7 @@ 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 {
@@ -151,7 +176,6 @@ 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() );
@@ -170,31 +194,6 @@ 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>
@@ -225,7 +224,6 @@ 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();
 
@@ -306,7 +304,6 @@ 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();
 
@@ -349,7 +346,6 @@ 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();
 
@@ -363,7 +359,6 @@ 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