From 93f00ce7f29ba72afb42f1153c2ad3e0cec16f45 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 22 Jun 2011 00:28:51 +0300 Subject: [PATCH] Add check of URI schema to OpenUri --- mopidy/frontends/mpris.py | 5 ++++- tests/frontends/mpris/player_interface_test.py | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mopidy/frontends/mpris.py b/mopidy/frontends/mpris.py index 0e6f0e03..8cf73359 100644 --- a/mopidy/frontends/mpris.py +++ b/mopidy/frontends/mpris.py @@ -339,7 +339,10 @@ class MprisObject(dbus.service.Object): # the other methods doesn't help much if OpenUri is open for use. logger.debug(u'%s.Play not allowed', PLAYER_IFACE) return - # TODO Check if URI is known scheme and has known MIME type. + # TODO Check if URI has known MIME type. + uri_schemes = self.backend.uri_schemes.get() + if not any([uri.startswith(uri_scheme) for uri_scheme in uri_schemes]): + return track = self.backend.library.lookup(uri).get() if track is not None: cp_track = self.backend.current_playlist.add(track).get() diff --git a/tests/frontends/mpris/player_interface_test.py b/tests/frontends/mpris/player_interface_test.py index b568db64..1ddd23fe 100644 --- a/tests/frontends/mpris/player_interface_test.py +++ b/tests/frontends/mpris/player_interface_test.py @@ -763,6 +763,14 @@ class PlayerInterfaceTest(unittest.TestCase): self.mpris.OpenUri('dummy:/test/uri') self.assertEquals(len(self.backend.current_playlist.tracks.get()), 0) + def test_open_uri_ignores_uris_with_unknown_uri_scheme(self): + self.assertListEqual(self.backend.uri_schemes.get(), ['dummy']) + self.mpris.get_CanPlay = lambda *_: True + self.backend.library.provider.dummy_library = [ + Track(uri='notdummy:/test/uri')] + self.mpris.OpenUri('notdummy:/test/uri') + self.assertEquals(len(self.backend.current_playlist.tracks.get()), 0) + def test_open_uri_adds_uri_to_current_playlist(self): self.mpris.get_CanPlay = lambda *_: True self.backend.library.provider.dummy_library = [