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