def test_seemingly_valid(self): fake_macaroon = pymacaroons.Macaroon( identifier=b"12345-67890", signature="4eba1dde2d0866f550278e40bb354542", location="pypi.org", version=pymacaroons.MACAROON_V2, ) fake_macaroon.add_first_party_caveat(json.dumps({"permissions": {"projects": ["dict2css"]}, "version": 1})) assert validate_pypi_token(f"pypi-{fake_macaroon.serialize()}") == (True, '')
def test_no_caveats(self): fake_macaroon = pymacaroons.Macaroon( identifier=b"12345-67890", signature="4eba1dde2d0866f550278e40bb354542", location="pypi.org", version=pymacaroons.MACAROON_V2, ) error_msg = "The decoded output does not have the expected format." assert validate_pypi_token(f"pypi-{fake_macaroon.serialize()}") == (False, error_msg)
def test_wrong_location(self): fake_macaroon = pymacaroons.Macaroon( identifier=b"12345-67890", signature="4eba1dde2d0866f550278e40bb354542", location="github.com", version=pymacaroons.MACAROON_V2, ) fake_macaroon.add_first_party_caveat(json.dumps({"permissions": {"projects": ["dict2css"]}, "version": 1})) assert validate_pypi_token(f"pypi-{fake_macaroon.serialize()}") == (False, "The token is not for PyPI.")
def test_not_b64(self, token: str): assert validate_pypi_token(token) == (False, "Could not decode token.")
def test_wrong_start(self, token: str): assert validate_pypi_token(token) == (False, "The token should start with 'pypi-'.")