Skip to content

Commit

Permalink
test(aud): Rename fixture default_audiences to default_audience
Browse files Browse the repository at this point in the history
  • Loading branch information
vpsx committed Oct 13, 2020
1 parent fe0fb51 commit cf666cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def iss():


@pytest.fixture(scope="session")
def default_audiences():
def default_audience():
"""
Return default audience to pass to core.validate_jwt calls.
"""
Expand Down
28 changes: 14 additions & 14 deletions tests/test_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,53 @@


def test_valid_signature(
claims, encoded_jwt, rsa_public_key, default_audiences, default_scopes, iss
claims, encoded_jwt, rsa_public_key, default_audience, default_scopes, iss
):
"""
Do a basic test of the expected functionality with the sample payload in
the fence README.
"""
decoded_token = validate_jwt(
encoded_jwt, rsa_public_key, default_audiences, default_scopes, [iss]
encoded_jwt, rsa_public_key, default_audience, default_scopes, [iss]
)
assert decoded_token
assert decoded_token == claims


def test_expired_token_rejected(
encoded_jwt_expired, rsa_public_key, default_audiences, default_scopes, iss
encoded_jwt_expired, rsa_public_key, default_audience, default_scopes, iss
):
with pytest.raises(JWTExpiredError):
validate_jwt(
encoded_jwt_expired,
rsa_public_key,
default_audiences,
default_audience,
default_scopes,
[iss],
)


def test_invalid_signature_rejected(
encoded_jwt, rsa_public_key_2, default_audiences, default_scopes, iss
encoded_jwt, rsa_public_key_2, default_audience, default_scopes, iss
):
"""
Test that ``validate_jwt`` rejects JWTs signed with a private key not
corresponding to the public key it is given.
"""
with pytest.raises(JWTError):
validate_jwt(
encoded_jwt, rsa_public_key_2, default_audiences, default_scopes, [iss]
encoded_jwt, rsa_public_key_2, default_audience, default_scopes, [iss]
)


def test_invalid_scope_rejected(encoded_jwt, rsa_public_key, default_audiences, iss):
def test_invalid_scope_rejected(encoded_jwt, rsa_public_key, default_audience, iss):
"""
Test that if ``validate_jwt`` is passed values for ``scope`` which do not
appear in the token, a ``JWTScopeError`` is raised.
"""
with pytest.raises(JWTScopeError):
validate_jwt(
encoded_jwt, rsa_public_key, default_audiences, {"not-in-scopes"}, [iss]
encoded_jwt, rsa_public_key, default_audience, {"not-in-scopes"}, [iss]
)


Expand Down Expand Up @@ -125,7 +125,7 @@ def test_valid_aud_accepted(


def test_invalid_iss_rejected(
encoded_jwt, rsa_public_key, default_audiences, default_scopes, iss
encoded_jwt, rsa_public_key, default_audience, default_scopes, iss
):
"""
Test that if ``validate_jwt`` receives a token whose value for ``iss``
Expand All @@ -134,7 +134,7 @@ def test_invalid_iss_rejected(
wrong_iss = iss + "garbage"
with pytest.raises(JWTError):
validate_jwt(
encoded_jwt, rsa_public_key, default_audiences, default_scopes, [wrong_iss]
encoded_jwt, rsa_public_key, default_audience, default_scopes, [wrong_iss]
)


Expand Down Expand Up @@ -192,7 +192,7 @@ def test_validate_request_jwt_bad_header(client, mock_get, encoded_jwt):


def test_validate_request_jwt_missing_all_scopes(
app, client, auth_header, default_audiences, mock_get
app, client, auth_header, default_audience, mock_get
):
"""
Test that if the JWT is completely missing a scope which is required by
Expand All @@ -203,7 +203,7 @@ def test_validate_request_jwt_missing_all_scopes(
# This should raise a JWTScopeError, since the scope it
# requires does not appear in the default JWT anywhere.
@app.route("/test_missing_scope")
@require_auth_header({"missing_scope"}, default_audiences, "access")
@require_auth_header({"missing_scope"}, default_audience, "access")
def bad():
return flask.jsonify({"foo": "bar"})

Expand All @@ -212,7 +212,7 @@ def bad():


def test_validate_request_jwt_missing_some_scopes(
app, client, auth_header, default_audiences, mock_get
app, client, auth_header, default_audience, mock_get
):
"""
Test that if the JWT satisfies some scopes but is missing at least one
Expand All @@ -224,7 +224,7 @@ def test_validate_request_jwt_missing_some_scopes(
# This should raise JWTScopeError, since the scope it requires does
# not appear in the default JWT anywhere.
@app.route("/test_missing_scope")
@require_auth_header({"access", "missing_scope"}, default_audiences, "access")
@require_auth_header({"access", "missing_scope"}, default_audience, "access")
def bad():
return flask.jsonify({"foo": "bar"})

Expand Down

0 comments on commit cf666cc

Please sign in to comment.