-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check user authorization on api calls - backport from newsroom-core (#…
- Loading branch information
1 parent
096fad4
commit c19c2ee
Showing
11 changed files
with
143 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import enum | ||
|
||
|
||
class UserRole(enum.Enum): | ||
ADMINISTRATOR = "administrator" | ||
INTERNAL = "internal" | ||
PUBLIC = "public" | ||
COMPANY_ADMIN = "company_admin" | ||
ACCOUNT_MANAGEMENT = "account_management" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from flask import url_for | ||
from bson import ObjectId | ||
|
||
|
||
def test_public_user_api(app, client): | ||
company_ids = app.data.insert('companies', [{ | ||
'phone': '2132132134', | ||
'sd_subscriber_id': '12345', | ||
'name': 'Press Co.', | ||
'is_enabled': True, | ||
'contact_name': 'Tom' | ||
}]) | ||
user = { | ||
'_id': ObjectId("5c5914275f627d5885fee6a8"), | ||
'first_name': 'Normal', | ||
'last_name': 'User', | ||
'email': '[email protected]', | ||
'password': '$2b$12$HGyWCf9VNfnVAwc2wQxQW.Op3Ejk7KIGE6urUXugpI0KQuuK6RWIG', | ||
'user_type': 'public', | ||
'is_validated': True, | ||
'is_enabled': True, | ||
'is_approved': True, | ||
'receive_email': True, | ||
'phone': '2132132134', | ||
'expiry_alert': True, | ||
'company': company_ids[0]} | ||
app.data.insert('users', [user]) | ||
client.post( | ||
url_for('auth.login'), | ||
data={'email': '[email protected]', 'password': 'admin'}, | ||
follow_redirects=True | ||
) | ||
|
||
resp = client.get("/api") | ||
assert 200 == resp.status_code | ||
|
||
resp = client.get("/api/users") | ||
assert resp.status_code == 401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
from datetime import datetime, timedelta | ||
from superdesk import get_resource_service | ||
|
||
from newsroom.auth import get_user_by_email | ||
from newsroom.auth import get_auth_user_by_email | ||
from newsroom.utils import get_user_dict, get_company_dict, is_valid_login | ||
from .utils import mock_send_email | ||
from unittest import mock | ||
|
@@ -79,7 +79,7 @@ def test_reset_password_token_sent_for_user_succeeds(app, client): | |
response = client.post('/users/59b4c5c61d41c8d736852fbf/reset_password') | ||
assert response.status_code == 200 | ||
assert '"success": true' in response.get_data(as_text=True) | ||
user = get_resource_service('users').find_one(req=None, email='[email protected]') | ||
user = get_resource_service('auth_user').find_one(req=None, email='[email protected]') | ||
assert user.get('token') is not None | ||
|
||
|
||
|
@@ -185,7 +185,7 @@ def test_create_new_user_succeeds(app, client): | |
assert 'account created' in outbox[0].subject | ||
|
||
# get reset password token | ||
user = get_user_by_email('[email protected]') | ||
user = get_auth_user_by_email('[email protected]') | ||
client.get(url_for('auth.reset_password', token=user['token'])) | ||
|
||
# change the password | ||
|