]>
Commit | Line | Data |
---|---|---|
1 | #include "clar_libgit2.h" | |
2 | ||
3 | #include "git2/cred_helpers.h" | |
4 | ||
5 | void test_network_cred__stock_userpass_validates_args(void) | |
6 | { | |
7 | git_credential_userpass_payload payload = {0}; | |
8 | ||
9 | cl_git_fail(git_credential_userpass(NULL, NULL, NULL, 0, NULL)); | |
10 | ||
11 | payload.username = "user"; | |
12 | cl_git_fail(git_credential_userpass(NULL, NULL, NULL, 0, &payload)); | |
13 | ||
14 | payload.username = NULL; | |
15 | payload.username = "pass"; | |
16 | cl_git_fail(git_credential_userpass(NULL, NULL, NULL, 0, &payload)); | |
17 | } | |
18 | ||
19 | void test_network_cred__stock_userpass_validates_that_method_is_allowed(void) | |
20 | { | |
21 | git_credential *cred; | |
22 | git_credential_userpass_payload payload = {"user", "pass"}; | |
23 | ||
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); | |
27 | } | |
28 | ||
29 | void test_network_cred__stock_userpass_properly_handles_username_in_url(void) | |
30 | { | |
31 | git_credential *cred; | |
32 | git_credential_userpass_payload payload = {"alice", "password"}; | |
33 | ||
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); | |
37 | ||
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); | |
41 | ||
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); | |
46 | } |