From 282bfc31510383e23e551ad30bf36c4ea099768d Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Sat, 12 Dec 2009 17:32:27 +0000 Subject: [PATCH] Added some integration tests for Basic authentication, both alone and in combination with form login. --- .../webapp/WEB-INF/http-security-basic.xml | 14 +++++++++++ .../integration/BasicAuthenticationTests.java | 23 +++++++++++++++++++ .../InMemoryProviderWebAppTests.java | 7 ++++++ 3 files changed, 44 insertions(+) create mode 100644 itest/web/src/main/webapp/WEB-INF/http-security-basic.xml create mode 100644 itest/web/src/test/java/org/springframework/security/integration/BasicAuthenticationTests.java diff --git a/itest/web/src/main/webapp/WEB-INF/http-security-basic.xml b/itest/web/src/main/webapp/WEB-INF/http-security-basic.xml new file mode 100644 index 0000000000..460950b09f --- /dev/null +++ b/itest/web/src/main/webapp/WEB-INF/http-security-basic.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/itest/web/src/test/java/org/springframework/security/integration/BasicAuthenticationTests.java b/itest/web/src/test/java/org/springframework/security/integration/BasicAuthenticationTests.java new file mode 100644 index 0000000000..4886386e17 --- /dev/null +++ b/itest/web/src/test/java/org/springframework/security/integration/BasicAuthenticationTests.java @@ -0,0 +1,23 @@ +package org.springframework.security.integration; + +import org.testng.annotations.Test; + +public class BasicAuthenticationTests extends AbstractWebServerIntegrationTests { + + @Override + protected String getContextConfigLocations() { + return "/WEB-INF/http-security-basic.xml /WEB-INF/in-memory-provider.xml"; + } + + @Test + public void basicAuthenticationIsSuccessful() throws Exception { + tester.setIgnoreFailingStatusCodes(true); + beginAt("secure/index.html"); + // Ignore the 401 + tester.setIgnoreFailingStatusCodes(false); + tester.assertHeaderEquals("WWW-Authenticate", "Basic realm=\"Spring Security Application\""); + tester.getTestContext().setAuthorization("johnc", "johncspassword"); + beginAt("secure/index.html"); + } + +} diff --git a/itest/web/src/test/java/org/springframework/security/integration/InMemoryProviderWebAppTests.java b/itest/web/src/test/java/org/springframework/security/integration/InMemoryProviderWebAppTests.java index a9ac66676f..5f5b3c03fb 100644 --- a/itest/web/src/test/java/org/springframework/security/integration/InMemoryProviderWebAppTests.java +++ b/itest/web/src/test/java/org/springframework/security/integration/InMemoryProviderWebAppTests.java @@ -29,6 +29,13 @@ public class InMemoryProviderWebAppTests extends AbstractWebServerIntegrationTes tester.gotoPage("/logout"); } + @Test + public void basicAuthenticationIsSuccessful() throws Exception { + tester.getTestContext().setAuthorization("johnc", "johncspassword"); + beginAt("secure/index.html"); + beginAt("secure/index.html"); + } + /* * Checks use of with parameters in the secured page. */