def test_get_authorize_url_doesnt_pass_state_by_default(self): auth = SpotifyPKCE("CLID", "REDIR") url = auth.get_authorize_url() parsed_url = urllibparse.urlparse(url) parsed_qs = urllibparse.parse_qs(parsed_url.query) self.assertNotIn('state', parsed_qs)
def test_get_authorize_url_passes_state_from_func_call(self): state = "STATE" auth = SpotifyPKCE("CLID", "REDIR") url = auth.get_authorize_url(state=state) parsed_url = urllibparse.urlparse(url) parsed_qs = urllibparse.parse_qs(parsed_url.query) self.assertEqual(parsed_qs['state'][0], state)
def test_code_verifier_and_code_challenge_are_correct(self): import hashlib import base64 auth = SpotifyPKCE("CLID", "REDIR") auth.get_pkce_handshake_parameters() self.assertEqual( auth.code_challenge, base64.urlsafe_b64encode( hashlib.sha256(auth.code_verifier.encode( 'utf-8')).digest()).decode('utf-8').replace('=', ''))
def test_saves_to_cache_path(self, opener): scope = "playlist-modify-private" path = ".cache-username" tok = _make_fake_token(1, 1, scope) fi = _fake_file() opener.return_value = fi spot = SpotifyPKCE("CLID", "REDIR", "STATE", scope, path) spot._save_token_info(tok) opener.assert_called_with(path, 'w') self.assertTrue(fi.write.called)
def setUpClass(cls): scope = ( 'user-follow-read ' 'user-follow-modify ' ) auth_manager = SpotifyPKCE(scope=scope, cache_path=".cache-implicittest") cls.spotify = Spotify(auth_manager=auth_manager)
def __init__(self): self.results = [] self.session_bus = dbus.SessionBus() self.command = None bus_name = dbus.service.BusName(self.bus_name, bus=self.session_bus) dbus.service.Object.__init__(self, bus_name, self._object_path) os.makedirs(ALBUMART_DIR, exist_ok=True) self.auth_manager = SpotifyPKCE( client_id=CLIENT_ID, cache_path=CACHE_FILE, redirect_uri=REDIRECT_URI, scope=ACCESS_SCOPE, ) self.spotify = Spotify(auth_manager=self.auth_manager)
def _make_pkceauth(*args, **kwargs): return SpotifyPKCE("CLID", "REDIR", "STATE", *args, **kwargs)
def test_generate_code_challenge_for_pkce(self): auth = SpotifyPKCE("CLID", "REDIR") auth.get_pkce_handshake_parameters() self.assertTrue(auth.code_challenge)