Merge branch 'master' into 'master'
Added subsonic server config for salt auth logic See merge request sublime-music/sublime-music!47
This commit is contained in:
@@ -21,6 +21,7 @@ def adapter_manager(tmp_path: Path):
|
||||
server_address="https://subsonic.example.com",
|
||||
username="test",
|
||||
verify_cert=True,
|
||||
salt_auth=False,
|
||||
)
|
||||
subsonic_config_store.set_secret("password", "testpass")
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
@@ -21,11 +22,31 @@ def adapter(tmp_path: Path):
|
||||
server_address="https://subsonic.example.com",
|
||||
username="test",
|
||||
verify_cert=True,
|
||||
salt_auth=False,
|
||||
)
|
||||
config.set_secret("password", "testpass")
|
||||
|
||||
adapter = SubsonicAdapter(config, tmp_path)
|
||||
adapter._is_mock = True
|
||||
|
||||
yield adapter
|
||||
adapter.shutdown()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def salt_auth_adapter(tmp_path: Path):
|
||||
ConfigurationStore.MOCK = True
|
||||
config = ConfigurationStore(
|
||||
server_address="https://subsonic.example.com",
|
||||
username="test",
|
||||
verify_cert=True,
|
||||
salt_auth=True,
|
||||
)
|
||||
config.set_secret("password", "testpass")
|
||||
|
||||
adapter = SubsonicAdapter(config, tmp_path)
|
||||
adapter._is_mock = True
|
||||
|
||||
yield adapter
|
||||
adapter.shutdown()
|
||||
|
||||
@@ -79,7 +100,7 @@ def test_config_form():
|
||||
SubsonicAdapter.get_configuration_form(config_store)
|
||||
|
||||
|
||||
def test_request_making_methods(adapter: SubsonicAdapter):
|
||||
def test_plain_auth_logic(adapter: SubsonicAdapter):
|
||||
expected = {
|
||||
"u": "test",
|
||||
"p": "testpass",
|
||||
@@ -89,6 +110,48 @@ def test_request_making_methods(adapter: SubsonicAdapter):
|
||||
}
|
||||
assert sorted(expected.items()) == sorted(adapter._get_params().items())
|
||||
|
||||
|
||||
def test_salt_auth_logic(salt_auth_adapter: SubsonicAdapter):
|
||||
expected = {
|
||||
"u": "test",
|
||||
"c": "Sublime Music",
|
||||
"f": "json",
|
||||
"v": "1.15.0",
|
||||
}
|
||||
|
||||
params = salt_auth_adapter._get_params()
|
||||
assert "p" not in params
|
||||
assert "s" in params
|
||||
salt = params["s"]
|
||||
assert "t" in params
|
||||
assert params["t"] == hashlib.md5(f"testpass{salt}".encode()).hexdigest()
|
||||
assert all(key in params and params[key] == expected[key] for key in expected)
|
||||
|
||||
|
||||
def test_migrate_configuration_populate_salt_auth():
|
||||
config = ConfigurationStore(
|
||||
server_address="https://subsonic.example.com",
|
||||
username="test",
|
||||
verify_cert=True,
|
||||
)
|
||||
SubsonicAdapter.migrate_configuration(config)
|
||||
assert "salt_auth" in config
|
||||
assert config["salt_auth"]
|
||||
|
||||
|
||||
def test_migrate_configuration_salt_auth_present():
|
||||
config = ConfigurationStore(
|
||||
server_address="https://subsonic.example.com",
|
||||
username="test",
|
||||
verify_cert=True,
|
||||
salt_auth=False,
|
||||
)
|
||||
SubsonicAdapter.migrate_configuration(config)
|
||||
assert "salt_auth" in config
|
||||
assert not config["salt_auth"]
|
||||
|
||||
|
||||
def test_make_url(adapter: SubsonicAdapter):
|
||||
assert adapter._make_url("foo") == "https://subsonic.example.com/rest/foo.view"
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user