Skip to content

Commit

Permalink
Warn if new OAuth config values don't match spotify-web values.
Browse files Browse the repository at this point in the history
  • Loading branch information
kingosticks committed Jun 6, 2017
1 parent 7a1b4bf commit de91721
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mopidy_spotify/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,22 @@ def __init__(self, config, audio):
self.playlists = None
self.uri_schemes = ['spotify']

def _config_consistent_with_spotify_web(self):
config = self._config['spotify']
web_config = self._config.get('spotify_web', {})
if (web_config.get('enabled') and
web_config.get('use_mopidy_oauth_bridge') and
(web_config.get('client_id', '') != config['client_id'] or
web_config.get('client_secret', '') != config['client_secret'])):
return False

return True

def on_start(self):
if not self._config_consistent_with_spotify_web():
logger.warning('Spotify and Spotify-Web configs should use the '
'same OAuth client_id and client_secret')

self._actor_proxy = self.actor_ref.proxy()
self._session = self._get_session(self._config)

Expand Down
23 changes: 23 additions & 0 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from mopidy import backend as backend_api

import pytest

import spotify

from mopidy_spotify import backend, library, playback, playlists
Expand Down Expand Up @@ -49,6 +51,27 @@ def test_init_disables_playlists_provider_if_not_allowed(spotify_mock, config):
assert backend.playlists is None


@pytest.mark.parametrize("web_config,expected", [
({'enabled': False, 'use_mopidy_oauth_bridge': True,
'client_id': 'abcd1234', 'client_secret': 'YWJjZDEyMzQ='}, False),
({'enabled': True, 'use_mopidy_oauth_bridge': True,
'client_id': 'abcd1234', 'client_secret': 'YWJjZDEyMzQ='}, False),
({'enabled': True, 'use_mopidy_oauth_bridge': False,
'client_id': 'abcd1234', 'client_secret': 'YWJjZDEyMzQ='}, False),
({'enabled': True, 'use_mopidy_oauth_bridge': True,
'client_id': 'abcd1234', 'client_secret': 'deadbeef'}, True),
({'enabled': True, 'use_mopidy_oauth_bridge': True,
'client_id': 'f33df4c3', 'client_secret': 'YWJjZDEyMzQ='}, True),
])
def test_on_start_checks_spotify_web_config(
config, web_config, spotify_mock, expected, caplog):
config['spotify_web'] = web_config
get_backend(config).on_start()

assert ('Spotify and Spotify-Web configs should use the same OAuth '
'client_id and client_secret' in caplog.text()) == expected


def test_on_start_creates_configured_session(tmpdir, spotify_mock, config):
cache_location_mock = mock.PropertyMock()
settings_location_mock = mock.PropertyMock()
Expand Down

0 comments on commit de91721

Please sign in to comment.