diff --git a/g3proxy/ci/httpbin/Java+HttpComponents-Client-4.5/AuthNoCachePostFile.java b/g3proxy/ci/Java+HttpComponents-Client-4.5/AuthNoCachePostFile.java similarity index 100% rename from g3proxy/ci/httpbin/Java+HttpComponents-Client-4.5/AuthNoCachePostFile.java rename to g3proxy/ci/Java+HttpComponents-Client-4.5/AuthNoCachePostFile.java diff --git a/g3proxy/ci/httpbin/Java+HttpComponents-Client-4.5/README.md b/g3proxy/ci/Java+HttpComponents-Client-4.5/README.md similarity index 100% rename from g3proxy/ci/httpbin/Java+HttpComponents-Client-4.5/README.md rename to g3proxy/ci/Java+HttpComponents-Client-4.5/README.md diff --git a/g3proxy/ci/httpbin/Java+OkHttp-3/AuthPostFile.java b/g3proxy/ci/Java+OkHttp-3/AuthPostFile.java similarity index 100% rename from g3proxy/ci/httpbin/Java+OkHttp-3/AuthPostFile.java rename to g3proxy/ci/Java+OkHttp-3/AuthPostFile.java diff --git a/g3proxy/ci/httpbin/Java+OkHttp-3/README.md b/g3proxy/ci/Java+OkHttp-3/README.md similarity index 100% rename from g3proxy/ci/httpbin/Java+OkHttp-3/README.md rename to g3proxy/ci/Java+OkHttp-3/README.md diff --git a/g3proxy/ci/httpbin/Java+OkHttp-3/SimpleAuthenticator.java b/g3proxy/ci/Java+OkHttp-3/SimpleAuthenticator.java similarity index 100% rename from g3proxy/ci/httpbin/Java+OkHttp-3/SimpleAuthenticator.java rename to g3proxy/ci/Java+OkHttp-3/SimpleAuthenticator.java diff --git a/g3proxy/ci/httpbin/Java+OkHttp-3/SimpleProxySelector.java b/g3proxy/ci/Java+OkHttp-3/SimpleProxySelector.java similarity index 100% rename from g3proxy/ci/httpbin/Java+OkHttp-3/SimpleProxySelector.java rename to g3proxy/ci/Java+OkHttp-3/SimpleProxySelector.java diff --git a/g3proxy/ci/polygraph/regress/expect_post.pg b/g3proxy/ci/polygraph/regress/expect_post.pg deleted file mode 100644 index d38d3021..00000000 --- a/g3proxy/ci/polygraph/regress/expect_post.pg +++ /dev/null @@ -1,50 +0,0 @@ - -#include "vars.pg" - -Content SimpleContent = { - size = exp(13KB); // response sizes distributed exponentially - cachable = 0%; // disable check of cache -}; - -// a primitive server cleverly labeled "S101" -// normally, you would specify more properties, -// but we will mostly rely on defaults for now -Server S = { - kind = "S101"; - - addresses = server_address; // where to create these server agents - - contents = [ SimpleContent ]; - direct_access = contents; - - req_body_allowed = 70%; // affects "Expect: 100-continue" requests -}; - -// a primitive robot -Robot R = { - kind = "R101"; - - origins = S.addresses; // where the origin servers are - addresses = client_address; // where these robot agents will be created - - http_proxies = proxy_address; - - req_methods = ["POST", "PUT": 10%]; - req_body_pause_prob = 50%; // add "Expect: 100-continue" header - post_contents = [ SimpleContent ]; - put_contents = post_contents; - - open_conn_lmt = 4; -}; - -Phase P1 = { - name = "expect_post"; - - goal.xactions = 100; - goal.errors = 1; -}; - -schedule(P1); - -// commit to using these servers and robots -use(S, R); diff --git a/g3proxy/ci/polygraph/regress/g3proxy.conf b/g3proxy/ci/polygraph/regress/g3proxy.conf deleted file mode 100644 index 7f8f6565..00000000 --- a/g3proxy/ci/polygraph/regress/g3proxy.conf +++ /dev/null @@ -1,44 +0,0 @@ ---- -runtime: - thread_number: 2 - -controller: - local: - recv_timeout: 30 - send_timeout: 1 - -server: - - name: server_direct - escaper: direct - type: http_proxy - listen: - address: "[::]:10087" - conn_limit: 100M - - name: server_http - escaper: http - type: http_proxy - listen: - address: "[::]:10086" - -resolver: - - name: default - type: DenyAll - -escaper: - - name: direct - type: direct_fixed - no_ipv6: true - resolver: default - resolve_strategy: IPv4Only - tcp_conn_limit: 80M - udp_relay_limit: 10M - egress_network_filter: - default: allow - allow: 127.0.0.1 - - name: http - type: proxy_http - proxy_addr: 127.0.0.1:10087 - no_ipv6: true - resolver: default - resolve_strategy: IPv4Only - tcp_conn_limit: 80M diff --git a/g3proxy/ci/polygraph/regress/keepalive.pg b/g3proxy/ci/polygraph/regress/keepalive.pg deleted file mode 100644 index e1a348ae..00000000 --- a/g3proxy/ci/polygraph/regress/keepalive.pg +++ /dev/null @@ -1,61 +0,0 @@ - -#include "vars.pg" - -Content cntImage = { - kind = "Image"; - mime = { type = "image/jpg"; extensions = [ ".jpg" ]; }; - size = exp(100KB); - cachable = 0%; -}; - -Content cntHTML = { - kind = "HTML"; - mime = { type = "text/html"; extensions = [ ".html" : 60%, ".htm" ]; }; - size = exp(8.5KB); - cachable = 0%; - - may_contain = [ cntImage ]; - embedded_obj_cnt = zipf(13); -}; - -// a primitive server cleverly labeled "S101" -// normally, you would specify more properties, -// but we will mostly rely on defaults for now -Server S = { - kind = "S101"; - - addresses = server_address; // where to create these server agents - - contents = [ cntHTML, cntImage ]; - direct_access = contents; - - pconn_use_lmt = const(10); -}; - -// a primitive robot -Robot R = { - kind = "R101"; - - origins = S.addresses; // where the origin servers are - addresses = client_address; // where these robot agents will be created - - http_proxies = proxy_address; - - req_methods = ["GET", "HEAD": 10%]; - embed_recur = 100%; - pconn_use_lmt = const(10); - - open_conn_lmt = 4; -}; - -Phase P1 = { - name = "keepalive_get"; - - goal.xactions = 100; - goal.errors = 1; -}; - -schedule(P1); - -// commit to using these servers and robots -use(S, R); diff --git a/g3proxy/ci/polygraph/regress/simple_get.pg b/g3proxy/ci/polygraph/regress/simple_get.pg deleted file mode 100644 index c3a26cbc..00000000 --- a/g3proxy/ci/polygraph/regress/simple_get.pg +++ /dev/null @@ -1,45 +0,0 @@ - -#include "vars.pg" - -Content SimpleContent = { - size = exp(13KB); // response sizes distributed exponentially - cachable = 0%; // disable check of cache -}; - -// a primitive server cleverly labeled "S101" -// normally, you would specify more properties, -// but we will mostly rely on defaults for now -Server S = { - kind = "S101"; - - addresses = server_address; // where to create these server agents - - contents = [ SimpleContent ]; - direct_access = contents; -}; - -// a primitive robot -Robot R = { - kind = "R101"; - - origins = S.addresses; // where the origin servers are - addresses = client_address; // where these robot agents will be created - - http_proxies = proxy_address; - - req_methods = ["GET", "HEAD": 10%]; - - open_conn_lmt = 4; -}; - -Phase P1 = { - name = "simple_get"; - - goal.xactions = 100; - goal.errors = 1; -}; - -schedule(P1); - -// commit to using these servers and robots -use(S, R); diff --git a/g3proxy/ci/polygraph/regress/simple_post.pg b/g3proxy/ci/polygraph/regress/simple_post.pg deleted file mode 100644 index bd9fdf1e..00000000 --- a/g3proxy/ci/polygraph/regress/simple_post.pg +++ /dev/null @@ -1,47 +0,0 @@ - -#include "vars.pg" - -Content SimpleContent = { - size = exp(13KB); // response sizes distributed exponentially - cachable = 0%; // disable check of cache -}; - -// a primitive server cleverly labeled "S101" -// normally, you would specify more properties, -// but we will mostly rely on defaults for now -Server S = { - kind = "S101"; - - addresses = server_address; // where to create these server agents - - contents = [ SimpleContent ]; - direct_access = contents; -}; - -// a primitive robot -Robot R = { - kind = "R101"; - - origins = S.addresses; // where the origin servers are - addresses = client_address; // where these robot agents will be created - - http_proxies = proxy_address; - - req_methods = ["POST", "PUT": 10%]; - post_contents = [ SimpleContent ]; - put_contents = post_contents; - - open_conn_lmt = 4; -}; - -Phase P1 = { - name = "simple_post"; - - goal.xactions = 100; - goal.errors = 1; -}; - -schedule(P1); - -// commit to using these servers and robots -use(S, R); diff --git a/g3proxy/ci/polygraph/regress/vars.pg b/g3proxy/ci/polygraph/regress/vars.pg deleted file mode 100644 index 8df47a68..00000000 --- a/g3proxy/ci/polygraph/regress/vars.pg +++ /dev/null @@ -1,4 +0,0 @@ - -addr[] server_address = ['127.0.0.1:9090']; -addr[] client_address = ['127.0.0.1']; -addr[] proxy_address = ['127.0.0.1:10086']; diff --git a/g3proxy/ci/python3+curl/test_httpbin.py b/g3proxy/ci/python3+curl/test_httpbin.py new file mode 100644 index 00000000..3d1a7516 --- /dev/null +++ b/g3proxy/ci/python3+curl/test_httpbin.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python3 + +import argparse +import sys +import unittest +import base64 +from io import BytesIO + +import pycurl + +target_site = 'http://httpbin.org' +target_ca_cert = None +target_proxy = None +proxy_ca_cert = None +local_resolve = None + +ACCEPT_JSON = 'Accept: application/json' +ACCEPT_HTML = 'Accept: text/html' + +class TestHttpBin(unittest.TestCase): + def setUp(self): + self.c = pycurl.Curl() + self.c.setopt(pycurl.HTTPHEADER, [ACCEPT_JSON]) + if target_ca_cert is not None: + self.c.setopt(pycurl.CAINFO, target_ca_cert) + if target_proxy is not None: + self.c.setopt(pycurl.PROXY, target_proxy) + if proxy_ca_cert is not None: + self.c.setopt(pycurl.PROXY_CAINFO, proxy_ca_cert) + if local_resolve is not None: + self.c.setopt(pycurl.RESOLVE, [local_resolve]) + + def tearDown(self): + self.c.close() + + def test_simple_get(self): + self.c.setopt(pycurl.URL, f"{target_site}/get") + self.c.perform() + self.assertEqual(self.c.getinfo(pycurl.RESPONSE_CODE), 200) + + def test_basic_auth_get(self): + self.c.setopt(pycurl.URL, f"{target_site}/basic-auth/name/pass") + self.c.perform() + self.assertEqual(self.c.getinfo(pycurl.RESPONSE_CODE), 401) + + if target_proxy is not None: + auth_header = "Authorization: Basic {}".format(base64.standard_b64encode(b'name:pass').decode('utf-8')) + self.c.setopt(pycurl.HTTPHEADER, [ACCEPT_JSON, auth_header]) + self.c.perform() + self.assertEqual(self.c.getinfo(pycurl.RESPONSE_CODE), 200) + + auth_header = "Authorization: Basic {}".format(base64.standard_b64encode(b'name:pas').decode('utf-8')) + self.c.setopt(pycurl.HTTPHEADER, [ACCEPT_JSON, auth_header]) + self.c.perform() + self.assertEqual(self.c.getinfo(pycurl.RESPONSE_CODE), 401) + + def test_base64_decode(self): + buffer = BytesIO() + + self.c.setopt(pycurl.URL, f"{target_site}/base64/SFRUUEJJTiBpcyBhd2Vzb21l") + self.c.setopt(pycurl.HTTPHEADER, [ACCEPT_HTML]) + self.c.setopt(pycurl.WRITEFUNCTION, buffer.write) + self.c.perform() + self.assertEqual(self.c.getinfo(pycurl.RESPONSE_CODE), 200) + self.assertEqual(buffer.getvalue(), b"HTTPBIN is awesome") + + def test_post_continue(self): + data = "Content to post" + + self.c.setopt(pycurl.URL, f"{target_site}/post") + self.c.setopt(pycurl.POSTFIELDS, data) + self.c.perform() + self.assertEqual(self.c.getinfo(pycurl.RESPONSE_CODE), 200) + + self.c.setopt(pycurl.HTTPHEADER, ['Expect: 100-continue']) + self.c.perform() + self.assertEqual(self.c.getinfo(pycurl.RESPONSE_CODE), 200) + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--proxy', '-x', nargs='?', help='Proxy URL') + parser.add_argument('--site', '-T', nargs='?', help='Target Site', default=target_site) + parser.add_argument('--ca-cert', nargs='?', help='CA Cert') + parser.add_argument('--proxy-ca-cert', nargs='?', help='Proxy CA Cert') + parser.add_argument('--resolve', nargs='?', help='Local Resolve Record for curl') + + (args, left_args) = parser.parse_known_args() + + if args.ca_cert is not None: + target_ca_cert = args.ca_cert + if args.proxy is not None: + target_proxy = args.proxy + if args.proxy_ca_cert is not None: + proxy_ca_cert = args.proxy_ca_cert + if args.resolve is not None: + local_resolve = args.resolve + target_site = args.site + + left_args.insert(0, sys.argv[0]) + + unittest.main(argv=left_args) diff --git a/g3proxy/ci/httpbin/python3+requests/test_httpbin.py b/g3proxy/ci/python3+requests/test_httpbin.py similarity index 79% rename from g3proxy/ci/httpbin/python3+requests/test_httpbin.py rename to g3proxy/ci/python3+requests/test_httpbin.py index 2ef901c1..352d2933 100644 --- a/g3proxy/ci/httpbin/python3+requests/test_httpbin.py +++ b/g3proxy/ci/python3+requests/test_httpbin.py @@ -8,7 +8,7 @@ import requests from requests.auth import HTTPBasicAuth -target_proxy = '' +target_proxy = None target_site = 'http://httpbin.org' server_ca_cert = None @@ -16,7 +16,8 @@ server_ca_cert = None class TestHttpBin(unittest.TestCase): def setUp(self): self.session = requests.Session() - self.session.proxies.update({'http': target_proxy, 'https': target_proxy}) + if target_proxy is not None: + self.session.proxies.update({'http': target_proxy, 'https': target_proxy}) self.session.headers.update({'accept': 'application/json'}) self.session.verify = server_ca_cert @@ -31,11 +32,12 @@ class TestHttpBin(unittest.TestCase): r = self.session.get(f"{target_site}/basic-auth/name/pass") self.assertEqual(r.status_code, 401) - r = self.session.get(f"{target_site}/basic-auth/name/pass", auth=HTTPBasicAuth('name', 'pass')) - self.assertEqual(r.status_code, 200) + if target_proxy is not None: + r = self.session.get(f"{target_site}/basic-auth/name/pass", auth=HTTPBasicAuth('name', 'pass')) + self.assertEqual(r.status_code, 200) - r = self.session.get(f"{target_site}/basic-auth/name/pass", auth=HTTPBasicAuth('name', 'pas')) - self.assertEqual(r.status_code, 401) + r = self.session.get(f"{target_site}/basic-auth/name/pass", auth=HTTPBasicAuth('name', 'pas')) + self.assertEqual(r.status_code, 401) def test_base64_decode(self): self.session.headers.update({'accept': 'text/html'}) diff --git a/scripts/coverage/g3proxy.sh b/scripts/coverage/g3proxy.sh index fe3d26d4..02405ec0 100755 --- a/scripts/coverage/g3proxy.sh +++ b/scripts/coverage/g3proxy.sh @@ -14,102 +14,36 @@ cargo build -p g3proxy -p g3proxy-ctl -p g3proxy-ftp -p g3mkcert all_binaries=$(find target/debug/ -maxdepth 1 -type f -perm /111 | awk '{print "-object "$0}') -# generate resource files -"${SCRIPTS_DIR}"/g3proxy/mkcert.sh - # run the tests cargo test --all all_objects=$(find target/debug/deps/ -type f -perm /111 -not -name "*.so" | awk '{print "-object "$0}') -# run integration tests +# generate resource files +"${SCRIPTS_DIR}"/g3proxy/mkcert.sh -./target/debug/g3proxy -c "${SCRIPTS_DIR}/g3proxy/g3proxy.yaml" -G ${TEST_NAME} & -proxy_pid=$! +export SSL_CERT_FILE="${SCRIPTS_DIR}/g3proxy/rootCA.pem" -all_http_proxies="http://127.0.0.1:10080 http://t1:toor@127.0.0.1:10082 http://t2:toor@127.0.0.1:10082 http://127.0.0.1:20080 http://127.0.0.1:20443 http://127.0.0.1:9001 http://127.0.0.1:9003" -all_socks_proxies="socks5h://127.0.0.1:11080 socks5h://127.0.0.1:11081 socks5h://t1:toor@127.0.0.1:11082 socks5h://127.0.0.1:21080 socks5h://127.0.0.1:21081 socks5h://127.0.0.1:9003" -partial_proxies="http://127.0.0.1:13128 http://127.0.0.1:10081 http://t3:toor@127.0.0.1:10082 http://127.0.0.1:20081 http://127.0.0.1:20082 http://127.0.0.1:20083 http://127.0.0.1:20084 socks5h://127.0.0.1:21082 socks5h://127.0.0.1:21083" -all_proxies="${all_http_proxies} ${all_socks_proxies} ${partial_proxies}" +# run g3proxy integration tests -sleep 2 - -## -echo "==== Update dynamic escapers" -./target/debug/g3proxy-ctl -G ${TEST_NAME} -p $proxy_pid escaper float10080 publish '{"type":"http","addr":"127.0.0.1:10080"}' -./target/debug/g3proxy-ctl -G ${TEST_NAME} -p $proxy_pid escaper float10443 publish '{"type":"https","addr":"127.0.0.1:10443", "tls_name": "g3proxy.local"}' -./target/debug/g3proxy-ctl -G ${TEST_NAME} -p $proxy_pid escaper float11080 publish '{"type":"socks5","addr":"127.0.0.1:11080"}' -./target/debug/g3proxy-ctl -G ${TEST_NAME} -p $proxy_pid escaper direct_lazy publish "{\"ipv4\": \"127.0.0.1\"}" - -## -for resolver in main cares1 cares2 hickory +for dir in $(find "${SCRIPTS_DIR}/g3proxy/" -type d | sort) do - echo "==== Query directly on resolver ${resolver}" - ./target/debug/g3proxy-ctl -G ${TEST_NAME} -p $proxy_pid resolver ${resolver} query g3proxy.local - ./target/debug/g3proxy-ctl -G ${TEST_NAME} -p $proxy_pid resolver ${resolver} query httpbin.local + [ -f "${dir}/g3proxy.yaml" ] || continue + + echo "=== ${dir}" + + "${PROJECT_DIR}"/target/debug/g3proxy -c "${dir}/g3proxy.yaml" -G ${TEST_NAME} & + PROXY_PID=$! + + sleep 2 + + [ -f "${dir}/testcases.sh" ] || continue + . "${dir}/testcases.sh" + + "${PROJECT_DIR}"/target/debug/g3proxy-ctl -G ${TEST_NAME} -p $PROXY_PID offline + wait $PROXY_PID done -## tcp stream -echo "==== TCP Stream" -curl http://httpbin.local:9080/get - -## tls stream -echo "==== TLS Stream" -curl https://httpbin.local:9443/get --cacert "${SCRIPTS_DIR}/g3proxy/rootCA.pem" - -## SNI Proxy -echo "==== SNI Proxy" -curl https://httpbin.local:9443/get --cacert "${SCRIPTS_DIR}/g3proxy/rootCA.pem" --resolve httpbin.local:9443:[::1] - -## http tproxy -echo "==== Http TProxy" -curl http://g3proxy.local:8080/get --resolve g3proxy.local:8080:[::1] - -## http rproxy -echo "==== Http RProxy" -curl http://g3proxy.local:8080/get -curl https://g3proxy.local:8443/get --cacert "${SCRIPTS_DIR}/g3proxy/rootCA.pem" - -## https proxy -echo "==== Https Proxy" -curl -x https://g3proxy.local:10443 http://httpbin.local/get --proxy-cacert "${SCRIPTS_DIR}/g3proxy/rootCA.pem" -curl -x https://g3proxy.local:9002 http://httpbin.local/get --proxy-cacert "${SCRIPTS_DIR}/g3proxy/rootCA.pem" - -## socks4a proxy -echo "==== Socks4a Proxy" -curl -x socks4a://g3proxy.local:11080 http://httpbin.local/get - -## httpbin -echo "==== httpbin" -for proxy in $all_proxies -do - echo "-- ${proxy}" - python3 "${PROJECT_DIR}/g3proxy/ci/httpbin/python3+requests/test_httpbin.py" -x ${proxy} -T http://httpbin.local || : - python3 "${PROJECT_DIR}/g3proxy/ci/httpbin/python3+requests/test_httpbin.py" -x ${proxy} -T https://httpbin.local:9443 --ca-cert "${SCRIPTS_DIR}/g3proxy/rootCA.pem" || : -done - -## DNS -echo "==== DNS" -for proxy in $all_socks_proxies -do - echo "-- ${proxy}" - "${SCRIPTS_DIR}/../test/socks5_dns_query.py" -x ${proxy} --dns-server 127.0.0.1 g3proxy.local httpbin.local -v || : -done - -## FTP over HTTP -echo "==== FTP over HTTP" -for proxy in $all_http_proxies -do - echo "-- ${proxy}" - curl -x ${proxy} --upload-file "${SCRIPTS_DIR}/g3proxy/README.md" ftp://ftpuser:ftppass@127.0.0.1/README - curl -x ${proxy} ftp://ftpuser:ftppass@127.0.0.1 - curl -x ${proxy} ftp://ftpuser:ftppass@127.0.0.1/README -done - - -./target/debug/g3proxy-ctl -G ${TEST_NAME} -p $proxy_pid offline -wait $proxy_pid - ## g3proxy-ftp echo "==== g3proxy-ftp" @@ -118,7 +52,6 @@ echo "==== g3proxy-ftp" ./target/debug/g3proxy-ftp -u ftpuser -p ftppass 127.0.0.1 get README ./target/debug/g3proxy-ftp -u ftpuser -p ftppass 127.0.0.1 del README - # get all profraw files generated in each test profraw_files=$(find . -type f -regex ".*/${TEST_NAME}.*\.profraw") diff --git a/scripts/coverage/g3proxy/0000_all_resolver/g3proxy.yaml b/scripts/coverage/g3proxy/0000_all_resolver/g3proxy.yaml new file mode 100644 index 00000000..cbd0830a --- /dev/null +++ b/scripts/coverage/g3proxy/0000_all_resolver/g3proxy.yaml @@ -0,0 +1,19 @@ +--- + +log: journal + +resolver: + - name: cares1 + type: c-ares + server: + - 127.0.0.1 + - name: cares2 + type: c-ares + server: 127.0.0.1 + - name: main + type: fail_over + primary: cares1 + standby: cares2 + - name: hickory + type: hickory + server: 127.0.0.1 diff --git a/scripts/coverage/g3proxy/0000_all_resolver/testcases.sh b/scripts/coverage/g3proxy/0000_all_resolver/testcases.sh new file mode 100644 index 00000000..965cf6d3 --- /dev/null +++ b/scripts/coverage/g3proxy/0000_all_resolver/testcases.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +## +for resolver in main cares1 cares2 hickory +do + echo "==== Query directly on resolver ${resolver}" + "${PROJECT_DIR}"/target/debug/g3proxy-ctl -G ${TEST_NAME} -p $PROXY_PID resolver ${resolver} query g3proxy.local + "${PROJECT_DIR}"/target/debug/g3proxy-ctl -G ${TEST_NAME} -p $PROXY_PID resolver ${resolver} query httpbin.local +done diff --git a/scripts/coverage/g3proxy/0001_base_http_proxy/g3proxy.yaml b/scripts/coverage/g3proxy/0001_base_http_proxy/g3proxy.yaml new file mode 100644 index 00000000..2fc8776a --- /dev/null +++ b/scripts/coverage/g3proxy/0001_base_http_proxy/g3proxy.yaml @@ -0,0 +1,39 @@ +--- + +log: journal + +resolver: + - name: default + type: c-ares + server: + - 127.0.0.1 + +escaper: + - name: default + type: direct_fixed + resolver: default + egress_net_filter: + default: allow + allow: 127.0.0.1 + +server: + - name: http + type: http_proxy + listen: 127.0.0.1:8080 + escaper: default + - name: tls + type: native_tls_port + listen: 127.0.0.1:8443 + server: http + tls_server: + cert_pairs: + certificate: ../g3proxy.local.pem + private-key: ../g3proxy.local-key.pem + - name: https + type: http_proxy + listen: 127.0.0.1:9443 + escaper: default + tls_server: + cert_pairs: + certificate: ../g3proxy.local.pem + private-key: ../g3proxy.local-key.pem diff --git a/scripts/coverage/g3proxy/0001_base_http_proxy/testcases.sh b/scripts/coverage/g3proxy/0001_base_http_proxy/testcases.sh new file mode 100644 index 00000000..855ae8a4 --- /dev/null +++ b/scripts/coverage/g3proxy/0001_base_http_proxy/testcases.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +HTTP_PROXY="http://127.0.0.1:8080" +HTTPS_PROXY="https://g3proxy.local:8443" +HTTPS_PROXY2="https://g3proxy.local:9443" + +python3 "${PROJECT_DIR}/g3proxy/ci/python3+curl/test_httpbin.py" -x ${HTTP_PROXY} -T http://httpbin.local +python3 "${PROJECT_DIR}/g3proxy/ci/python3+curl/test_httpbin.py" -x ${HTTPS_PROXY} -T http://httpbin.local --proxy-ca-cert ${SSL_CERT_FILE} +python3 "${PROJECT_DIR}/g3proxy/ci/python3+curl/test_httpbin.py" -x ${HTTPS_PROXY2} -T http://httpbin.local --proxy-ca-cert ${SSL_CERT_FILE} + +python3 "${PROJECT_DIR}/g3proxy/ci/python3+requests/test_httpbin.py" -x ${HTTP_PROXY} -T http://httpbin.local +python3 "${PROJECT_DIR}/g3proxy/ci/python3+requests/test_httpbin.py" -x ${HTTPS_PROXY} -T http://httpbin.local +python3 "${PROJECT_DIR}/g3proxy/ci/python3+requests/test_httpbin.py" -x ${HTTPS_PROXY2} -T http://httpbin.local diff --git a/scripts/coverage/g3proxy/0002_base_socks_proxy/g3proxy.yaml b/scripts/coverage/g3proxy/0002_base_socks_proxy/g3proxy.yaml new file mode 100644 index 00000000..395e7aa3 --- /dev/null +++ b/scripts/coverage/g3proxy/0002_base_socks_proxy/g3proxy.yaml @@ -0,0 +1,23 @@ +--- + +log: journal + +resolver: + - name: default + type: c-ares + server: + - 127.0.0.1 + +escaper: + - name: default + type: direct_fixed + resolver: default + egress_net_filter: + default: allow + allow: 127.0.0.1 + +server: + - name: socks + type: socks_proxy + listen: 127.0.0.1:1080 + escaper: default diff --git a/scripts/coverage/g3proxy/0002_base_socks_proxy/testcases.sh b/scripts/coverage/g3proxy/0002_base_socks_proxy/testcases.sh new file mode 100644 index 00000000..1211f9ae --- /dev/null +++ b/scripts/coverage/g3proxy/0002_base_socks_proxy/testcases.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +SOCKS5_PROXY="socks5h://127.0.0.1:1080" +SOCKS4_PROXY="socks4a://127.0.0.1:1080" + +python3 "${PROJECT_DIR}/g3proxy/ci/python3+curl/test_httpbin.py" -x ${SOCKS5_PROXY} -T http://httpbin.local +python3 "${PROJECT_DIR}/g3proxy/ci/python3+curl/test_httpbin.py" -x ${SOCKS4_PROXY} -T http://httpbin.local + +python3 "${PROJECT_DIR}/g3proxy/ci/python3+requests/test_httpbin.py" -x ${SOCKS5_PROXY} -T http://httpbin.local + +python3 "${PROJECT_DIR}/scripts/test/socks5_dns_query.py" -x ${SOCKS5_PROXY} --dns-server 127.0.0.1 g3proxy.local httpbin.local -v diff --git a/scripts/coverage/g3proxy/0003_base_tcp_stream/g3proxy.yaml b/scripts/coverage/g3proxy/0003_base_tcp_stream/g3proxy.yaml new file mode 100644 index 00000000..bf1e5d67 --- /dev/null +++ b/scripts/coverage/g3proxy/0003_base_tcp_stream/g3proxy.yaml @@ -0,0 +1,33 @@ +--- + +log: journal + +resolver: + - name: default + type: c-ares + server: + - 127.0.0.1 + +escaper: + - name: default + type: direct_fixed + resolver: default + egress_net_filter: + default: allow + allow: 127.0.0.1 + +server: + - name: tcp + type: tcp_stream + listen: 127.0.0.1:8080 + escaper: default + upstream: 127.0.0.1:80 + - name: tls + type: tls_stream + escaper: default + listen: 127.0.0.1:8443 + tls_server: + cert_pairs: + certificate: ../httpbin.local.pem + private-key: ../httpbin.local-key.pem + upstream: 127.0.0.1:80 diff --git a/scripts/coverage/g3proxy/0003_base_tcp_stream/testcases.sh b/scripts/coverage/g3proxy/0003_base_tcp_stream/testcases.sh new file mode 100644 index 00000000..25386682 --- /dev/null +++ b/scripts/coverage/g3proxy/0003_base_tcp_stream/testcases.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +python3 "${PROJECT_DIR}/g3proxy/ci/python3+curl/test_httpbin.py" -T http://httpbin.local:8080 + +python3 "${PROJECT_DIR}/g3proxy/ci/python3+curl/test_httpbin.py" -T https://httpbin.local:8443 --ca-cert ${SSL_CERT_FILE} diff --git a/scripts/coverage/g3proxy/0004_base_http_gateway/g3proxy.yaml b/scripts/coverage/g3proxy/0004_base_http_gateway/g3proxy.yaml new file mode 100644 index 00000000..7d0ff23a --- /dev/null +++ b/scripts/coverage/g3proxy/0004_base_http_gateway/g3proxy.yaml @@ -0,0 +1,50 @@ +--- + +log: journal + +resolver: + - name: default + type: c-ares + server: + - 127.0.0.1 + +escaper: + - name: default + type: direct_fixed + resolver: default + egress_net_filter: + default: allow + allow: 127.0.0.1 + +server: + - name: http + type: http_rproxy + listen: 127.0.0.1:8080 + escaper: default + hosts: + - exact_match: httpbin.local + upstream: 127.0.0.1:80 + - name: tls + type: plain_tls_port + listen: 127.0.0.1:8443 + server: http + tls_server: + cert_pairs: + certificate: ../httpbin.local.pem + private-key: ../httpbin.local-key.pem + - name: https + type: http_rproxy + listen: 127.0.0.1:9443 + escaper: default + enable_tls_server: true + global_tls_server: + cert_pairs: + certificate: ../httpbin.local.pem + private-key: ../httpbin.local-key.pem + hosts: + - exact_match: httpbin.local + upstream: 127.0.0.1:80 + tls_server: + cert_pairs: + certificate: ../httpbin.local.pem + private-key: ../httpbin.local-key.pem diff --git a/scripts/coverage/g3proxy/0004_base_http_gateway/testcases.sh b/scripts/coverage/g3proxy/0004_base_http_gateway/testcases.sh new file mode 100644 index 00000000..c1dd3df6 --- /dev/null +++ b/scripts/coverage/g3proxy/0004_base_http_gateway/testcases.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +python3 "${PROJECT_DIR}/g3proxy/ci/python3+curl/test_httpbin.py" -T http://httpbin.local:8080 +python3 "${PROJECT_DIR}/g3proxy/ci/python3+curl/test_httpbin.py" -T https://httpbin.local:8443 --ca-cert ${SSL_CERT_FILE} +python3 "${PROJECT_DIR}/g3proxy/ci/python3+curl/test_httpbin.py" -T https://httpbin.local:9443 --ca-cert ${SSL_CERT_FILE} + +python3 "${PROJECT_DIR}/g3proxy/ci/python3+requests/test_httpbin.py" -T http://httpbin.local:8080 +python3 "${PROJECT_DIR}/g3proxy/ci/python3+requests/test_httpbin.py" -T https://httpbin.local:8443 +python3 "${PROJECT_DIR}/g3proxy/ci/python3+requests/test_httpbin.py" -T https://httpbin.local:9443 diff --git a/scripts/coverage/g3proxy/0005_transparent_proxy/g3proxy.yaml b/scripts/coverage/g3proxy/0005_transparent_proxy/g3proxy.yaml new file mode 100644 index 00000000..e6240f30 --- /dev/null +++ b/scripts/coverage/g3proxy/0005_transparent_proxy/g3proxy.yaml @@ -0,0 +1,58 @@ +--- + +log: journal + +resolver: + - name: default + type: c-ares + server: + - 127.0.0.1 + +escaper: + - name: default + type: direct_fixed + resolver: default + egress_net_filter: + default: allow + allow: 127.0.0.1 + +server: + - name: http + type: http_rproxy + listen: 127.0.0.1:8080 + escaper: default + hosts: + - exact_match: httpbin.local + upstream: 127.0.0.1:9443 + tls_client: + ca_certificate: ../rootCA.pem + tls_name: httpbin.local + - name: tls8443 + type: tls_stream + escaper: default + listen: 127.0.0.1:8443 + tls_server: + cert_pairs: + certificate: ../httpbin.local.pem + private-key: ../httpbin.local-key.pem + upstream: 127.0.0.1:9443 + tls_client: + ca_certificate: ../rootCA.pem + upstream_tls_name: httpbin.local + - name: tls + type: tls_stream + escaper: default + listen: 127.0.0.1:9443 + tls_server: + cert_pairs: + certificate: ../httpbin.local.pem + private-key: ../httpbin.local-key.pem + upstream: 127.0.0.1:80 + - name: sni8443 + escaper: default + type: sni_proxy + listen: "[::1]:8443" + - name: sni8080 + escaper: default + type: sni_proxy + listen: "[::1]:8080" diff --git a/scripts/coverage/g3proxy/0005_transparent_proxy/testcases.sh b/scripts/coverage/g3proxy/0005_transparent_proxy/testcases.sh new file mode 100644 index 00000000..fc31c606 --- /dev/null +++ b/scripts/coverage/g3proxy/0005_transparent_proxy/testcases.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +python3 "${PROJECT_DIR}/g3proxy/ci/python3+curl/test_httpbin.py" -T http://httpbin.local:8080 --resolve httpbin.local:8080:[::1] +python3 "${PROJECT_DIR}/g3proxy/ci/python3+curl/test_httpbin.py" -T https://httpbin.local:8443 --resolve httpbin.local:8443:[::1] --ca-cert ${SSL_CERT_FILE} diff --git a/scripts/coverage/g3proxy/testcases.sh b/scripts/coverage/g3proxy/testcases.sh new file mode 100644 index 00000000..d42b8c1a --- /dev/null +++ b/scripts/coverage/g3proxy/testcases.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +all_http_proxies="http://127.0.0.1:10080 http://t1:toor@127.0.0.1:10082 http://t2:toor@127.0.0.1:10082 http://127.0.0.1:20080 http://127.0.0.1:20443 http://127.0.0.1:9001 http://127.0.0.1:9003" +all_socks_proxies="socks5h://127.0.0.1:11080 socks5h://127.0.0.1:11081 socks5h://t1:toor@127.0.0.1:11082 socks5h://127.0.0.1:21080 socks5h://127.0.0.1:21081 socks5h://127.0.0.1:9003" +partial_proxies="http://127.0.0.1:13128 http://127.0.0.1:10081 http://t3:toor@127.0.0.1:10082 http://127.0.0.1:20081 http://127.0.0.1:20082 http://127.0.0.1:20083 http://127.0.0.1:20084 socks5h://127.0.0.1:21082 socks5h://127.0.0.1:21083" +all_proxies="${all_http_proxies} ${all_socks_proxies} ${partial_proxies}" + +## +echo "==== Update dynamic escapers" +./target/debug/g3proxy-ctl -G ${TEST_NAME} -p $PROXY_PID escaper float10080 publish '{"type":"http","addr":"127.0.0.1:10080"}' +./target/debug/g3proxy-ctl -G ${TEST_NAME} -p $PROXY_PID escaper float10443 publish '{"type":"https","addr":"127.0.0.1:10443", "tls_name": "g3proxy.local"}' +./target/debug/g3proxy-ctl -G ${TEST_NAME} -p $PROXY_PID escaper float11080 publish '{"type":"socks5","addr":"127.0.0.1:11080"}' +./target/debug/g3proxy-ctl -G ${TEST_NAME} -p $PROXY_PID escaper direct_lazy publish "{\"ipv4\": \"127.0.0.1\"}" + +## https proxy +echo "==== Https Proxy" +curl -x https://g3proxy.local:10443 http://httpbin.local/get --proxy-cacert "${SCRIPTS_DIR}/g3proxy/rootCA.pem" +curl -x https://g3proxy.local:9002 http://httpbin.local/get --proxy-cacert "${SCRIPTS_DIR}/g3proxy/rootCA.pem" + +## httpbin +echo "==== httpbin" +for proxy in $all_proxies +do + echo "-- ${proxy}" + python3 "${PROJECT_DIR}/g3proxy/ci/python3+requests/test_httpbin.py" -x ${proxy} -T http://httpbin.local || : + python3 "${PROJECT_DIR}/g3proxy/ci/python3+requests/test_httpbin.py" -x ${proxy} -T https://httpbin.local:9443 --ca-cert "${SCRIPTS_DIR}/g3proxy/rootCA.pem" || : +done + +## DNS +echo "==== DNS" +for proxy in $all_socks_proxies +do + echo "-- ${proxy}" + "${SCRIPTS_DIR}/../test/socks5_dns_query.py" -x ${proxy} --dns-server 127.0.0.1 g3proxy.local httpbin.local -v || : +done + +## FTP over HTTP +echo "==== FTP over HTTP" +for proxy in $all_http_proxies +do + echo "-- ${proxy}" + curl -x ${proxy} --upload-file "${SCRIPTS_DIR}/g3proxy/README.md" ftp://ftpuser:ftppass@127.0.0.1/README + curl -x ${proxy} ftp://ftpuser:ftppass@127.0.0.1 + curl -x ${proxy} ftp://ftpuser:ftppass@127.0.0.1/README +done