1 #include "clar_libgit2.h"
3 #include "git2/cred_helpers.h"
5 void test_network_cred__stock_userpass_validates_args(void)
7 git_credential_userpass_payload payload
= {0};
9 cl_git_fail(git_credential_userpass(NULL
, NULL
, NULL
, 0, NULL
));
11 payload
.username
= "user";
12 cl_git_fail(git_credential_userpass(NULL
, NULL
, NULL
, 0, &payload
));
14 payload
.username
= NULL
;
15 payload
.username
= "pass";
16 cl_git_fail(git_credential_userpass(NULL
, NULL
, NULL
, 0, &payload
));
19 void test_network_cred__stock_userpass_validates_that_method_is_allowed(void)
22 git_credential_userpass_payload payload
= {"user", "pass"};
24 cl_git_fail(git_credential_userpass(&cred
, NULL
, NULL
, 0, &payload
));
25 cl_git_pass(git_credential_userpass(&cred
, NULL
, NULL
, GIT_CREDENTIAL_USERPASS_PLAINTEXT
, &payload
));
26 git_credential_free(cred
);
29 void test_network_cred__stock_userpass_properly_handles_username_in_url(void)
32 git_credential_userpass_payload payload
= {"alice", "password"};
34 cl_git_pass(git_credential_userpass(&cred
, NULL
, NULL
, GIT_CREDENTIAL_USERPASS_PLAINTEXT
, &payload
));
35 cl_assert_equal_s("alice", git_credential_get_username(cred
));
36 git_credential_free(cred
);
38 cl_git_pass(git_credential_userpass(&cred
, NULL
, "bob", GIT_CREDENTIAL_USERPASS_PLAINTEXT
, &payload
));
39 cl_assert_equal_s("alice", git_credential_get_username(cred
));
40 git_credential_free(cred
);
42 payload
.username
= NULL
;
43 cl_git_pass(git_credential_userpass(&cred
, NULL
, "bob", GIT_CREDENTIAL_USERPASS_PLAINTEXT
, &payload
));
44 cl_assert_equal_s("bob", git_credential_get_username(cred
));
45 git_credential_free(cred
);