|
1 | 1 | # coding: utf-8
|
2 | 2 | import json
|
3 | 3 | import logging
|
| 4 | +import os |
4 | 5 | import pytest
|
5 | 6 | import subprocess
|
6 | 7 | import sys
|
@@ -52,25 +53,106 @@ def test_transport_option(monkeypatch):
|
52 | 53 | assert str(Client(transport=transport).dsn) == dsn
|
53 | 54 |
|
54 | 55 |
|
55 |
| -def test_http_proxy(monkeypatch): |
56 |
| - client = Client("https://foo@sentry.io/123", http_proxy="http://localhost/123") |
| 56 | +def test_proxy_http_use(monkeypatch): |
| 57 | + client = Client("http://foo@sentry.io/123", http_proxy="http://localhost/123") |
57 | 58 | assert client.transport._pool.proxy.scheme == "http"
|
58 | 59 |
|
| 60 | + |
| 61 | +def test_proxy_https_use(monkeypatch): |
| 62 | + client = Client("https://foo@sentry.io/123", http_proxy="https://localhost/123") |
| 63 | + assert client.transport._pool.proxy.scheme == "https" |
| 64 | + |
| 65 | + |
| 66 | +def test_proxy_both_select_http(monkeypatch): |
59 | 67 | client = Client(
|
60 |
| - "https://foo@sentry.io/123", |
| 68 | + "http://foo@sentry.io/123", |
61 | 69 | https_proxy="https://localhost/123",
|
62 | 70 | http_proxy="http://localhost/123",
|
63 | 71 | )
|
64 |
| - assert client.transport._pool.proxy.scheme == "https" |
65 |
| - |
66 |
| - client = Client("http://foo@sentry.io/123", http_proxy="http://localhost/123") |
67 | 72 | assert client.transport._pool.proxy.scheme == "http"
|
68 | 73 |
|
| 74 | + |
| 75 | +def test_proxy_both_select_https(monkeypatch): |
69 | 76 | client = Client(
|
70 |
| - "http://foo@sentry.io/123", |
| 77 | + "https://foo@sentry.io/123", |
71 | 78 | https_proxy="https://localhost/123",
|
72 | 79 | http_proxy="http://localhost/123",
|
73 | 80 | )
|
| 81 | + assert client.transport._pool.proxy.scheme == "https" |
| 82 | + |
| 83 | + |
| 84 | +def test_proxy_http_fallback_http(monkeypatch): |
| 85 | + client = Client("https://foo@sentry.io/123", http_proxy="http://localhost/123") |
| 86 | + assert client.transport._pool.proxy.scheme == "http" |
| 87 | + |
| 88 | + |
| 89 | +def test_proxy_none_noenv(monkeypatch): |
| 90 | + client = Client("http://foo@sentry.io/123") |
| 91 | + assert client.transport._pool.proxy is None |
| 92 | + |
| 93 | + |
| 94 | +def test_proxy_none_httpenv_select(monkeypatch): |
| 95 | + os.environ["HTTP_PROXY"] = "http://localhost/123" |
| 96 | + client = Client("http://foo@sentry.io/123") |
| 97 | + assert client.transport._pool.proxy.scheme == "http" |
| 98 | + |
| 99 | + |
| 100 | +def test_proxy_none_httpsenv_select(monkeypatch): |
| 101 | + os.environ["HTTPS_PROXY"] = "https://localhost/123" |
| 102 | + client = Client("https://foo@sentry.io/123") |
| 103 | + assert client.transport._pool.proxy.scheme == "https" |
| 104 | + |
| 105 | + |
| 106 | +def test_proxy_none_httpenv_fallback(monkeypatch): |
| 107 | + os.environ["HTTP_PROXY"] = "http://localhost/123" |
| 108 | + client = Client("https://foo@sentry.io/123") |
| 109 | + assert client.transport._pool.proxy.scheme == "http" |
| 110 | + |
| 111 | + |
| 112 | +def test_proxy_bothselect_bothen(monkeypatch): |
| 113 | + os.environ["HTTP_PROXY"] = "http://localhost/123" |
| 114 | + os.environ["HTTPS_PROXY"] = "https://localhost/123" |
| 115 | + client = Client("https://foo@sentry.io/123", http_proxy="", https_proxy="") |
| 116 | + assert client.transport._pool.proxy is None |
| 117 | + |
| 118 | + |
| 119 | +def test_proxy_bothavoid_bothenv(monkeypatch): |
| 120 | + os.environ["HTTP_PROXY"] = "http://localhost/123" |
| 121 | + os.environ["HTTPS_PROXY"] = "https://localhost/123" |
| 122 | + client = Client("https://foo@sentry.io/123", http_proxy=None, https_proxy=None) |
| 123 | + assert client.transport._pool.proxy.scheme == "https" |
| 124 | + |
| 125 | + |
| 126 | +def test_proxy_bothselect_httpenv(monkeypatch): |
| 127 | + os.environ["HTTP_PROXY"] = "http://localhost/123" |
| 128 | + client = Client("https://foo@sentry.io/123", http_proxy=None, https_proxy=None) |
| 129 | + assert client.transport._pool.proxy.scheme == "http" |
| 130 | + |
| 131 | + |
| 132 | +def test_proxy_httpselect_bothenv(monkeypatch): |
| 133 | + os.environ["HTTP_PROXY"] = "http://localhost/123" |
| 134 | + os.environ["HTTPS_PROXY"] = "https://localhost/123" |
| 135 | + client = Client("https://foo@sentry.io/123", http_proxy=None, https_proxy="") |
| 136 | + assert client.transport._pool.proxy.scheme == "http" |
| 137 | + |
| 138 | + |
| 139 | +def test_proxy_httpsselect_bothenv(monkeypatch): |
| 140 | + os.environ["HTTP_PROXY"] = "http://localhost/123" |
| 141 | + os.environ["HTTPS_PROXY"] = "https://localhost/123" |
| 142 | + client = Client("https://foo@sentry.io/123", http_proxy="", https_proxy=None) |
| 143 | + assert client.transport._pool.proxy.scheme == "https" |
| 144 | + |
| 145 | + |
| 146 | +def test_proxy_httpselect_httpsenv(monkeypatch): |
| 147 | + os.environ["HTTPS_PROXY"] = "https://localhost/123" |
| 148 | + client = Client("https://foo@sentry.io/123", http_proxy=None, https_proxy="") |
| 149 | + assert client.transport._pool.proxy is None |
| 150 | + |
| 151 | + |
| 152 | +def test_proxy_httpsselect_bothenv_http(monkeypatch): |
| 153 | + os.environ["HTTP_PROXY"] = "http://localhost/123" |
| 154 | + os.environ["HTTPS_PROXY"] = "https://localhost/123" |
| 155 | + client = Client("http://foo@sentry.io/123", http_proxy=None, https_proxy=None) |
74 | 156 | assert client.transport._pool.proxy.scheme == "http"
|
75 | 157 |
|
76 | 158 |
|
|
0 commit comments