|
| 1 | +#include "clar_libgit2.h" |
| 2 | + |
| 3 | +#include "path.h" |
| 4 | +#include "git2/clone.h" |
| 5 | +#include "git2/cred_helpers.h" |
| 6 | +#include "remote.h" |
| 7 | +#include "futils.h" |
| 8 | +#include "refs.h" |
| 9 | + |
| 10 | +/* |
| 11 | + * Certificate one is in the `certs` folder; certificate two is in the |
| 12 | + * `self-signed.pem` file. |
| 13 | + */ |
| 14 | +#define CUSTOM_CERT_ONE_URL "https://test.libgit2.org:1443/anonymous/test.git" |
| 15 | +#define CUSTOM_CERT_ONE_PATH "certs" |
| 16 | + |
| 17 | +#define CUSTOM_CERT_TWO_URL "https://test.libgit2.org:2443/anonymous/test.git" |
| 18 | +#define CUSTOM_CERT_TWO_FILE "self-signed.pem" |
| 19 | + |
| 20 | +#if (GIT_OPENSSL || GIT_MBEDTLS) |
| 21 | +static git_repository *g_repo; |
| 22 | +static int initialized = false; |
| 23 | +#endif |
| 24 | + |
| 25 | +void test_online_customcert__initialize(void) |
| 26 | +{ |
| 27 | +#if (GIT_OPENSSL || GIT_MBEDTLS) |
| 28 | + g_repo = NULL; |
| 29 | + |
| 30 | + if (!initialized) { |
| 31 | + git_buf path = GIT_BUF_INIT, file = GIT_BUF_INIT; |
| 32 | + char cwd[GIT_PATH_MAX]; |
| 33 | + |
| 34 | + cl_fixture_sandbox(CUSTOM_CERT_ONE_PATH); |
| 35 | + cl_fixture_sandbox(CUSTOM_CERT_TWO_FILE); |
| 36 | + |
| 37 | + cl_must_pass(p_getcwd(cwd, GIT_PATH_MAX)); |
| 38 | + cl_git_pass(git_buf_joinpath(&path, cwd, CUSTOM_CERT_ONE_PATH)); |
| 39 | + cl_git_pass(git_buf_joinpath(&file, cwd, CUSTOM_CERT_TWO_FILE)); |
| 40 | + |
| 41 | + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, |
| 42 | + file.ptr, path.ptr)); |
| 43 | + initialized = true; |
| 44 | + |
| 45 | + git_buf_dispose(&file); |
| 46 | + git_buf_dispose(&path); |
| 47 | + } |
| 48 | +#endif |
| 49 | +} |
| 50 | + |
| 51 | +void test_online_customcert__cleanup(void) |
| 52 | +{ |
| 53 | +#if (GIT_OPENSSL || GIT_MBEDTLS) |
| 54 | + if (g_repo) { |
| 55 | + git_repository_free(g_repo); |
| 56 | + g_repo = NULL; |
| 57 | + } |
| 58 | + |
| 59 | + cl_fixture_cleanup("./cloned"); |
| 60 | + cl_fixture_cleanup(CUSTOM_CERT_ONE_PATH); |
| 61 | + cl_fixture_cleanup(CUSTOM_CERT_TWO_FILE); |
| 62 | +#endif |
| 63 | +} |
| 64 | + |
| 65 | +void test_online_customcert__file(void) |
| 66 | +{ |
| 67 | +#if (GIT_OPENSSL || GIT_MBEDTLS) |
| 68 | + cl_git_pass(git_clone(&g_repo, CUSTOM_CERT_ONE_URL, "./cloned", NULL)); |
| 69 | + cl_assert(git_path_exists("./cloned/master.txt")); |
| 70 | +#endif |
| 71 | +} |
| 72 | + |
| 73 | +void test_online_customcert__path(void) |
| 74 | +{ |
| 75 | +#if (GIT_OPENSSL || GIT_MBEDTLS) |
| 76 | + cl_git_pass(git_clone(&g_repo, CUSTOM_CERT_TWO_URL, "./cloned", NULL)); |
| 77 | + cl_assert(git_path_exists("./cloned/master.txt")); |
| 78 | +#endif |
| 79 | +} |
0 commit comments