示例#1
0
	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, '')
示例#2
0
	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)
示例#3
0
	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.")
示例#4
0
	def test_not_b64(self, token: str):
		assert validate_pypi_token(token) == (False, "Could not decode token.")
示例#5
0
	def test_wrong_start(self, token: str):
		assert validate_pypi_token(token) == (False, "The token should start with 'pypi-'.")