[libsoup] soup-auth-basic: Correctly handle the protection space for subdirectories of root dir



commit c6c95600f00d36d6e1c76e2f6bc6286019de0688
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Fri Sep 25 11:14:09 2015 +0200

    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

 libsoup/soup-auth-basic.c |    4 +++-
 tests/auth-test.c         |   12 ++++++++++++
 tests/httpd.conf.22.in    |    8 ++++++++
 tests/httpd.conf.24.in    |    8 ++++++++
 4 files changed, 31 insertions(+), 1 deletions(-)
---
diff --git a/libsoup/soup-auth-basic.c b/libsoup/soup-auth-basic.c
index f298e36..f4b3717 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 f69501e..775c7f8 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 b912ca3..06f2b38 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 850b839..9d36d58 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 .


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]