(self)
| 282 | assert self.g.requester.__hostnameHasDomain("abc.def", ["github.com", "githubusercontent.com"]) is False |
| 283 | |
| 284 | def testAssertUrlAllowed(self): |
| 285 | # default github.com requester |
| 286 | requester = self.g.requester |
| 287 | self.assertEqual(set(requester.__domains), {"github.com", "githubusercontent.com"}) |
| 288 | |
| 289 | for allowed in [ |
| 290 | "https://api.github.com/request", |
| 291 | "https://github.com/path", |
| 292 | "https://uploads.github.com/path", |
| 293 | "https://status.github.com/path", |
| 294 | "https://githubusercontent.com/path", |
| 295 | "https://objects.githubusercontent.com/path", |
| 296 | "https://release-assets.githubusercontent.com/path", |
| 297 | ]: |
| 298 | requester.__assertUrlAllowed(allowed) |
| 299 | |
| 300 | for not_allowed, arg in [ |
| 301 | ("https://prod.ghe.local/github-api/request", "prod.ghe.local"), |
| 302 | ("https://api.prod.ghe.local/github-api/request", "api.prod.ghe.local"), |
| 303 | ("https://uploads.prod.ghe.local/github-api/path", "uploads.prod.ghe.local"), |
| 304 | ("https://status.prod.ghe.local/github-api/path", "status.prod.ghe.local"), |
| 305 | ("https://example.com/", "example.com"), |
| 306 | ]: |
| 307 | with self.assertRaises(AssertionError) as exc: |
| 308 | requester.__assertUrlAllowed(not_allowed) |
| 309 | self.assertEqual(exc.exception.args, (arg,)) |
| 310 | |
| 311 | # custom (Enterprise) requester with prefix |
| 312 | requester = github.Github(base_url="https://prod.ghe.local/github-api/").requester |
| 313 | self.assertEqual(set(requester.__domains), {"prod.ghe.local"}) |
| 314 | |
| 315 | for allowed in [ |
| 316 | "https://prod.ghe.local/github-api/request", |
| 317 | "https://uploads.prod.ghe.local/path", |
| 318 | "https://status.prod.ghe.local/path", |
| 319 | ]: |
| 320 | requester.__assertUrlAllowed(allowed) |
| 321 | |
| 322 | for not_allowed, arg in [ |
| 323 | ("https://prod.ghe.local/path", "/path"), |
| 324 | ("https://ghe.local/path", "ghe.local"), |
| 325 | ("https://api.github.com/request", "api.github.com"), |
| 326 | ("https://github.com/path", "github.com"), |
| 327 | ("https://uploads.github.com/path", "uploads.github.com"), |
| 328 | ("https://status.github.com/path", "status.github.com"), |
| 329 | ("https://githubusercontent.com/path", "githubusercontent.com"), |
| 330 | ("https://objects.githubusercontent.com/path", "objects.githubusercontent.com"), |
| 331 | ( |
| 332 | "https://release-assets.githubusercontent.com/path", |
| 333 | "release-assets.githubusercontent.com", |
| 334 | ), |
| 335 | ("https://example.com/", "example.com"), |
| 336 | ]: |
| 337 | with self.assertRaises(AssertionError) as exc: |
| 338 | requester.__assertUrlAllowed(not_allowed) |
| 339 | self.assertEqual(exc.exception.args, (arg,)) |
| 340 | |
| 341 | # custom (Enterprise) requester with api subdomain and prefix |
nothing calls this directly
no test coverage detected