-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4349 from freedomofpress/revoke-tokens
Logout to revoke tokens
- Loading branch information
Showing
11 changed files
with
185 additions
and
13 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
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
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,42 @@ | ||
# -*- coding: utf-8 -*- | ||
from flask import url_for | ||
import os | ||
import pytest | ||
import random | ||
|
||
from models import RevokedToken | ||
from sqlalchemy.orm.exc import NoResultFound | ||
|
||
from journalist_app.utils import cleanup_expired_revoked_tokens | ||
|
||
os.environ['SECUREDROP_ENV'] = 'test' # noqa | ||
from .utils.api_helper import get_api_headers | ||
|
||
random.seed('◔ ⌣ ◔') | ||
|
||
|
||
def test_revoke_token_cleanup_does_not_delete_tokens_if_not_expired(journalist_app, test_journo, | ||
journalist_api_token): | ||
with journalist_app.test_client() as app: | ||
resp = app.post(url_for('api.logout'), headers=get_api_headers(journalist_api_token)) | ||
assert resp.status_code == 200 | ||
|
||
cleanup_expired_revoked_tokens() | ||
|
||
revoked_token = RevokedToken.query.filter_by(token=journalist_api_token).one() | ||
assert revoked_token.journalist_id == test_journo['id'] | ||
|
||
|
||
def test_revoke_token_cleanup_does_deletes_tokens_that_are_expired(journalist_app, test_journo, | ||
journalist_api_token, mocker): | ||
with journalist_app.test_client() as app: | ||
resp = app.post(url_for('api.logout'), headers=get_api_headers(journalist_api_token)) | ||
assert resp.status_code == 200 | ||
|
||
# Mock response from expired token method when token is expired | ||
mocker.patch('journalist_app.admin.Journalist.validate_token_is_not_expired_or_invalid', | ||
return_value=None) | ||
cleanup_expired_revoked_tokens() | ||
|
||
with pytest.raises(NoResultFound): | ||
RevokedToken.query.filter_by(token=journalist_api_token).one() |
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