From 2214522bc5a91bfb5cf4c75852fa20c4bed4180c Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Fri, 6 Sep 2019 15:46:50 +0100
Subject: [PATCH] Add a custom mod_sso test

Matches a specific production config that needed to be tested.
---
 src/mod_sso/test/htdocs/protected/index.html |  1 +
 src/mod_sso/test/httpd_integration_test.py   | 12 +++++--
 src/mod_sso/test/test-httpd-subdir.conf      | 34 ++++++++++++++++++++
 3 files changed, 45 insertions(+), 2 deletions(-)
 create mode 100644 src/mod_sso/test/htdocs/protected/index.html
 create mode 100644 src/mod_sso/test/test-httpd-subdir.conf

diff --git a/src/mod_sso/test/htdocs/protected/index.html b/src/mod_sso/test/htdocs/protected/index.html
new file mode 100644
index 0000000..ce01362
--- /dev/null
+++ b/src/mod_sso/test/htdocs/protected/index.html
@@ -0,0 +1 @@
+hello
diff --git a/src/mod_sso/test/httpd_integration_test.py b/src/mod_sso/test/httpd_integration_test.py
index 3e40ff0..38079f5 100755
--- a/src/mod_sso/test/httpd_integration_test.py
+++ b/src/mod_sso/test/httpd_integration_test.py
@@ -261,12 +261,12 @@ class HttpdIntegrationTestBase(unittest.TestCase):
                             name, check["url"], location, check["location"]))
 
     def _login_workflow(self, host_header, url, sso_service=None, sso_login_url=None):
-        if not sso_login_url:
-            sso_login_url = "/sso_login"
         if not sso_service:
             sso_service = host_header + os.path.dirname(url)
         if not sso_service.endswith('/'):
             sso_service += '/'
+        if not sso_login_url:
+            sso_login_url = '/%s/sso_login' % sso_service.split('/', 1)[1]
 
         cookies = Cookie.SimpleCookie()
 
@@ -418,6 +418,14 @@ class WebmailIntegrationTestWithNonces(HttpdIntegrationTestBase):
     def test_login_workflow(self):
         self._login_workflow("service.example.com", "/index.html")
 
+
+class SubdirIntegrationTest(HttpdIntegrationTestBase):
+
+    CONFIG = 'test-httpd-subdir.conf'
+
+    def test_subdir(self):
+        self._login_workflow("service.example.com", "/protected/index.html")
+
     
 if __name__ == "__main__":
     unittest.main()
diff --git a/src/mod_sso/test/test-httpd-subdir.conf b/src/mod_sso/test/test-httpd-subdir.conf
new file mode 100644
index 0000000..1e59971
--- /dev/null
+++ b/src/mod_sso/test/test-httpd-subdir.conf
@@ -0,0 +1,34 @@
+LoadModule mpm_worker_module /usr/lib/apache2/modules/mod_mpm_worker.so
+
+LoadModule auth_basic_module ${MODULEDIR}/mod_auth_basic.so
+LoadModule authn_core_module ${MODULEDIR}/mod_authn_core.so
+LoadModule authz_core_module ${MODULEDIR}/mod_authz_core.so
+LoadModule authz_user_module ${MODULEDIR}/mod_authz_user.so
+
+LoadModule unique_id_module ${MODULEDIR}/mod_unique_id.so
+LoadModule sso_module ${TESTROOT}/../.libs/mod_sso.so
+LoadModule cgi_module /usr/lib/apache2/modules/mod_cgi.so
+
+Listen 127.0.0.1:${APACHE_PORT}
+ServerName test
+PidFile ${TESTROOT}/test-httpd.pid
+Mutex file:${TESTROOT} default
+ErrorLog ${APACHE_LOG}
+LogLevel debug
+
+SSOLoginServer login.example.com
+SSODomain example.com
+SSOPublicKeyFile ${TESTROOT}/public.key
+SSOSessionKeyFile ${TESTROOT}/session.key
+
+DocumentRoot ${TESTROOT}/htdocs
+<Directory "${TESTROOT}/htdocs">
+        require all granted
+</Directory>
+
+<Location "/protected">
+	AuthType SSO
+	AuthName test
+	SSOService service.example.com/protected/
+	require valid-user
+</Location>
-- 
GitLab