Commit a79cc76f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

https: fix proxy URL parsing, improve coverage

parent 8a9a8d9f
......@@ -125,11 +125,11 @@ vlc_tls_t *vlc_https_connect_proxy(vlc_tls_creds_t *creds,
vlc_tls_t *session = NULL;
bool ptwo = false;
#if TLS_OVER_TLS
if (strcasecmp(url.psz_protocol, "https"))
if (!strcasecmp(url.psz_protocol, "https"))
session = vlc_https_connect(creds, url.psz_host, url.i_port, &ptwo);
else
#endif
if (strcasecmp(url.psz_protocol, "http"))
if (!strcasecmp(url.psz_protocol, "http"))
session = vlc_http_connect(creds ? creds->p_parent : NULL,
url.psz_host, url.i_port);
else
......
......@@ -99,11 +99,11 @@ static void *proxy_thread(void *data)
vlc_assert_unreachable();
}
int main(void)
static int server_socket(unsigned *port)
{
int lfd = socket(PF_INET6, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP);
if (lfd == -1)
return 77;
int fd = socket(PF_INET6, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP);
if (fd == -1)
return -1;
struct sockaddr_in6 addr = {
.sin6_family = AF_INET6,
......@@ -114,27 +114,53 @@ int main(void)
};
socklen_t addrlen = sizeof (addr);
if (bind(lfd, (struct sockaddr *)&addr, addrlen)
|| listen(lfd, 255))
if (bind(fd, (struct sockaddr *)&addr, addrlen)
|| getsockname(fd, &addr, &addrlen))
{
close(lfd);
return 77;
close(fd);
return -1;
}
*port = ntohs(addr.sin6_port);
return fd;
}
int main(void)
{
char *url;
unsigned port;
bool two;
getsockname(lfd, &addr, &addrlen);
if (asprintf(&url, "https://[::1]:%u", ntohs(addr.sin6_port)) < 0)
/* Test bad URLs */
vlc_https_connect_proxy(NULL, "www.example.com", 0, &two,
"/test");
vlc_https_connect_proxy(NULL, "www.example.com", 0, &two,
"ftp://proxy.example.com/");
int lfd = server_socket(&port);
if (lfd == -1)
return 77;
if (asprintf(&url, "http://[::1]:%u", port) < 0)
url = NULL;
assert(url != NULL);
vlc_thread_t th;
/* Test connection failure */
vlc_https_connect_proxy(NULL, "www.example.com", 0, &two, url);
if (listen(lfd, 255))
{
close(lfd);
return 77;
}
vlc_thread_t th;
if (vlc_clone(&th, proxy_thread, (void*)(intptr_t)lfd,
VLC_THREAD_PRIORITY_LOW))
assert(!"Thread error");
/* Test proxy error */
vlc_https_connect_proxy(NULL, "www.example.com", 0, &two, url);
vlc_cancel(th);
......
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