diff options
author | Atul Anand <atulhjp@gmail.com> | 2016-06-16 16:45:54 +0530 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2016-06-16 15:35:57 +0300 |
commit | ba18cf534d77efc8352104a7e5409bd921784c1f (patch) | |
tree | 092afa8d317191b0a6f3b619934c6e73a331973b | |
parent | ee610da7096d5b3dfa7e073141de8c82b71250d0 (diff) | |
download | pacrunner-ba18cf534d77efc8352104a7e5409bd921784c1f.tar.gz |
unit: new test proxy_domain added.
A new test proxy_domain.test has been added which tests all
conditions to see whether Pacrunner answer correctly using Domains.
-rw-r--r-- | unit/suite/manual_basic.test | 2 | ||||
-rw-r--r-- | unit/suite/manual_exclude.test | 2 | ||||
-rw-r--r-- | unit/suite/pac_basic.test | 2 | ||||
-rw-r--r-- | unit/suite/pac_direct.test | 2 | ||||
-rw-r--r-- | unit/suite/proxy_domain.test | 37 | ||||
-rw-r--r-- | unit/suite/stub.test | 3 | ||||
-rw-r--r-- | unit/test-pacrunner.c | 86 |
7 files changed, 130 insertions, 4 deletions
diff --git a/unit/suite/manual_basic.test b/unit/suite/manual_basic.test index a5ec3a1..4406d9c 100644 --- a/unit/suite/manual_basic.test +++ b/unit/suite/manual_basic.test @@ -10,6 +10,8 @@ socks4://sockproxy.internal.com [excludes] +[domains] + [config] VALID diff --git a/unit/suite/manual_exclude.test b/unit/suite/manual_exclude.test index c155743..211ae16 100644 --- a/unit/suite/manual_exclude.test +++ b/unit/suite/manual_exclude.test @@ -15,6 +15,8 @@ ftp:// *net tri* +[domains] + [config] VALID diff --git a/unit/suite/pac_basic.test b/unit/suite/pac_basic.test index 58af200..c63757e 100644 --- a/unit/suite/pac_basic.test +++ b/unit/suite/pac_basic.test @@ -17,6 +17,8 @@ function FindProxyForURL(url, host) [excludes] +[domains] + [config] VALID diff --git a/unit/suite/pac_direct.test b/unit/suite/pac_direct.test index 3164872..b820abc 100644 --- a/unit/suite/pac_direct.test +++ b/unit/suite/pac_direct.test @@ -11,6 +11,8 @@ function FindProxyForURL(url, host) [excludes] +[domains] + [config] VALID diff --git a/unit/suite/proxy_domain.test b/unit/suite/proxy_domain.test new file mode 100644 index 0000000..8c2c5e4 --- /dev/null +++ b/unit/suite/proxy_domain.test @@ -0,0 +1,37 @@ +[title] +Proxy Domain lookup + +[pac] + +[servers] +http://proxy.suite.com + +[excludes] + +[domains] +suite.com +test.suite.com +172.132.231.6/24 + +[config] +VALID + +[tests] +http://foo.suite.com foo.suite.com +PROXY proxy.suite.com +http://172.132.231.101/search=?true 172.132.231.101 +PROXY proxy.suite.com +http://111.121.131.141/page1 111.121.131.141 +DIRECT +http://notintel.com notintel.com +DIRECT +http://intel.com intel.com +PROXY proxy2.com; PROXY secproxy2.com +https://bar.domain2.com bar.domain2.com +PROXY secproxy2.com; PROXY proxy2.com +http://192.168.4.4/index.html 192.168.4.4 +PROXY proxy2.com; PROXY secproxy2.com +socks4://baz.domain3.com/xyz baz.domain3.com +SOCKS4 sockproxy3.com; PROXY proxy3.com +http://[fe80:96db:12ce::43ef]/ip6.mp4 [fe80:96db:12ce::43ef] +PROXY proxy3.com; SOCKS4 sockproxy3.com diff --git a/unit/suite/stub.test b/unit/suite/stub.test index 12a0426..cde0aeb 100644 --- a/unit/suite/stub.test +++ b/unit/suite/stub.test @@ -11,6 +11,9 @@ Stub suite file [excludes] # If so, optional exlusion rules can be written here +[domains] +# List of domains are here + [config] # Result of the configuration: VALID or INVALID diff --git a/unit/test-pacrunner.c b/unit/test-pacrunner.c index f234a35..0c4ac69 100644 --- a/unit/test-pacrunner.c +++ b/unit/test-pacrunner.c @@ -42,9 +42,10 @@ enum test_suite_part { SUITE_PAC = 1, SUITE_SERVERS = 2, SUITE_EXCLUDES = 3, - SUITE_CONFIG = 4, - SUITE_TESTS = 5, - SUITE_NOTHING = 6, + SUITE_DOMAINS = 4, + SUITE_CONFIG = 5, + SUITE_TESTS = 6, + SUITE_NOTHING = 7, }; enum cu_test_mode { @@ -58,6 +59,7 @@ struct pacrunner_test_suite { gchar *pac; gchar **servers; gchar **excludes; + gchar **domains; bool config_result; @@ -67,7 +69,7 @@ struct pacrunner_test_suite { static struct pacrunner_test_suite *test_suite; static bool verbose = false; -static struct pacrunner_proxy *proxy; +static struct pacrunner_proxy *proxy, *proxy2 = NULL, *proxy3 = NULL; static bool test_config; static void free_pacrunner_test_suite(struct pacrunner_test_suite *suite) @@ -79,6 +81,7 @@ static void free_pacrunner_test_suite(struct pacrunner_test_suite *suite) g_free(suite->pac); g_strfreev(suite->servers); g_strfreev(suite->excludes); + g_strfreev(suite->domains); g_strfreev(suite->tests); g_free(suite); @@ -142,6 +145,13 @@ static void print_test_suite(struct pacrunner_test_suite *suite) } else printf("(none)\n"); + printf("\nDomains:\n"); + if (suite->domains) { + for (line = suite->domains; *line; line++) + printf("%s\n", *line); + } else + printf("(none)\n"); + printf("\nConfig result: %s\n", suite->config_result ? "Valid" : "Invalid"); @@ -240,6 +250,15 @@ static struct pacrunner_test_suite *read_test_suite(const char *path) suite->excludes = array; break; + case SUITE_DOMAINS: + array = _g_strappendv(suite->domains, *line); + if (!array) + goto error; + + g_free(suite->domains); + suite->domains = array; + + break; case SUITE_CONFIG: if (strncmp(*line, "VALID", 5) == 0) suite->config_result = true; @@ -272,6 +291,8 @@ static struct pacrunner_test_suite *read_test_suite(const char *path) part = SUITE_SERVERS; else if (strncmp(*line, "[excludes]", 10) == 0) part = SUITE_EXCLUDES; + else if (strncmp(*line, "[domains]", 9) == 0) + part = SUITE_DOMAINS; else if (strncmp(*line, "[config]", 8) == 0) part = SUITE_CONFIG; else if (strncmp(*line, "[tests]", 7) == 0) @@ -338,6 +359,54 @@ static void test_manual_config(void) CU_ASSERT_TRUE(test_suite->config_result == test_config); } +static void test_proxy_domain(void) +{ + int val = 0; + + if (pacrunner_proxy_set_domains(proxy, test_suite->domains) != 0) + val = -1; + + proxy2 = pacrunner_proxy_create("eth1"); + if (proxy2) { + char *servers[] = { + "http://proxy2.com", + "https://secproxy2.com", + NULL}; + char *domains[] = { + "intel.com", + "domain2.com", + "192.168.4.0/16", + NULL}; + + if (pacrunner_proxy_set_manual(proxy2, servers, NULL) != 0) + val = -1; + + if (pacrunner_proxy_set_domains(proxy2, domains) != 0) + val = -1; + } + + proxy3 = pacrunner_proxy_create("wl0"); + if (proxy3) { + char *servers[] = { + "http://proxy3.com", + "socks4://sockproxy3.com", + NULL}; + char *domains[] = { + "redhat.com", + "domain3.com", + "fe80:96db::/32", + NULL}; + + if (pacrunner_proxy_set_manual(proxy3, servers, NULL) != 0) + val = -1; + + if (pacrunner_proxy_set_domains(proxy3, domains) != 0) + val = -1; + } + + CU_ASSERT_TRUE(val == 0); +} + static void test_proxy_requests(void) { gchar **test_strings; @@ -430,12 +499,21 @@ static void run_test_suite(const char *test_file_path, enum cu_test_mode mode) CU_add_test(cu_suite, "Manual config test", test_manual_config); + if (test_suite->domains) + CU_add_test(cu_suite, "Proxy domain test", + test_proxy_domain); + if (test_suite->config_result && test_suite->tests) CU_add_test(cu_suite, "Proxy requests test", test_proxy_requests); test_config = false; + if (test_suite->domains) { + pacrunner_proxy_unref(proxy2); + pacrunner_proxy_unref(proxy3); + } + switch (mode) { case CU_MODE_BASIC: CU_basic_set_mode(CU_BRM_VERBOSE); |