|
|
|
|
@ -6,6 +6,7 @@
|
|
|
|
|
#include "../lib/socket_compat.h" |
|
|
|
|
#include "../lib/platform_compat.h" |
|
|
|
|
#include "test_clock.h" |
|
|
|
|
#include "test_net.h" |
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
@ -15,8 +16,6 @@ static int test_failed = 0;
|
|
|
|
|
if (!(cond)) { DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, " FAIL: %s", #cond); test_failed = 1; return test_failed; } \
|
|
|
|
|
} while(0) |
|
|
|
|
|
|
|
|
|
#define MOCK_PORT 24771 |
|
|
|
|
|
|
|
|
|
enum { MOCK_NOAUTH = 0, MOCK_AUTH = 1, MOCK_REJECT = 2 }; |
|
|
|
|
|
|
|
|
|
struct mock { |
|
|
|
|
@ -324,9 +323,9 @@ static int run_dial(struct UASYNC *ua, struct socks_cfg *cfg, const char *target
|
|
|
|
|
static int test1_noauth_v4(void) { |
|
|
|
|
struct UASYNC *ua = uasync_create(); TASSERT(ua); |
|
|
|
|
struct mock m; |
|
|
|
|
TASSERT(mock_start(&m, ua, MOCK_PORT, MOCK_NOAUTH) == 0); |
|
|
|
|
TASSERT(mock_start(&m, ua, 0, MOCK_NOAUTH) == 0); |
|
|
|
|
struct socks_cfg cfg; memset(&cfg, 0, sizeof(cfg)); |
|
|
|
|
strcpy(cfg.host, "127.0.0.1"); cfg.port = MOCK_PORT; |
|
|
|
|
strcpy(cfg.host, "127.0.0.1"); cfg.port = test_bound_port(m.listen_sock); |
|
|
|
|
|
|
|
|
|
TASSERT(run_dial(ua, &cfg, "127.0.0.1", 12345) == 0); |
|
|
|
|
TASSERT(g_sock != SOCKET_INVALID); |
|
|
|
|
@ -351,9 +350,9 @@ static int test1_noauth_v4(void) {
|
|
|
|
|
static int test2_auth_domain(void) { |
|
|
|
|
struct UASYNC *ua = uasync_create(); TASSERT(ua); |
|
|
|
|
struct mock m; |
|
|
|
|
TASSERT(mock_start(&m, ua, MOCK_PORT, MOCK_AUTH) == 0); |
|
|
|
|
TASSERT(mock_start(&m, ua, 0, MOCK_AUTH) == 0); |
|
|
|
|
struct socks_cfg cfg; memset(&cfg, 0, sizeof(cfg)); |
|
|
|
|
strcpy(cfg.host, "127.0.0.1"); cfg.port = MOCK_PORT; |
|
|
|
|
strcpy(cfg.host, "127.0.0.1"); cfg.port = test_bound_port(m.listen_sock); |
|
|
|
|
strcpy(cfg.user, "alice"); strcpy(cfg.pass, "secret"); |
|
|
|
|
|
|
|
|
|
TASSERT(run_dial(ua, &cfg, "example.com", 443) == 0); |
|
|
|
|
@ -369,9 +368,9 @@ static int test2_auth_domain(void) {
|
|
|
|
|
static int test3_reject(void) { |
|
|
|
|
struct UASYNC *ua = uasync_create(); TASSERT(ua); |
|
|
|
|
struct mock m; |
|
|
|
|
TASSERT(mock_start(&m, ua, MOCK_PORT, MOCK_REJECT) == 0); |
|
|
|
|
TASSERT(mock_start(&m, ua, 0, MOCK_REJECT) == 0); |
|
|
|
|
struct socks_cfg cfg; memset(&cfg, 0, sizeof(cfg)); |
|
|
|
|
strcpy(cfg.host, "127.0.0.1"); cfg.port = MOCK_PORT; |
|
|
|
|
strcpy(cfg.host, "127.0.0.1"); cfg.port = test_bound_port(m.listen_sock); |
|
|
|
|
|
|
|
|
|
int err = run_dial(ua, &cfg, "127.0.0.1", 12345); |
|
|
|
|
TASSERT(err != 0); |
|
|
|
|
@ -385,7 +384,7 @@ static int test3_reject(void) {
|
|
|
|
|
static int test4_udp_associate(void) { |
|
|
|
|
struct UASYNC *ua = uasync_create(); TASSERT(ua); |
|
|
|
|
struct udp_mock m; |
|
|
|
|
TASSERT(umock_start(&m, ua, MOCK_PORT) == 0); |
|
|
|
|
TASSERT(umock_start(&m, ua, 0) == 0); |
|
|
|
|
|
|
|
|
|
socket_t lfd = socket(AF_INET, SOCK_DGRAM, 0); |
|
|
|
|
TASSERT(lfd != SOCKET_INVALID); |
|
|
|
|
@ -395,7 +394,7 @@ static int test4_udp_associate(void) {
|
|
|
|
|
TASSERT(bind(lfd, (struct sockaddr *)&lb, sizeof(lb)) == 0); |
|
|
|
|
|
|
|
|
|
struct socks_cfg cfg; memset(&cfg, 0, sizeof(cfg)); |
|
|
|
|
strcpy(cfg.host, "127.0.0.1"); cfg.port = MOCK_PORT; |
|
|
|
|
strcpy(cfg.host, "127.0.0.1"); cfg.port = test_bound_port(m.listen_sock); |
|
|
|
|
|
|
|
|
|
g_su_ready = 0; g_su_err = 0; |
|
|
|
|
struct socks_udp *su = socks_udp_associate(ua, &cfg, lfd, su_ready_cb, NULL); |
|
|
|
|
@ -443,7 +442,7 @@ static int test4_udp_associate(void) {
|
|
|
|
|
static int test5_udp_reassociate(void) { |
|
|
|
|
struct UASYNC *ua = uasync_create(); TASSERT(ua); |
|
|
|
|
struct udp_mock m; |
|
|
|
|
TASSERT(umock_start(&m, ua, MOCK_PORT) == 0); |
|
|
|
|
TASSERT(umock_start(&m, ua, 0) == 0); |
|
|
|
|
|
|
|
|
|
socket_t lfd = socket(AF_INET, SOCK_DGRAM, 0); |
|
|
|
|
TASSERT(lfd != SOCKET_INVALID); |
|
|
|
|
@ -453,7 +452,7 @@ static int test5_udp_reassociate(void) {
|
|
|
|
|
TASSERT(bind(lfd, (struct sockaddr *)&lb, sizeof(lb)) == 0); |
|
|
|
|
|
|
|
|
|
struct socks_cfg cfg; memset(&cfg, 0, sizeof(cfg)); |
|
|
|
|
strcpy(cfg.host, "127.0.0.1"); cfg.port = MOCK_PORT; |
|
|
|
|
strcpy(cfg.host, "127.0.0.1"); cfg.port = test_bound_port(m.listen_sock); |
|
|
|
|
|
|
|
|
|
g_su_ready = 0; g_su_err = 0; |
|
|
|
|
struct socks_udp *su = socks_udp_associate(ua, &cfg, lfd, su_ready_cb, NULL); |
|
|
|
|
|