Skip to content

Commit aba4865

Browse files
committed
Test POST as well
1 parent 9b1bb00 commit aba4865

1 file changed

Lines changed: 28 additions & 13 deletions

File tree

src/org/labkey/test/tests/SecurityTest.java

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import static org.junit.Assert.assertTrue;
6565
import static org.junit.Assert.fail;
6666
import static org.labkey.test.WebTestHelper.buildURL;
67+
import static org.labkey.test.WebTestHelper.getHttpResponse;
6768
import static org.labkey.test.util.PermissionsHelper.AUTHOR_ROLE;
6869
import static org.labkey.test.util.PermissionsHelper.EDITOR_ROLE;
6970
import static org.labkey.test.util.PermissionsHelper.READER_ROLE;
@@ -556,20 +557,34 @@ public void loginSelfRegistrationDisabledTest()
556557
@Test
557558
public void invokeMutatingSqlAction()
558559
{
559-
// Ensure that a GET request invoking mutating SQL is flagged
560+
String getUrl = buildURL("test", "executeMutatingSqlGet");
561+
String postUrl = buildURL("test", "executeMutatingSqlPost");
560562
String feature = "AllowMutatingSqlViaGet";
561563
Connection conn = createDefaultConnection();
562-
OptionalFeatureHelper.disableOptionalFeature(conn, feature);
563-
beginAt(buildURL("test", "executeMutatingSql"));
564-
assertTextPresent("MUTATING SQL executed as part of handling action: GET org.labkey.devtools.TestController$ExecuteMutatingSqlAction");
565-
checkExpectedErrors(2);
566-
567-
// Turn on the deprecated feature flag and ensure that GET request can invoke mutating SQL
568-
OptionalFeatureHelper.enableOptionalFeature(conn, feature);
569-
beginAt(buildURL("test", "executeMutatingSql"));
570-
assertTextPresent("UPDATE via GET was allowed!");
571-
572-
// Restore flag to original value
573-
OptionalFeatureHelper.resetOptionalFeature(conn, feature);
564+
565+
try
566+
{
567+
OptionalFeatureHelper.disableOptionalFeature(conn, feature);
568+
569+
// Ensure that a GET request invoking mutating SQL is forbidden
570+
beginAt(getUrl);
571+
assertTextPresent("MUTATING SQL executed as part of handling action: GET org.labkey.devtools.TestController$ExecuteMutatingSqlAction");
572+
checkExpectedErrors(2);
573+
574+
// Ensure that a POST request to a POST action can invoke mutating SQL
575+
SimpleHttpResponse response = getHttpResponse(postUrl, "POST");
576+
assertTrue(response.getResponseBody().contains("UPDATE via POST was allowed!"));
577+
assertEquals(HttpStatus.SC_OK, response.getResponseCode());
578+
579+
// Turn on the deprecated feature flag and ensure that a GET request can now invoke mutating SQL
580+
OptionalFeatureHelper.enableOptionalFeature(conn, feature);
581+
beginAt(getUrl);
582+
assertTextPresent("UPDATE via GET was allowed!");
583+
}
584+
finally
585+
{
586+
// Restore flag to its original value
587+
OptionalFeatureHelper.resetOptionalFeature(conn, feature);
588+
}
574589
}
575590
}

0 commit comments

Comments
 (0)