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 #147 from zalando/146-tokeninfo-url
#146 allow using TOKENINFO_URL env var (OAuth2 token info)
- Loading branch information
Showing
5 changed files
with
59 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ htmlcov/ | |
*.pyc | ||
.eggs | ||
.cache/ | ||
*.swp |
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,37 @@ | ||
from mock import MagicMock | ||
from connexion.decorators.security import get_tokeninfo_url, verify_oauth | ||
from connexion.problem import problem | ||
|
||
|
||
def test_get_tokeninfo_url(monkeypatch): | ||
env = {} | ||
monkeypatch.setattr('os.environ', env) | ||
logger = MagicMock() | ||
monkeypatch.setattr('connexion.decorators.security.logger', logger) | ||
security_def = {} | ||
assert get_tokeninfo_url(security_def) is None | ||
logger.warn.assert_not_called() | ||
env['TOKENINFO_URL'] = 'issue-146' | ||
assert get_tokeninfo_url(security_def) == 'issue-146' | ||
logger.warn.assert_not_called() | ||
env['HTTP_TOKENINFO_URL'] = 'foo' | ||
assert get_tokeninfo_url(security_def) == 'foo' | ||
logger.warn.assert_called_once_with('The HTTP_TOKENINFO_URL environment variable is deprecated. Please use TOKENINFO_URL instead.') | ||
logger.warn.reset_mock() | ||
security_def = {'x-tokenInfoUrl': 'bar'} | ||
assert get_tokeninfo_url(security_def) == 'bar' | ||
logger.warn.assert_not_called() | ||
|
||
|
||
def test_verify_oauth_invalid_auth_header(monkeypatch): | ||
def func(): | ||
pass | ||
|
||
wrapped_func = verify_oauth('https://example.org/tokeninfo', set(['admin']), func) | ||
|
||
request = MagicMock() | ||
app = MagicMock() | ||
monkeypatch.setattr('connexion.decorators.security.request', request) | ||
monkeypatch.setattr('flask.current_app', app) | ||
resp = wrapped_func() | ||
assert resp == problem(401, 'Unauthorized', 'Invalid authorization header') |