summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2015-09-25 11:14:09 +0200
committerCarlos Garcia Campos <carlosgc@gnome.org>2015-09-28 09:55:22 +0200
commitc6c95600f00d36d6e1c76e2f6bc6286019de0688 (patch)
tree4a2713d8cccb301c63d559addc2699bbadaae0ff
parent8da87a6aad7cd221bdf787fcd1a9e8f12cd8d43f (diff)
downloadlibsoup-c6c95600f00d36d6e1c76e2f6bc6286019de0688.tar.gz
soup-auth-basic: Correctly handle the protection space for subdirectories of root dir
Return "/" as parent directory of "/foo", instead of returning "/foo" in soup_auth_basic_get_protection_space(). This was causing that the Authorization header was not set when visiting / after a succesful login from /foo. https://bugzilla.gnome.org/show_bug.cgi?id=755617
-rw-r--r--libsoup/soup-auth-basic.c4
-rw-r--r--tests/auth-test.c12
-rw-r--r--tests/httpd.conf.22.in8
-rw-r--r--tests/httpd.conf.24.in8
4 files changed, 31 insertions, 1 deletions
diff --git a/libsoup/soup-auth-basic.c b/libsoup/soup-auth-basic.c
index f298e36c..f4b37173 100644
--- a/libsoup/soup-auth-basic.c
+++ b/libsoup/soup-auth-basic.c
@@ -75,7 +75,9 @@ soup_auth_basic_get_protection_space (SoupAuth *auth, SoupURI *source_uri)
/* Strip filename component */
p = strrchr (space, '/');
- if (p && p != space && p[1])
+ if (p == space && p[1])
+ p[1] = '\0';
+ else if (p && p[1])
*p = '\0';
return g_slist_prepend (NULL, space);
diff --git a/tests/auth-test.c b/tests/auth-test.c
index f69501e9..775c7f8d 100644
--- a/tests/auth-test.c
+++ b/tests/auth-test.c
@@ -1183,6 +1183,17 @@ static SoupAuthTest relogin_tests[] = {
{ NULL }
};
+/* https://bugzilla.gnome.org/show_bug.cgi?id=755617 */
+static SoupAuthTest basic_root_pspace_test[] = {
+ { "Auth provided via URL, should succeed",
+ "BasicRoot", "1", TRUE, "01", SOUP_STATUS_OK },
+
+ { "Parent dir should automatically reuse auth",
+ "/", "1", FALSE, "1", SOUP_STATUS_OK },
+
+ { NULL }
+};
+
static void
do_batch_tests (gconstpointer data)
{
@@ -1265,6 +1276,7 @@ main (int argc, char **argv)
g_test_add_data_func ("/auth/main-tests", main_tests, do_batch_tests);
g_test_add_data_func ("/auth/relogin-tests", relogin_tests, do_batch_tests);
+ g_test_add_data_func ("/auth/basic-root-pspec-test", basic_root_pspace_test, do_batch_tests);
g_test_add_func ("/auth/pipelined-auth", do_pipelined_auth_test);
g_test_add_func ("/auth/digest-expiration", do_digest_expiration_test);
g_test_add_func ("/auth/async-auth/good-password", do_async_auth_good_password_test);
diff --git a/tests/httpd.conf.22.in b/tests/httpd.conf.22.in
index b912ca36..06f2b38f 100644
--- a/tests/httpd.conf.22.in
+++ b/tests/httpd.conf.22.in
@@ -171,6 +171,7 @@ Alias /Basic/realm12 .
Alias /Basic/realm2 .
Alias /Basic/realm3 .
Alias /Basic .
+Alias /BasicRoot .
<Location /Basic/realm1>
AuthType Basic
@@ -221,6 +222,13 @@ Alias /Basic .
Require user user3
</Location>
+<Location /BasicRoot>
+ AuthType Basic
+ AuthName realm1
+ AuthUserFile ./htpasswd
+ Require user user1
+</Location>
+
# Digest auth tests
Alias /Digest/realm1/realm2/realm1 .
Alias /Digest/realm1/realm2 .
diff --git a/tests/httpd.conf.24.in b/tests/httpd.conf.24.in
index 850b8393..9d36d588 100644
--- a/tests/httpd.conf.24.in
+++ b/tests/httpd.conf.24.in
@@ -155,6 +155,7 @@ Alias /Basic/realm12 .
Alias /Basic/realm2 .
Alias /Basic/realm3 .
Alias /Basic .
+Alias /BasicRoot .
<Location /Basic/realm1>
AuthType Basic
@@ -205,6 +206,13 @@ Alias /Basic .
Require user user3
</Location>
+<Location /BasicRoot>
+ AuthType Basic
+ AuthName realm1
+ AuthUserFile ./htpasswd
+ Require user user1
+</Location>
+
# Digest auth tests
Alias /Digest/realm1/realm2/realm1 .
Alias /Digest/realm1/realm2 .