-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove long-deprecated _unauthorized_callback method. (#878)
Also - add deprecation notice for BACKWARDS_COMPAT_UNAUTHN configuration.
- Loading branch information
Showing
5 changed files
with
36 additions
and
81 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 |
---|---|---|
|
@@ -612,16 +612,14 @@ def test_http_auth_no_authorization_json(client, get_message): | |
assert response.headers["Content-Type"] == "application/json" | ||
|
||
|
||
@pytest.mark.settings(backwards_compat_unauthn=True) | ||
def test_http_auth_no_authentication(client, get_message): | ||
response = client.get("/http", headers={}) | ||
assert response.status_code == 401 | ||
assert b"<h1>Unauthorized</h1>" in response.data | ||
assert get_message("UNAUTHENTICATED") in response.data | ||
assert "WWW-Authenticate" in response.headers | ||
assert 'Basic realm="Login Required"' == response.headers["WWW-Authenticate"] | ||
|
||
|
||
@pytest.mark.settings(backwards_compat_unauthn=False) | ||
def test_http_auth_no_authentication_json(client, get_message): | ||
response = client.get("/http", headers={"accept": "application/json"}) | ||
assert response.status_code == 401 | ||
|
@@ -631,21 +629,19 @@ def test_http_auth_no_authentication_json(client, get_message): | |
assert response.headers["Content-Type"] == "application/json" | ||
|
||
|
||
@pytest.mark.settings(backwards_compat_unauthn=True) | ||
def test_invalid_http_auth_invalid_username(client): | ||
def test_invalid_http_auth_invalid_username(client, get_message): | ||
response = client.get( | ||
"/http", | ||
headers={ | ||
"Authorization": "Basic %s" | ||
% base64.b64encode(b"bogus:bogus").decode("utf-8") | ||
}, | ||
) | ||
assert b"<h1>Unauthorized</h1>" in response.data | ||
assert get_message("UNAUTHENTICATED") in response.data | ||
assert "WWW-Authenticate" in response.headers | ||
assert 'Basic realm="Login Required"' == response.headers["WWW-Authenticate"] | ||
|
||
|
||
@pytest.mark.settings(backwards_compat_unauthn=False) | ||
def test_invalid_http_auth_invalid_username_json(client, get_message): | ||
# Even with JSON - Basic Auth required a WWW-Authenticate header response. | ||
response = client.get( | ||
|
@@ -664,30 +660,28 @@ def test_invalid_http_auth_invalid_username_json(client, get_message): | |
assert "WWW-Authenticate" in response.headers | ||
|
||
|
||
@pytest.mark.settings(backwards_compat_unauthn=True) | ||
def test_invalid_http_auth_bad_password(client): | ||
def test_invalid_http_auth_bad_password(client, get_message): | ||
response = client.get( | ||
"/http", | ||
headers={ | ||
"Authorization": "Basic %s" | ||
% base64.b64encode(b"[email protected]:bogus").decode("utf-8") | ||
}, | ||
) | ||
assert b"<h1>Unauthorized</h1>" in response.data | ||
assert get_message("UNAUTHENTICATED") in response.data | ||
assert "WWW-Authenticate" in response.headers | ||
assert 'Basic realm="Login Required"' == response.headers["WWW-Authenticate"] | ||
|
||
|
||
@pytest.mark.settings(backwards_compat_unauthn=True) | ||
def test_custom_http_auth_realm(client): | ||
def test_custom_http_auth_realm(client, get_message): | ||
response = client.get( | ||
"/http_custom_realm", | ||
headers={ | ||
"Authorization": "Basic %s" | ||
% base64.b64encode(b"[email protected]:bogus").decode("utf-8") | ||
}, | ||
) | ||
assert b"<h1>Unauthorized</h1>" in response.data | ||
assert get_message("UNAUTHENTICATED") in response.data | ||
assert "WWW-Authenticate" in response.headers | ||
assert 'Basic realm="My Realm"' == response.headers["WWW-Authenticate"] | ||
|
||
|
@@ -709,16 +703,15 @@ def test_multi_auth_basic(client): | |
assert "WWW-Authenticate" in response.headers | ||
|
||
|
||
@pytest.mark.settings(backwards_compat_unauthn=True) | ||
def test_multi_auth_basic_invalid(client): | ||
def test_multi_auth_basic_invalid(client, get_message): | ||
response = client.get( | ||
"/multi_auth", | ||
headers={ | ||
"Authorization": "Basic %s" | ||
% base64.b64encode(b"bogus:bogus").decode("utf-8") | ||
}, | ||
) | ||
assert b"<h1>Unauthorized</h1>" in response.data | ||
assert get_message("UNAUTHENTICATED") in response.data | ||
assert "WWW-Authenticate" in response.headers | ||
assert 'Basic realm="Login Required"' == response.headers["WWW-Authenticate"] | ||
|
||
|
@@ -1079,3 +1072,10 @@ def test_auth_token_decorator(in_app_context): | |
headers={"Content-Type": "application/json", "Authentication-Token": token}, | ||
) | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.filterwarnings("ignore:.*BACKWARDS_COMPAT_UNAUTHN:DeprecationWarning") | ||
@pytest.mark.settings(backwards_compat_unauthn=True) | ||
def test_unauthn_compat(client): | ||
response = client.get("/profile") | ||
assert response.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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,25 +353,6 @@ def test_password_unicode_password_salt(client): | |
assert b"Welcome [email protected]" in response.data | ||
|
||
|
||
@pytest.mark.filterwarnings( | ||
"ignore:.*'unauthorized_handler' has been replaced.*:DeprecationWarning" | ||
) | ||
def test_set_unauthorized_handler(app, client): | ||
@app.security.unauthorized_handler | ||
def unauthorized(): | ||
app.unauthorized_handler_set = True | ||
return "unauthorized-handler-set", 401 | ||
|
||
app.unauthorized_handler_set = False | ||
|
||
authenticate(client, "[email protected]") | ||
response = client.get("/admin", follow_redirects=True) | ||
|
||
assert app.unauthorized_handler_set is True | ||
assert b"unauthorized-handler-set" in response.data | ||
assert response.status_code == 401 | ||
|
||
|
||
@pytest.mark.registerable() | ||
def test_custom_forms_via_config(app, sqlalchemy_datastore): | ||
class MyLoginForm(LoginForm): | ||
|