@@ -271,18 +271,19 @@ def testHostnameHasDomain(self):
271271 assert self .g .requester .__hostnameHasDomain ("ghe.local" , "ghe.local" )
272272 assert self .g .requester .__hostnameHasDomain ("api.ghe.local" , "ghe.local" )
273273 assert self .g .requester .__hostnameHasDomain ("api.prod.ghe.local" , "prod.ghe.local" )
274- assert self .g .requester .__hostnameHasDomain ("github.com" , ( "github.com" , "githubusercontent.com" ) )
275- assert self .g .requester .__hostnameHasDomain ("api.github.com" , ( "github.com" , "githubusercontent.com" ) )
276- assert self .g .requester .__hostnameHasDomain ("githubusercontent.com" , ( "github.com" , "githubusercontent.com" ) )
274+ assert self .g .requester .__hostnameHasDomain ("github.com" , [ "github.com" , "githubusercontent.com" ] )
275+ assert self .g .requester .__hostnameHasDomain ("api.github.com" , [ "github.com" , "githubusercontent.com" ] )
276+ assert self .g .requester .__hostnameHasDomain ("githubusercontent.com" , [ "github.com" , "githubusercontent.com" ] )
277277 assert self .g .requester .__hostnameHasDomain (
278- "objects.githubusercontent.com" , ( "github.com" , "githubusercontent.com" )
278+ "objects.githubusercontent.com" , [ "github.com" , "githubusercontent.com" ]
279279 )
280280 assert self .g .requester .__hostnameHasDomain ("maliciousgithub.com" , "github.com" ) is False
281- assert self .g .requester .__hostnameHasDomain ("abc.def" , ( "github.com" , "githubusercontent.com" ) ) is False
281+ assert self .g .requester .__hostnameHasDomain ("abc.def" , [ "github.com" , "githubusercontent.com" ] ) is False
282282
283283 def testAssertUrlAllowed (self ):
284284 # default github.com requester
285285 requester = self .g .requester
286+ self .assertEqual (set (requester .__domains ), {"github.com" , "githubusercontent.com" })
286287
287288 for allowed in [
288289 "https://api.github.com/request" ,
@@ -308,6 +309,7 @@ def testAssertUrlAllowed(self):
308309
309310 # custom (Enterprise) requester with prefix
310311 requester = github .Github (base_url = "https://prod.ghe.local/github-api/" ).requester
312+ self .assertEqual (set (requester .__domains ), {"prod.ghe.local" })
311313
312314 for allowed in [
313315 "https://prod.ghe.local/github-api/request" ,
@@ -335,6 +337,37 @@ def testAssertUrlAllowed(self):
335337 requester .__assertUrlAllowed (not_allowed )
336338 self .assertEqual (exc .exception .args , (arg ,))
337339
340+ # custom (Enterprise) requester with api subdomain and prefix
341+ requester = github .Github (base_url = "https://api.prod.ghe.local/github-api/" ).requester
342+ self .assertEqual (set (requester .__domains ), {"api.prod.ghe.local" , "prod.ghe.local" })
343+
344+ for allowed in [
345+ "https://api.prod.ghe.local/github-api/request" ,
346+ "https://prod.ghe.local/path" ,
347+ "https://uploads.prod.ghe.local/path" ,
348+ "https://status.prod.ghe.local/path" ,
349+ ]:
350+ requester .__assertUrlAllowed (allowed )
351+
352+ for not_allowed , arg in [
353+ ("https://api.prod.ghe.local/path" , "/path" ),
354+ ("https://ghe.local/path" , "ghe.local" ),
355+ ("https://api.github.com/request" , "api.github.com" ),
356+ ("https://github.com/path" , "github.com" ),
357+ ("https://uploads.github.com/path" , "uploads.github.com" ),
358+ ("https://status.github.com/path" , "status.github.com" ),
359+ ("https://githubusercontent.com/path" , "githubusercontent.com" ),
360+ ("https://objects.githubusercontent.com/path" , "objects.githubusercontent.com" ),
361+ (
362+ "https://release-assets.githubusercontent.com/path" ,
363+ "release-assets.githubusercontent.com" ,
364+ ),
365+ ("https://example.com/" , "example.com" ),
366+ ]:
367+ with self .assertRaises (AssertionError ) as exc :
368+ requester .__assertUrlAllowed (not_allowed )
369+ self .assertEqual (exc .exception .args , (arg ,))
370+
338371 def testMakeAbsoluteUrl (self ):
339372 # default github.com requester
340373 requester = self .g .requester
0 commit comments