Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_revoke__access_token_with_refresh_set(self):
authorizer = prawcore.Authorizer(self.authentication, REFRESH_TOKEN)
with Betamax(REQUESTOR).use_cassette(
"Authorizer_revoke__access_token_with_refresh_set"
):
authorizer.refresh()
authorizer.revoke(only_access=True)
self.assertIsNone(authorizer.access_token)
self.assertIsNotNone(authorizer.refresh_token)
self.assertIsNone(authorizer.scopes)
self.assertFalse(authorizer.is_valid())
authorizer.refresh()
self.assertTrue(authorizer.is_valid())
def client_authorizer():
authenticator = prawcore.TrustedAuthenticator(
REQUESTOR, CLIENT_ID, CLIENT_SECRET
)
authorizer = prawcore.Authorizer(authenticator, REFRESH_TOKEN)
authorizer.refresh()
return authorizer
def test_revoke__refresh_token_without_access_set(self):
authorizer = prawcore.Authorizer(self.authentication, REFRESH_TOKEN)
with Betamax(REQUESTOR).use_cassette(
"Authorizer_revoke__refresh_token_without_access_set"
):
authorizer.revoke()
self.assertIsNone(authorizer.access_token)
self.assertIsNone(authorizer.refresh_token)
self.assertIsNone(authorizer.scopes)
self.assertFalse(authorizer.is_valid())
def test_authorize__with_invalid_code(self):
self.authentication.redirect_uri = REDIRECT_URI
authorizer = prawcore.Authorizer(self.authentication)
with Betamax(REQUESTOR).use_cassette(
"Authorizer_authorize__with_invalid_code"
):
self.assertRaises(
prawcore.OAuthException, authorizer.authorize, "invalid code"
)
self.assertFalse(authorizer.is_valid())
def test_refresh(self):
authorizer = prawcore.Authorizer(self.authentication, REFRESH_TOKEN)
with Betamax(REQUESTOR).use_cassette("Authorizer_refresh"):
authorizer.refresh()
self.assertIsNotNone(authorizer.access_token)
self.assertIsInstance(authorizer.scopes, set)
self.assertTrue(len(authorizer.scopes) > 0)
self.assertTrue(authorizer.is_valid())
def test_authorize__with_temporary_grant(self):
self.authentication.redirect_uri = REDIRECT_URI
authorizer = prawcore.Authorizer(self.authentication)
with Betamax(REQUESTOR).use_cassette(
"Authorizer_authorize__with_temporary_grant"
):
authorizer.authorize(TEMPORARY_GRANT_CODE)
self.assertIsNotNone(authorizer.access_token)
self.assertIsNone(authorizer.refresh_token)
self.assertIsInstance(authorizer.scopes, set)
self.assertTrue(len(authorizer.scopes) > 0)
self.assertTrue(authorizer.is_valid())
authenticator = TrustedAuthenticator(
requestor,
self.config.client_id,
self.config.client_secret,
self.config.redirect_uri,
)
read_only_authorizer = ReadOnlyAuthorizer(authenticator)
self._read_only_core = session(read_only_authorizer)
if self.config.username and self.config.password:
script_authorizer = ScriptAuthorizer(
authenticator, self.config.username, self.config.password
)
self._core = self._authorized_core = session(script_authorizer)
elif self.config.refresh_token:
authorizer = Authorizer(authenticator, self.config.refresh_token)
self._core = self._authorized_core = session(authorizer)
else:
self._core = self._read_only_core
def _prepare_untrusted_prawcore(self, requestor):
authenticator = UntrustedAuthenticator(
requestor, self.config.client_id, self.config.redirect_uri
)
read_only_authorizer = DeviceIDAuthorizer(authenticator)
self._read_only_core = session(read_only_authorizer)
if self.config.refresh_token:
authorizer = Authorizer(authenticator, self.config.refresh_token)
self._core = self._authorized_core = session(authorizer)
else:
self._core = self._read_only_core