@@ -357,15 +357,45 @@ void test_online_clone__bitbucket_style(void)
357357 cl_git_pass (git_clone (& g_repo , BB_REPO_URL , "./foo" , & g_options ));
358358 git_repository_free (g_repo ); g_repo = NULL ;
359359 cl_fixture_cleanup ("./foo" );
360+ }
361+
362+ void test_online_clone__bitbucket_uses_creds_in_url (void )
363+ {
364+ git_cred_userpass_payload user_pass = {
365+ "libgit2" , "wrong"
366+ };
367+
368+ g_options .fetch_opts .callbacks .credentials = git_cred_userpass ;
369+ g_options .fetch_opts .callbacks .payload = & user_pass ;
360370
361- /* User and pass from URL */
362- user_pass .password = "wrong" ;
371+ /*
372+ * Correct user and pass are in the URL; the (incorrect) creds in
373+ * the `git_cred_userpass_payload` should be ignored.
374+ */
363375 cl_git_pass (git_clone (& g_repo , BB_REPO_URL_WITH_PASS , "./foo" , & g_options ));
364376 git_repository_free (g_repo ); g_repo = NULL ;
365377 cl_fixture_cleanup ("./foo" );
378+ }
379+
380+ void test_online_clone__bitbucket_falls_back_to_specified_creds (void )
381+ {
382+ git_cred_userpass_payload user_pass = {
383+ "libgit2" , "libgit2"
384+ };
385+
386+ g_options .fetch_opts .callbacks .credentials = git_cred_userpass ;
387+ g_options .fetch_opts .callbacks .payload = & user_pass ;
388+
389+ /*
390+ * TODO: as of March 2018, bitbucket sporadically fails with
391+ * 403s instead of replying with a 401 - but only sometimes.
392+ */
393+ cl_skip ();
366394
367- /* Wrong password in URL, fall back to user_pass */
368- user_pass .password = "libgit2" ;
395+ /*
396+ * Incorrect user and pass are in the URL; the (correct) creds in
397+ * the `git_cred_userpass_payload` should be used as a fallback.
398+ */
369399 cl_git_pass (git_clone (& g_repo , BB_REPO_URL_WITH_WRONG_PASS , "./foo" , & g_options ));
370400 git_repository_free (g_repo ); g_repo = NULL ;
371401 cl_fixture_cleanup ("./foo" );
0 commit comments