Commit fba14763 by Vicent Martí

Merge pull request #1879 from libgit2/redir-refactor

Redir refactor
parents a6884b6f b59344bf
...@@ -573,6 +573,83 @@ int gitno_select_in(gitno_buffer *buf, long int sec, long int usec) ...@@ -573,6 +573,83 @@ int gitno_select_in(gitno_buffer *buf, long int sec, long int usec)
return select((int)buf->socket->socket + 1, &fds, NULL, NULL, &tv); return select((int)buf->socket->socket + 1, &fds, NULL, NULL, &tv);
} }
static const char *prefix_http = "http://";
static const char *prefix_https = "https://";
int gitno_connection_data_from_url(
gitno_connection_data *data,
const char *url,
const char *service_suffix)
{
int error = -1;
const char *default_port = NULL;
char *original_host = NULL;
/* service_suffix is optional */
assert(data && url);
/* Save these for comparison later */
original_host = data->host;
data->host = NULL;
gitno_connection_data_free_ptrs(data);
if (!git__prefixcmp(url, prefix_http)) {
url = url + strlen(prefix_http);
default_port = "80";
if (data->use_ssl) {
giterr_set(GITERR_NET, "Redirect from HTTPS to HTTP is not allowed");
goto cleanup;
}
}
if (!git__prefixcmp(url, prefix_https)) {
url += strlen(prefix_https);
default_port = "443";
data->use_ssl = true;
}
if (!default_port) {
giterr_set(GITERR_NET, "Unrecognized URL prefix");
goto cleanup;
}
error = gitno_extract_url_parts(
&data->host, &data->port, &data->user, &data->pass,
url, default_port);
if (!error) {
const char *path = strchr(url, '/');
size_t pathlen = strlen(path);
size_t suffixlen = service_suffix ? strlen(service_suffix) : 0;
if (suffixlen &&
!memcmp(path + pathlen - suffixlen, service_suffix, suffixlen))
data->path = git__strndup(path, pathlen - suffixlen);
else
data->path = git__strdup(path);
/* Check for errors in the resulting data */
if (original_host && url[0] != '/' && strcmp(original_host, data->host)) {
giterr_set(GITERR_NET, "Cross host redirect not allowed");
error = -1;
}
}
cleanup:
if (original_host) git__free(original_host);
return error;
}
void gitno_connection_data_free_ptrs(gitno_connection_data *d)
{
git__free(d->host); d->host = NULL;
git__free(d->port); d->port = NULL;
git__free(d->path); d->path = NULL;
git__free(d->user); d->user = NULL;
git__free(d->pass); d->pass = NULL;
}
int gitno_extract_url_parts( int gitno_extract_url_parts(
char **host, char **host,
char **port, char **port,
......
...@@ -66,6 +66,29 @@ int gitno_send(gitno_socket *socket, const char *msg, size_t len, int flags); ...@@ -66,6 +66,29 @@ int gitno_send(gitno_socket *socket, const char *msg, size_t len, int flags);
int gitno_close(gitno_socket *s); int gitno_close(gitno_socket *s);
int gitno_select_in(gitno_buffer *buf, long int sec, long int usec); int gitno_select_in(gitno_buffer *buf, long int sec, long int usec);
typedef struct gitno_connection_data {
char *host;
char *port;
char *path;
char *user;
char *pass;
bool use_ssl;
} gitno_connection_data;
/*
* This replaces all the pointers in `data` with freshly-allocated strings,
* that the caller is responsible for freeing.
* `gitno_connection_data_free_ptrs` is good for this.
*/
int gitno_connection_data_from_url(
gitno_connection_data *data,
const char *url,
const char *service_suffix);
/* This frees all the pointers IN the struct, but not the struct itself. */
void gitno_connection_data_free_ptrs(gitno_connection_data *data);
int gitno_extract_url_parts( int gitno_extract_url_parts(
char **host, char **host,
char **port, char **port,
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
#include "netops.h" #include "netops.h"
#include "smart.h" #include "smart.h"
static const char *prefix_http = "http://";
static const char *prefix_https = "https://";
static const char *upload_pack_service = "upload-pack"; static const char *upload_pack_service = "upload-pack";
static const char *upload_pack_ls_service_url = "/info/refs?service=git-upload-pack"; static const char *upload_pack_ls_service_url = "/info/refs?service=git-upload-pack";
static const char *upload_pack_service_url = "/git-upload-pack"; static const char *upload_pack_service_url = "/git-upload-pack";
...@@ -59,16 +57,11 @@ typedef struct { ...@@ -59,16 +57,11 @@ typedef struct {
git_smart_subtransport parent; git_smart_subtransport parent;
transport_smart *owner; transport_smart *owner;
gitno_socket socket; gitno_socket socket;
char *path; gitno_connection_data connection_data;
char *host;
char *port;
char *user_from_url;
char *pass_from_url;
git_cred *cred; git_cred *cred;
git_cred *url_cred; git_cred *url_cred;
http_authmechanism_t auth_mechanism; http_authmechanism_t auth_mechanism;
unsigned connected : 1, bool connected;
use_ssl : 1;
/* Parser structures */ /* Parser structures */
http_parser parser; http_parser parser;
...@@ -125,12 +118,12 @@ static int gen_request( ...@@ -125,12 +118,12 @@ static int gen_request(
size_t content_length) size_t content_length)
{ {
http_subtransport *t = OWNING_SUBTRANSPORT(s); http_subtransport *t = OWNING_SUBTRANSPORT(s);
const char *path = t->path ? t->path : "/"; const char *path = t->connection_data.path ? t->connection_data.path : "/";
git_buf_printf(buf, "%s %s%s HTTP/1.1\r\n", s->verb, path, s->service_url); git_buf_printf(buf, "%s %s%s HTTP/1.1\r\n", s->verb, path, s->service_url);
git_buf_puts(buf, "User-Agent: git/1.0 (libgit2 " LIBGIT2_VERSION ")\r\n"); git_buf_puts(buf, "User-Agent: git/1.0 (libgit2 " LIBGIT2_VERSION ")\r\n");
git_buf_printf(buf, "Host: %s\r\n", t->host); git_buf_printf(buf, "Host: %s\r\n", t->connection_data.host);
if (s->chunked || content_length > 0) { if (s->chunked || content_length > 0) {
git_buf_printf(buf, "Accept: application/x-git-%s-result\r\n", s->service); git_buf_printf(buf, "Accept: application/x-git-%s-result\r\n", s->service);
...@@ -150,9 +143,9 @@ static int gen_request( ...@@ -150,9 +143,9 @@ static int gen_request(
return -1; return -1;
/* Use url-parsed basic auth if username and password are both provided */ /* Use url-parsed basic auth if username and password are both provided */
if (!t->cred && t->user_from_url && t->pass_from_url) { if (!t->cred && t->connection_data.user && t->connection_data.pass) {
if (!t->url_cred && if (!t->url_cred && git_cred_userpass_plaintext_new(&t->url_cred,
git_cred_userpass_plaintext_new(&t->url_cred, t->user_from_url, t->pass_from_url) < 0) t->connection_data.user, t->connection_data.pass) < 0)
return -1; return -1;
if (apply_basic_credential(buf, t->url_cred) < 0) return -1; if (apply_basic_credential(buf, t->url_cred) < 0) return -1;
} }
...@@ -249,98 +242,6 @@ static int on_header_value(http_parser *parser, const char *str, size_t len) ...@@ -249,98 +242,6 @@ static int on_header_value(http_parser *parser, const char *str, size_t len)
return 0; return 0;
} }
static void free_connection_data(http_subtransport *t)
{
if (t->host) {
git__free(t->host);
t->host = NULL;
}
if (t->port) {
git__free(t->port);
t->port = NULL;
}
if (t->user_from_url) {
git__free(t->user_from_url);
t->user_from_url = NULL;
}
if (t->pass_from_url) {
git__free(t->pass_from_url);
t->pass_from_url = NULL;
}
if (t->path) {
git__free(t->path);
t->path = NULL;
}
}
static int set_connection_data_from_url(
http_subtransport *t, const char *url, const char *service_suffix)
{
int error = 0;
const char *default_port = NULL;
char *original_host = NULL;
if (!git__prefixcmp(url, prefix_http)) {
url = url + strlen(prefix_http);
default_port = "80";
if (t->use_ssl) {
giterr_set(GITERR_NET, "Redirect from HTTPS to HTTP not allowed");
return -1;
}
}
if (!git__prefixcmp(url, prefix_https)) {
url += strlen(prefix_https);
default_port = "443";
t->use_ssl = 1;
}
if (!default_port) {
giterr_set(GITERR_NET, "Unrecognized URL prefix");
return -1;
}
/* preserve original host name for checking */
original_host = t->host;
t->host = NULL;
free_connection_data(t);
error = gitno_extract_url_parts(
&t->host, &t->port, &t->user_from_url, &t->pass_from_url,
url, default_port);
if (!error) {
const char *path = strchr(url, '/');
size_t pathlen = strlen(path);
size_t suffixlen = service_suffix ? strlen(service_suffix) : 0;
if (suffixlen &&
!memcmp(path + pathlen - suffixlen, service_suffix, suffixlen))
t->path = git__strndup(path, pathlen - suffixlen);
else
t->path = git__strdup(path);
/* Allow '/'-led urls, or a change of protocol */
if (original_host != NULL) {
if (strcmp(original_host, t->host) && t->location[0] != '/') {
giterr_set(GITERR_NET, "Cross host redirect not allowed");
error = -1;
}
git__free(original_host);
}
}
return error;
}
static int on_headers_complete(http_parser *parser) static int on_headers_complete(http_parser *parser)
{ {
parser_context *ctx = (parser_context *) parser->data; parser_context *ctx = (parser_context *) parser->data;
...@@ -369,7 +270,7 @@ static int on_headers_complete(http_parser *parser) ...@@ -369,7 +270,7 @@ static int on_headers_complete(http_parser *parser)
if (t->owner->cred_acquire_cb(&t->cred, if (t->owner->cred_acquire_cb(&t->cred,
t->owner->url, t->owner->url,
t->user_from_url, t->connection_data.user,
allowed_types, allowed_types,
t->owner->cred_acquire_payload) < 0) t->owner->cred_acquire_payload) < 0)
return PARSE_ERROR_GENERIC; return PARSE_ERROR_GENERIC;
...@@ -394,7 +295,7 @@ static int on_headers_complete(http_parser *parser) ...@@ -394,7 +295,7 @@ static int on_headers_complete(http_parser *parser)
return t->parse_error = PARSE_ERROR_GENERIC; return t->parse_error = PARSE_ERROR_GENERIC;
} }
if (set_connection_data_from_url(t, t->location, s->service_url) < 0) if (gitno_connection_data_from_url(&t->connection_data, t->location, s->service_url) < 0)
return t->parse_error = PARSE_ERROR_GENERIC; return t->parse_error = PARSE_ERROR_GENERIC;
/* Set the redirect URL on the stream. This is a transfer of /* Set the redirect URL on the stream. This is a transfer of
...@@ -552,7 +453,7 @@ static int http_connect(http_subtransport *t) ...@@ -552,7 +453,7 @@ static int http_connect(http_subtransport *t)
if (t->socket.socket) if (t->socket.socket)
gitno_close(&t->socket); gitno_close(&t->socket);
if (t->use_ssl) { if (t->connection_data.use_ssl) {
int tflags; int tflags;
if (t->owner->parent.read_flags(&t->owner->parent, &tflags) < 0) if (t->owner->parent.read_flags(&t->owner->parent, &tflags) < 0)
...@@ -564,7 +465,7 @@ static int http_connect(http_subtransport *t) ...@@ -564,7 +465,7 @@ static int http_connect(http_subtransport *t)
flags |= GITNO_CONNECT_SSL_NO_CHECK_CERT; flags |= GITNO_CONNECT_SSL_NO_CHECK_CERT;
} }
if (gitno_connect(&t->socket, t->host, t->port, flags) < 0) if (gitno_connect(&t->socket, t->connection_data.host, t->connection_data.port, flags) < 0)
return -1; return -1;
t->connected = 1; t->connected = 1;
...@@ -911,10 +812,9 @@ static int http_action( ...@@ -911,10 +812,9 @@ static int http_action(
if (!stream) if (!stream)
return -1; return -1;
if (!t->host || !t->port || !t->path) { if ((!t->connection_data.host || !t->connection_data.port || !t->connection_data.path) &&
if ((ret = set_connection_data_from_url(t, url, NULL)) < 0) (ret = gitno_connection_data_from_url(&t->connection_data, url, NULL)) < 0)
return ret; return ret;
}
if (http_connect(t) < 0) if (http_connect(t) < 0)
return -1; return -1;
...@@ -958,7 +858,7 @@ static int http_close(git_smart_subtransport *subtransport) ...@@ -958,7 +858,7 @@ static int http_close(git_smart_subtransport *subtransport)
t->url_cred = NULL; t->url_cred = NULL;
} }
free_connection_data(t); gitno_connection_data_free_ptrs(&t->connection_data);
return 0; return 0;
} }
......
...@@ -73,17 +73,12 @@ typedef struct { ...@@ -73,17 +73,12 @@ typedef struct {
typedef struct { typedef struct {
git_smart_subtransport parent; git_smart_subtransport parent;
transport_smart *owner; transport_smart *owner;
char *path; gitno_connection_data connection_data;
char *host;
char *port;
char *user_from_url;
char *pass_from_url;
git_cred *cred; git_cred *cred;
git_cred *url_cred; git_cred *url_cred;
int auth_mechanism; int auth_mechanism;
HINTERNET session; HINTERNET session;
HINTERNET connection; HINTERNET connection;
unsigned use_ssl : 1;
} winhttp_subtransport; } winhttp_subtransport;
static int apply_basic_credential(HINTERNET request, git_cred *cred) static int apply_basic_credential(HINTERNET request, git_cred *cred)
...@@ -155,7 +150,7 @@ static int winhttp_stream_connect(winhttp_stream *s) ...@@ -155,7 +150,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
unsigned long disable_redirects = WINHTTP_DISABLE_REDIRECTS; unsigned long disable_redirects = WINHTTP_DISABLE_REDIRECTS;
/* Prepare URL */ /* Prepare URL */
git_buf_printf(&buf, "%s%s", t->path, s->service_url); git_buf_printf(&buf, "%s%s", t->connection_data.path, s->service_url);
if (git_buf_oom(&buf)) if (git_buf_oom(&buf))
return -1; return -1;
...@@ -188,7 +183,7 @@ static int winhttp_stream_connect(winhttp_stream *s) ...@@ -188,7 +183,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
NULL, NULL,
WINHTTP_NO_REFERER, WINHTTP_NO_REFERER,
types, types,
t->use_ssl ? WINHTTP_FLAG_SECURE : 0); t->connection_data.use_ssl ? WINHTTP_FLAG_SECURE : 0);
if (!s->request) { if (!s->request) {
giterr_set(GITERR_OS, "Failed to open request"); giterr_set(GITERR_OS, "Failed to open request");
...@@ -196,7 +191,7 @@ static int winhttp_stream_connect(winhttp_stream *s) ...@@ -196,7 +191,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
} }
/* Set proxy if necessary */ /* Set proxy if necessary */
if (git_remote__get_http_proxy(t->owner->owner, !!t->use_ssl, &proxy_url) < 0) if (git_remote__get_http_proxy(t->owner->owner, !!t->connection_data.use_ssl, &proxy_url) < 0)
goto on_error; goto on_error;
if (proxy_url) { if (proxy_url) {
...@@ -285,7 +280,7 @@ static int winhttp_stream_connect(winhttp_stream *s) ...@@ -285,7 +280,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
} }
/* If requested, disable certificate validation */ /* If requested, disable certificate validation */
if (t->use_ssl) { if (t->connection_data.use_ssl) {
int flags; int flags;
if (t->owner->parent.read_flags(&t->owner->parent, &flags) < 0) if (t->owner->parent.read_flags(&t->owner->parent, &flags) < 0)
...@@ -308,9 +303,9 @@ static int winhttp_stream_connect(winhttp_stream *s) ...@@ -308,9 +303,9 @@ static int winhttp_stream_connect(winhttp_stream *s)
/* If no other credentials have been applied and the URL has username and /* If no other credentials have been applied and the URL has username and
* password, use those */ * password, use those */
if (!t->cred && t->user_from_url && t->pass_from_url) { if (!t->cred && t->connection_data.user && t->connection_data.pass) {
if (!t->url_cred && if (!t->url_cred &&
git_cred_userpass_plaintext_new(&t->url_cred, t->user_from_url, t->pass_from_url) < 0) git_cred_userpass_plaintext_new(&t->url_cred, t->connection_data.user, t->connection_data.pass) < 0)
goto on_error; goto on_error;
if (apply_basic_credential(s->request, t->url_cred) < 0) if (apply_basic_credential(s->request, t->url_cred) < 0)
goto on_error; goto on_error;
...@@ -392,98 +387,6 @@ static int write_chunk(HINTERNET request, const char *buffer, size_t len) ...@@ -392,98 +387,6 @@ static int write_chunk(HINTERNET request, const char *buffer, size_t len)
return 0; return 0;
} }
static void free_connection_data(winhttp_subtransport *t)
{
if (t->host) {
git__free(t->host);
t->host = NULL;
}
if (t->port) {
git__free(t->port);
t->port = NULL;
}
if (t->user_from_url) {
git__free(t->user_from_url);
t->user_from_url = NULL;
}
if (t->pass_from_url) {
git__free(t->pass_from_url);
t->pass_from_url = NULL;
}
if (t->path) {
git__free(t->path);
t->path = NULL;
}
}
static int set_connection_data_from_url(
winhttp_subtransport *t, const char *url, const char *service_suffix)
{
int error = 0;
const char *default_port = NULL;
char *original_host = NULL;
const char *original_url = url;
if (!git__prefixcmp(url, prefix_http)) {
url += strlen(prefix_http);
default_port = "80";
if (t->use_ssl) {
giterr_set(GITERR_NET, "Redirect from HTTPS to HTTP not allowed");
return -1;
}
}
if (!git__prefixcmp(url, prefix_https)) {
url += strlen(prefix_https);
default_port = "443";
t->use_ssl = 1;
}
if (!default_port) {
giterr_set(GITERR_NET, "Unrecognized URL prefix");
return -1;
}
/* preserve original host name for checking */
original_host = t->host;
t->host = NULL;
free_connection_data(t);
error = gitno_extract_url_parts(
&t->host, &t->port, &t->user_from_url, &t->pass_from_url,
url, default_port);
if (!error) {
const char *path = strchr(url, '/');
size_t pathlen = strlen(path);
size_t suffixlen = service_suffix ? strlen(service_suffix) : 0;
if (suffixlen &&
!memcmp(path + pathlen - suffixlen, service_suffix, suffixlen))
t->path = git__strndup(path, pathlen - suffixlen);
else
t->path = git__strdup(path);
/* Allow '/'-led urls, or a change of protocol */
if (original_host != NULL) {
if (strcmp(original_host, t->host) && original_url[0] != '/') {
giterr_set(GITERR_NET, "Cross host redirect not allowed");
error = -1;
}
git__free(original_host);
}
}
return error;
}
static int winhttp_connect( static int winhttp_connect(
winhttp_subtransport *t, winhttp_subtransport *t,
const char *url) const char *url)
...@@ -494,11 +397,11 @@ static int winhttp_connect( ...@@ -494,11 +397,11 @@ static int winhttp_connect(
const char *default_port = "80"; const char *default_port = "80";
/* Prepare port */ /* Prepare port */
if (git__strtol32(&port, t->port, NULL, 10) < 0) if (git__strtol32(&port, t->connection_data.port, NULL, 10) < 0)
return -1; return -1;
/* Prepare host */ /* Prepare host */
git_win32_path_from_c(host, t->host); git_win32_path_from_c(host, t->connection_data.host);
/* Establish session */ /* Establish session */
t->session = WinHttpOpen( t->session = WinHttpOpen(
...@@ -699,7 +602,8 @@ replay: ...@@ -699,7 +602,8 @@ replay:
if (!git__prefixcmp_icase(location8, prefix_https)) { if (!git__prefixcmp_icase(location8, prefix_https)) {
/* Upgrade to secure connection; disconnect and start over */ /* Upgrade to secure connection; disconnect and start over */
set_connection_data_from_url(t, location8, s->service_url); if (gitno_connection_data_from_url(&t->connection_data, location8, s->service_url) < 0)
return -1;
winhttp_connect(t, location8); winhttp_connect(t, location8);
} }
...@@ -718,7 +622,8 @@ replay: ...@@ -718,7 +622,8 @@ replay:
if (allowed_types && if (allowed_types &&
(!t->cred || 0 == (t->cred->credtype & allowed_types))) { (!t->cred || 0 == (t->cred->credtype & allowed_types))) {
if (t->owner->cred_acquire_cb(&t->cred, t->owner->url, t->user_from_url, allowed_types, t->owner->cred_acquire_payload) < 0) if (t->owner->cred_acquire_cb(&t->cred, t->owner->url, t->connection_data.user, allowed_types,
t->owner->cred_acquire_payload) < 0)
return -1; return -1;
assert(t->cred); assert(t->cred);
...@@ -1101,9 +1006,9 @@ static int winhttp_action( ...@@ -1101,9 +1006,9 @@ static int winhttp_action(
winhttp_stream *s; winhttp_stream *s;
int ret = -1; int ret = -1;
if (!t->connection && if (!t->connection)
(set_connection_data_from_url(t, url, NULL) < 0 || if (gitno_connection_data_from_url(&t->connection_data, url, NULL) < 0 ||
winhttp_connect(t, url) < 0)) winhttp_connect(t, url) < 0)
return -1; return -1;
if (winhttp_stream_alloc(t, &s) < 0) if (winhttp_stream_alloc(t, &s) < 0)
...@@ -1145,7 +1050,7 @@ static int winhttp_close(git_smart_subtransport *subtransport) ...@@ -1145,7 +1050,7 @@ static int winhttp_close(git_smart_subtransport *subtransport)
winhttp_subtransport *t = (winhttp_subtransport *)subtransport; winhttp_subtransport *t = (winhttp_subtransport *)subtransport;
int ret = 0; int ret = 0;
free_connection_data(t); gitno_connection_data_free_ptrs(&t->connection_data);
if (t->cred) { if (t->cred) {
t->cred->free(t->cred); t->cred->free(t->cred);
......
...@@ -2,10 +2,12 @@ ...@@ -2,10 +2,12 @@
#include "netops.h" #include "netops.h"
char *host, *port, *user, *pass; char *host, *port, *user, *pass;
gitno_connection_data conndata;
void test_network_urlparse__initialize(void) void test_network_urlparse__initialize(void)
{ {
host = port = user = pass = NULL; host = port = user = pass = NULL;
memset(&conndata, 0, sizeof(conndata));
} }
void test_network_urlparse__cleanup(void) void test_network_urlparse__cleanup(void)
...@@ -15,6 +17,8 @@ void test_network_urlparse__cleanup(void) ...@@ -15,6 +17,8 @@ void test_network_urlparse__cleanup(void)
FREE_AND_NULL(port); FREE_AND_NULL(port);
FREE_AND_NULL(user); FREE_AND_NULL(user);
FREE_AND_NULL(pass); FREE_AND_NULL(pass);
gitno_connection_data_free_ptrs(&conndata);
} }
void test_network_urlparse__trivial(void) void test_network_urlparse__trivial(void)
...@@ -80,3 +84,52 @@ void test_network_urlparse__user_pass_port(void) ...@@ -80,3 +84,52 @@ void test_network_urlparse__user_pass_port(void)
cl_assert_equal_s(user, "user"); cl_assert_equal_s(user, "user");
cl_assert_equal_s(pass, "pass"); cl_assert_equal_s(pass, "pass");
} }
void test_network_urlparse__connection_data_http(void)
{
cl_git_pass(gitno_connection_data_from_url(&conndata,
"http://example.com/foo/bar/baz", "bar/baz"));
cl_assert_equal_s(conndata.host, "example.com");
cl_assert_equal_s(conndata.port, "80");
cl_assert_equal_s(conndata.path, "/foo/");
cl_assert_equal_p(conndata.user, NULL);
cl_assert_equal_p(conndata.pass, NULL);
cl_assert_equal_i(conndata.use_ssl, false);
}
void test_network_urlparse__connection_data_ssl(void)
{
cl_git_pass(gitno_connection_data_from_url(&conndata,
"https://example.com/foo/bar/baz", "bar/baz"));
cl_assert_equal_s(conndata.host, "example.com");
cl_assert_equal_s(conndata.port, "443");
cl_assert_equal_s(conndata.path, "/foo/");
cl_assert_equal_p(conndata.user, NULL);
cl_assert_equal_p(conndata.pass, NULL);
cl_assert_equal_i(conndata.use_ssl, true);
}
void test_network_urlparse__connection_data_cross_host_redirect(void)
{
conndata.host = git__strdup("bar.com");
cl_git_fail_with(gitno_connection_data_from_url(&conndata,
"https://foo.com/bar/baz", NULL),
-1);
}
void test_network_urlparse__connection_data_http_downgrade(void)
{
conndata.use_ssl = true;
cl_git_fail_with(gitno_connection_data_from_url(&conndata,
"http://foo.com/bar/baz", NULL),
-1);
}
/* Run this under valgrind */
void test_network_urlparse__connection_data_cleanup(void)
{
cl_git_pass(gitno_connection_data_from_url(&conndata,
"http://foo.com/bar/baz/biff", "baz/biff"));
cl_git_pass(gitno_connection_data_from_url(&conndata,
"https://foo.com/bar/baz/biff", "baz/biff"));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment