@@ -1209,7 +1209,8 @@ def test_httpcore_response_headers_are_structured(self) -> None:
12091209 "receive_response_headers.complete "
12101210 "return_value=(b'HTTP/1.1', 200, b'OK', "
12111211 "[(b'Zed', b'last'), (b'Content-Type', b'application/json'), "
1212- "(b'Alpha', b'first')])"
1212+ "(b'Set-Cookie', b'session=secret'), "
1213+ "(b'X-Api-Key', b'secret'), (b'Alpha', b'first')])"
12131214 )
12141215 finally :
12151216 logger = logging .getLogger (logger_name )
@@ -1226,12 +1227,17 @@ def test_httpcore_response_headers_are_structured(self) -> None:
12261227 self .assertEqual (response_headers ["http_version" ], "HTTP/1.1" )
12271228 self .assertEqual (response_headers ["status_code" ], 200 )
12281229 self .assertEqual (response_headers ["reason_phrase" ], "OK" )
1229- self .assertEqual (list (response_headers ["headers" ]), ["alpha" , "content-type" , "zed" ])
1230+ self .assertEqual (
1231+ list (response_headers ["headers" ]),
1232+ ["alpha" , "content-type" , "set-cookie" , "x-api-key" , "zed" ],
1233+ )
12301234 self .assertEqual (
12311235 response_headers ["headers" ],
12321236 {
12331237 "alpha" : "first" ,
12341238 "content-type" : "application/json" ,
1239+ "set-cookie" : "[redacted]" ,
1240+ "x-api-key" : "[redacted]" ,
12351241 "zed" : "last" ,
12361242 },
12371243 )
@@ -1311,8 +1317,9 @@ def handler(_request: httpx.Request) -> httpx.Response:
13111317 client = HTTPClient (max_attempts = 1 , transport = httpx .MockTransport (handler ))
13121318 payload = client .json (
13131319 "POST" ,
1314- "https://example.com/api" ,
1320+ "https://user:pass@ example.com/api?code=oauth " ,
13151321 headers = {"Authorization" : "Bearer token" },
1322+ query = {"limit" : 10 , "access_token" : "secret" , "signature" : "signed" },
13161323 json_body = {"hello" : "world" },
13171324 )
13181325 finally :
@@ -1332,6 +1339,11 @@ def handler(_request: httpx.Request) -> httpx.Response:
13321339 self .assertFalse (any (row .get ("logger" ) in {"httpx" , "httpcore" } for row in rows ))
13331340 self .assertEqual (http_request ["status_code" ], 200 )
13341341 self .assertEqual (http_request ["reason_phrase" ], "OK" )
1342+ self .assertEqual (
1343+ http_request ["url" ],
1344+ "https://example.com/api?code=[redacted]&limit=10"
1345+ "&access_token=[redacted]&signature=[redacted]" ,
1346+ )
13351347 self .assertEqual (http_request ["request_bytes" ], len (b'{"hello": "world"}' ))
13361348 self .assertEqual (http_request ["request_headers" ]["authorization" ], "[redacted]" )
13371349 self .assertEqual (
@@ -1364,10 +1376,13 @@ def handler(_request: httpx.Request) -> httpx.Response:
13641376 )
13651377
13661378 with self .assertRaisesRegex (HTTPClientError , "rate limited" ) as raised :
1367- client .json ("GET" , "https://example.com/api" )
1379+ client .json ("GET" , "https://user:pass@ example.com/api?access_token=secret " )
13681380
13691381 self .assertEqual (raised .exception .status_code , 429 )
13701382 self .assertEqual (raised .exception .body , "rate limited" )
1383+ self .assertIn ("https://example.com/api?access_token=[redacted]" , str (raised .exception ))
1384+ self .assertNotIn ("user:pass" , str (raised .exception ))
1385+ self .assertNotIn ("secret" , str (raised .exception ))
13711386
13721387
13731388class ClientTest (unittest .TestCase ):
@@ -1409,6 +1424,13 @@ def test_sourcegraph_client_builds_graphql_request(self) -> None:
14091424 self .assertEqual (http .calls [0 ]["url" ], "https://sourcegraph.example.com/.api/graphql" )
14101425 self .assertEqual (http .calls [0 ]["headers" ], {"Authorization" : "token token" })
14111426
1427+ def test_sourcegraph_client_rejects_http_endpoint_by_default (self ) -> None :
1428+ with self .assertRaisesRegex (ValueError , "https:// URL" ):
1429+ SourcegraphClient ("http://sourcegraph.example.com" , "token" )
1430+
1431+ client = SourcegraphClient ("http://localhost:3080" , "token" , allow_insecure_http = True )
1432+ self .assertEqual (client .endpoint , "http://localhost:3080" )
1433+
14121434 def test_sourcegraph_client_streams_connection_nodes (self ) -> None :
14131435 http = RecordingHTTP (
14141436 [
@@ -1780,7 +1802,12 @@ def test_graphql_client_emits_query_debug_events(self) -> None:
17801802 },
17811803 ]
17821804 )
1783- client = GraphQLClient ("https://example.com/graphql" , {}, "Example" , http = http )
1805+ client = GraphQLClient (
1806+ "https://user:pass@example.com/graphql?access_token=secret&query=ok" ,
1807+ {},
1808+ "Example" ,
1809+ http = http ,
1810+ )
17841811 query = """
17851812query Items($first: Int!, $after: String, $userId: ID!) {
17861813 viewer { items { nodes { id } pageInfo { hasNextPage endCursor } } }
@@ -1822,6 +1849,10 @@ def test_graphql_client_emits_query_debug_events(self) -> None:
18221849 self .assertEqual ([row ["page_size" ] for row in starts ], [2 , 2 ])
18231850 self .assertEqual ([row ["cursor_present" ] for row in starts ], [False , True ])
18241851 self .assertEqual (starts [0 ]["graphql_client" ], "Example" )
1852+ self .assertEqual (
1853+ starts [0 ]["url" ],
1854+ "https://example.com/graphql?access_token=[redacted]&query=ok" ,
1855+ )
18251856 self .assertEqual (starts [0 ]["variable_names" ], ["after" , "first" , "userId" ])
18261857 self .assertEqual (ends [0 ]["response_fields" ], ["viewer" ])
18271858
@@ -1946,6 +1977,10 @@ def test_github_client_can_target_github_enterprise(self) -> None:
19461977 graphql_api_url ("github.example.com" ), "https://github.example.com/api/graphql"
19471978 )
19481979
1980+ def test_github_client_rejects_http_enterprise_url (self ) -> None :
1981+ with self .assertRaisesRegex (ValueError , "https:// URL" ):
1982+ graphql_api_url ("http://github.example.com" )
1983+
19491984 def test_github_client_validate_queries_viewer (self ) -> None :
19501985 http = RecordingHTTP ([{"data" : {"viewer" : {"login" : "alice" }}}])
19511986 client = GitHubClient ("token" , http = http )
0 commit comments