GNOME Bugzilla – Bug 631679
Credentials passed within URL's should always be taken into account for authentication
Last modified: 2010-11-14 16:57:42 UTC
Currently libsoup does not check the presence of credentials passed in the URLs if the session is currently authenticated. This way trying to login with different credentials when the session is already authenticated is not possible as libsoup will always use the currently authenticated SoupAuth. It'd be nice to allow relogin without having to deauthenticate.
Created attachment 171950 [details] [review] Allow relogin with URL credentials With this patch libsoup checks the presence of credentials in SoupMessage's SoupURI in authenticate_auth. If present it will try to authenticate using those credentials. This patch also updates the auth-test.c file. Some changes: * Added some tests for the re-login feature * Refactored some code. Now there is a do_batch_test method that runs both all the old auth tests plus the new tests for the re-login feature.
Comment on attachment 171950 [details] [review] Allow relogin with URL credentials >+ SoupURI *uri = soup_message_get_uri (msg); > >- if (soup_auth_is_authenticated (auth)) >+ if (soup_auth_is_authenticated (auth) && !uri->user && !uri->password) > return TRUE; > > if (proxy) { this is wrong, you're checking the message URI regardless of whether this is regular or proxy auth >-static int ntests = sizeof (tests) / sizeof (tests[0]); I'd say keep this, just have num_main_tests and num_relogin_tests. (Oh, and use G_N_ELEMENTS rather than sizeof/sizeof!) >+do_batch_tests (const gchar *base_uri, gint ntests) No gchar and gint please. Use char and int. >+ soup_uri = soup_message_get_uri (msg); >+ if (tests[i].url_auth) { >+ gchar *username = g_strdup_printf ("user%c", tests[i].provided[0]); >+ gchar *password = g_strdup_printf ("realm%c", tests[i].provided[0]); >+ soup_uri_set_user (soup_uri, username); >+ soup_uri_set_password (soup_uri, password); Um... no, don't change the SoupURI itself after creating the message. Create the URI the way you want it first, and then call soup_message_new/soup_message_new_with_uri using that. >+ tests = main_tests; >+ ntests = sizeof (main_tests) / sizeof (main_tests[0]); >+ do_batch_tests (base_uri, ntests); the gratuitous extra global variable seems unnecessary. Can't you just have do_batch_tests() take a SoupAuthTest* in addition to the base_uri and length? >+ >+ AuthType Basic >+ AuthName realm12 >+ AuthUserFile ./htpasswd >+ Require valid-user > </Proxy> This part is for proxy auth... I don't think your test requires allowing realm12 there.
Created attachment 174343 [details] [review] Allow relogin with URL credentials
ok, I changed the soup-auth-manager part a little bit more, verified that it still passed your tests, and then committed the tests as is. Thanks for the patch (and especially the tests)
*** Bug 625854 has been marked as a duplicate of this bug. ***