See #75: initial subsonic implementation that works with http://p.subfireplayer.net

This commit is contained in:
Eliot Berriot 2018-05-08 16:32:07 +02:00
parent 9682299480
commit bbd273404a
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
15 changed files with 774 additions and 48 deletions

View file

@ -0,0 +1,56 @@
import binascii
from funkwhale_api.subsonic import authentication
def test_auth_with_salt(api_request, factories):
salt = 'salt'
user = factories['users.User']()
user.subsonic_api_token = 'password'
user.save()
token = authentication.get_token(salt, 'password')
request = api_request.get('/', {
't': token,
's': salt,
'u': user.username
})
authenticator = authentication.SubsonicAuthentication()
u, _ = authenticator.authenticate(request)
assert user == u
def test_auth_with_password_hex(api_request, factories):
salt = 'salt'
user = factories['users.User']()
user.subsonic_api_token = 'password'
user.save()
token = authentication.get_token(salt, 'password')
request = api_request.get('/', {
'u': user.username,
'p': 'enc:{}'.format(binascii.hexlify(
user.subsonic_api_token.encode('utf-8')).decode('utf-8'))
})
authenticator = authentication.SubsonicAuthentication()
u, _ = authenticator.authenticate(request)
assert user == u
def test_auth_with_password_cleartext(api_request, factories):
salt = 'salt'
user = factories['users.User']()
user.subsonic_api_token = 'password'
user.save()
token = authentication.get_token(salt, 'password')
request = api_request.get('/', {
'u': user.username,
'p': 'password',
})
authenticator = authentication.SubsonicAuthentication()
u, _ = authenticator.authenticate(request)
assert user == u