Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion tools/bitbucket/tests/test_bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@

from magpie_bitbucket import cloud, datacenter
from magpie_bitbucket.cli import main
from magpie_bitbucket.client import BitbucketError, SameHostRedirectHandler, load_config, make_auth_header
from magpie_bitbucket.client import (
BitbucketError,
NoAuthRedirectHandler,
SameHostRedirectHandler,
load_config,
make_auth_header,
)
from magpie_bitbucket.normalize import (
created_issue_comment,
issue,
Expand Down Expand Up @@ -106,6 +112,24 @@ def urllib_request(url: str) -> urllib.request.Request:
)


def test_no_auth_redirect_handler_rejects_redirect() -> None:
handler = NoAuthRedirectHandler()
request = urllib_request("https://api.bitbucket.org/2.0/repositories/apache/magpie")

with pytest.raises(
BitbucketError,
match="refusing to forward credentials",
):
handler.redirect_request(
request,
None,
302,
"Found",
{},
"https://api.bitbucket.org/2.0/repositories/apache/magpie/issues/7/comments",
)


def test_same_host_redirect_handler_allows_same_origin() -> None:
handler = SameHostRedirectHandler()
request = urllib_request("https://bitbucket.example.test/rest/api/1.0/foo")
Expand Down
Loading