Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zwordi
funkwhale
Commits
fc48e16e
Verified
Commit
fc48e16e
authored
6 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Fix #218: Ensure inactive users cannot get auth tokens
parent
8ee34b89
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/tests/subsonic/test_authentication.py
+19
-0
19 additions, 0 deletions
api/tests/subsonic/test_authentication.py
api/tests/users/test_views.py
+29
-19
29 additions, 19 deletions
api/tests/users/test_views.py
changes/changelog.d/218.bugfix
+2
-0
2 additions, 0 deletions
changes/changelog.d/218.bugfix
with
50 additions
and
19 deletions
api/tests/subsonic/test_authentication.py
+
19
−
0
View file @
fc48e16e
import
binascii
import
pytest
from
rest_framework
import
exceptions
from
funkwhale_api.subsonic
import
authentication
...
...
@@ -54,3 +57,19 @@ def test_auth_with_password_cleartext(api_request, factories):
u
,
_
=
authenticator
.
authenticate
(
request
)
assert
user
==
u
def
test_auth_with_inactive_users
(
api_request
,
factories
):
salt
=
'
salt
'
user
=
factories
[
'
users.User
'
](
is_active
=
False
)
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
()
with
pytest
.
raises
(
exceptions
.
AuthenticationFailed
):
authenticator
.
authenticate
(
request
)
This diff is collapsed.
Click to expand it.
api/tests/users/test_views.py
+
29
−
19
View file @
fc48e16e
...
...
@@ -7,7 +7,7 @@ from django.urls import reverse
from
funkwhale_api.users.models
import
User
def
test_can_create_user_via_api
(
preferences
,
client
,
db
):
def
test_can_create_user_via_api
(
preferences
,
api_
client
,
db
):
url
=
reverse
(
'
rest_register
'
)
data
=
{
'
username
'
:
'
test1
'
,
...
...
@@ -16,14 +16,14 @@ def test_can_create_user_via_api(preferences, client, db):
'
password2
'
:
'
testtest
'
,
}
preferences
[
'
users__registration_enabled
'
]
=
True
response
=
client
.
post
(
url
,
data
)
response
=
api_
client
.
post
(
url
,
data
)
assert
response
.
status_code
==
201
u
=
User
.
objects
.
get
(
email
=
'
test1@test.com
'
)
assert
u
.
username
==
'
test1
'
def
test_can_restrict_usernames
(
settings
,
preferences
,
db
,
client
):
def
test_can_restrict_usernames
(
settings
,
preferences
,
db
,
api_
client
):
url
=
reverse
(
'
rest_register
'
)
preferences
[
'
users__registration_enabled
'
]
=
True
settings
.
USERNAME_BLACKLIST
=
[
'
funkwhale
'
]
...
...
@@ -34,13 +34,13 @@ def test_can_restrict_usernames(settings, preferences, db, client):
'
password2
'
:
'
testtest
'
,
}
response
=
client
.
post
(
url
,
data
)
response
=
api_
client
.
post
(
url
,
data
)
assert
response
.
status_code
==
400
assert
'
username
'
in
response
.
data
def
test_can_disable_registration_view
(
preferences
,
client
,
db
):
def
test_can_disable_registration_view
(
preferences
,
api_
client
,
db
):
url
=
reverse
(
'
rest_register
'
)
data
=
{
'
username
'
:
'
test1
'
,
...
...
@@ -49,7 +49,7 @@ def test_can_disable_registration_view(preferences, client, db):
'
password2
'
:
'
testtest
'
,
}
preferences
[
'
users__registration_enabled
'
]
=
False
response
=
client
.
post
(
url
,
data
)
response
=
api_
client
.
post
(
url
,
data
)
assert
response
.
status_code
==
403
...
...
@@ -73,7 +73,7 @@ def test_can_fetch_data_from_api(api_client, factories):
assert
response
.
data
[
'
permissions
'
]
==
user
.
get_permissions
()
def
test_can_get_token_via_api
(
client
,
factories
):
def
test_can_get_token_via_api
(
api_
client
,
factories
):
user
=
factories
[
'
users.User
'
]()
url
=
reverse
(
'
api:v1:token
'
)
payload
=
{
...
...
@@ -81,12 +81,24 @@ def test_can_get_token_via_api(client, factories):
'
password
'
:
'
test
'
}
response
=
client
.
post
(
url
,
payload
)
response
=
api_
client
.
post
(
url
,
payload
)
assert
response
.
status_code
==
200
assert
'"
token
"
:
'
in
response
.
content
.
decode
(
'
utf-8
'
)
assert
'
token
'
in
response
.
data
def
test_can_get_token_via_api_inactive
(
api_client
,
factories
):
user
=
factories
[
'
users.User
'
](
is_active
=
False
)
url
=
reverse
(
'
api:v1:token
'
)
payload
=
{
'
username
'
:
user
.
username
,
'
password
'
:
'
test
'
}
def
test_can_refresh_token_via_api
(
client
,
factories
):
response
=
api_client
.
post
(
url
,
payload
)
assert
response
.
status_code
==
400
def
test_can_refresh_token_via_api
(
api_client
,
factories
,
mocker
):
# first, we get a token
user
=
factories
[
'
users.User
'
]()
url
=
reverse
(
'
api:v1:token
'
)
...
...
@@ -95,21 +107,19 @@ def test_can_refresh_token_via_api(client, factories):
'
password
'
:
'
test
'
}
response
=
client
.
post
(
url
,
payload
)
response
=
api_
client
.
post
(
url
,
payload
)
assert
response
.
status_code
==
200
token
=
json
.
loads
(
response
.
content
.
decode
(
'
utf-8
'
))
[
'
token
'
]
token
=
response
.
data
[
'
token
'
]
url
=
reverse
(
'
api:v1:token_refresh
'
)
response
=
client
.
post
(
url
,{
'
token
'
:
token
})
response
=
api_
client
.
post
(
url
,
{
'
token
'
:
token
})
assert
response
.
status_code
==
200
assert
'"
token
"
:
'
in
response
.
content
.
decode
(
'
utf-8
'
)
# a different token should be returned
assert
token
in
response
.
content
.
decode
(
'
utf-8
'
)
assert
'
token
'
in
response
.
data
def
test_changing_password_updates_secret_key
(
logged_in_client
):
user
=
logged_in_client
.
user
def
test_changing_password_updates_secret_key
(
logged_in_
api_
client
):
user
=
logged_in_
api_
client
.
user
password
=
user
.
password
secret_key
=
user
.
secret_key
payload
=
{
...
...
@@ -119,7 +129,7 @@ def test_changing_password_updates_secret_key(logged_in_client):
}
url
=
reverse
(
'
change_password
'
)
response
=
logged_in_client
.
post
(
url
,
payload
)
response
=
logged_in_
api_
client
.
post
(
url
,
payload
)
user
.
refresh_from_db
()
...
...
This diff is collapsed.
Click to expand it.
changes/changelog.d/218.bugfix
0 → 100644
+
2
−
0
View file @
fc48e16e
Ensure inactive users cannot get auth tokens (#218)
This was already the case bug we missed some checks
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment