Jelajahi Sumber

Added some integration tests for Basic authentication, both alone and in combination with form login.

Luke Taylor 15 tahun lalu
induk
melakukan
282bfc3151

+ 14 - 0
itest/web/src/main/webapp/WEB-INF/http-security-basic.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<beans:beans xmlns="http://www.springframework.org/schema/security"
+    xmlns:beans="http://www.springframework.org/schema/beans"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
+
+    <http>
+        <intercept-url pattern="/**" access="ROLE_DEVELOPER,ROLE_USER" />
+        <http-basic />
+    </http>
+
+</beans:beans>

+ 23 - 0
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");
+    }
+
+}

+ 7 - 0
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 <jsp:include> with parameters in the secured page.
      */