Skip to content

Commit

Permalink
refactor(models/tests): rename all usages of "auth verification"
Browse files Browse the repository at this point in the history
to say "claims verification" instead.
also rename test fixtures related to scope and claim to be clearer.
  • Loading branch information
angela-tran committed Aug 2, 2024
1 parent 796a32e commit 6508029
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 120 deletions.
2 changes: 1 addition & 1 deletion benefits/core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def authentication(request):
"logged_in": session.logged_in(request),
}

if verifier.uses_auth_verification:
if verifier.uses_claims_verification:
data["sign_out_button_template"] = verifier.claims_provider.sign_out_button_template
data["sign_out_link_template"] = verifier.claims_provider.sign_out_link_template

Expand Down
4 changes: 2 additions & 2 deletions benefits/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ class LoginRequired(MiddlewareMixin):
"""Middleware that checks whether a user is logged in."""

def process_view(self, request, view_func, view_args, view_kwargs):
# only require login if verifier requires it
# only require login if verifier uses claims verification
verifier = session.verifier(request)
if not verifier or not verifier.uses_auth_verification or session.logged_in(request):
if not verifier or not verifier.uses_claims_verification or session.logged_in(request):
# pass through
return None

Expand Down
2 changes: 1 addition & 1 deletion benefits/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def public_key_data(self):
return self.public_key.data

@property
def uses_auth_verification(self):
def uses_claims_verification(self):
"""True if this Verifier verifies via the claims provider. False otherwise."""
return self.claims_provider is not None and self.claims_provider.supports_claims_verification

Expand Down
2 changes: 1 addition & 1 deletion benefits/eligibility/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def eligibility_from_api(verifier, form, agency):


def eligibility_from_oauth(verifier, oauth_claim, agency):
if verifier.uses_auth_verification and verifier.claims_provider.claim == oauth_claim:
if verifier.uses_claims_verification and verifier.claims_provider.claim == oauth_claim:
return agency.type_names_to_verify(verifier)
else:
return []
2 changes: 1 addition & 1 deletion benefits/eligibility/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def confirm(request):
types_to_verify = agency.type_names_to_verify(verifier)

# GET for OAuth verification
if request.method == "GET" and verifier.uses_auth_verification:
if request.method == "GET" and verifier.uses_claims_verification:
analytics.started_eligibility(request, types_to_verify)

verified_types = verify.eligibility_from_oauth(verifier, session.oauth_claim(request), agency)
Expand Down
2 changes: 1 addition & 1 deletion benefits/oauth/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OAuthEvent(core.Event):
def __init__(self, request, event_type):
super().__init__(request, event_type)
verifier = session.verifier(request)
if verifier and verifier.uses_auth_verification:
if verifier and verifier.uses_claims_verification:
self.update_event_properties(auth_provider=verifier.claims_provider.client_name)


Expand Down
2 changes: 1 addition & 1 deletion benefits/oauth/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def process_request(self, request):

verifier = session.verifier(request)

if verifier.uses_auth_verification:
if verifier.uses_claims_verification:
# all good, the chosen verifier is configured correctly
return None
elif not (verifier.api_url or verifier.form_class):
Expand Down
38 changes: 19 additions & 19 deletions tests/pytest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def model_ClaimsProvider():


@pytest.fixture
def model_ClaimsProvider_with_verification(model_ClaimsProvider):
def model_ClaimsProvider_with_scope_and_claim(model_ClaimsProvider):
model_ClaimsProvider.scope = "scope"
model_ClaimsProvider.claim = "claim"
model_ClaimsProvider.save()
Expand All @@ -69,7 +69,7 @@ def model_ClaimsProvider_with_verification(model_ClaimsProvider):


@pytest.fixture
def model_ClaimsProvider_with_verification_no_sign_out(model_ClaimsProvider):
def model_ClaimsProvider_with_scope_and_claim_no_sign_out(model_ClaimsProvider):
model_ClaimsProvider.scope = "scope"
model_ClaimsProvider.claim = "claim"
model_ClaimsProvider.sign_out_button_template = None
Expand All @@ -80,7 +80,7 @@ def model_ClaimsProvider_with_verification_no_sign_out(model_ClaimsProvider):


@pytest.fixture
def model_ClaimsProvider_without_verification(model_ClaimsProvider):
def model_ClaimsProvider_no_scope_and_claim(model_ClaimsProvider):
model_ClaimsProvider.scope = None
model_ClaimsProvider.claim = None
model_ClaimsProvider.save()
Expand All @@ -89,7 +89,7 @@ def model_ClaimsProvider_without_verification(model_ClaimsProvider):


@pytest.fixture
def model_ClaimsProvider_without_verification_no_sign_out(model_ClaimsProvider):
def model_ClaimsProvider_no_scope_and_claim_no_sign_out(model_ClaimsProvider):
model_ClaimsProvider.scope = None
model_ClaimsProvider.claim = None
model_ClaimsProvider.sign_out_button_template = None
Expand Down Expand Up @@ -168,10 +168,10 @@ def model_EligibilityVerifier(model_PemData, model_EligibilityType):


@pytest.fixture
def model_EligibilityVerifier_ClaimsProvider_with_verification(
model_ClaimsProvider_with_verification, model_EligibilityVerifier
def model_EligibilityVerifier_ClaimsProvider_with_scope_and_claim(
model_ClaimsProvider_with_scope_and_claim, model_EligibilityVerifier
):
model_EligibilityVerifier.claims_provider = model_ClaimsProvider_with_verification
model_EligibilityVerifier.claims_provider = model_ClaimsProvider_with_scope_and_claim
model_EligibilityVerifier.save()

return model_EligibilityVerifier
Expand Down Expand Up @@ -278,36 +278,36 @@ def mocked_session_verifier(mocker, model_EligibilityVerifier):


@pytest.fixture
def mocked_session_verifier_oauth(mocker, model_EligibilityVerifier_ClaimsProvider_with_verification):
def mocked_session_verifier_oauth(mocker, model_EligibilityVerifier_ClaimsProvider_with_scope_and_claim):
return mocker.patch(
"benefits.core.session.verifier",
autospec=True,
return_value=model_EligibilityVerifier_ClaimsProvider_with_verification,
return_value=model_EligibilityVerifier_ClaimsProvider_with_scope_and_claim,
)


@pytest.fixture
def mocked_session_verifier_uses_auth_verification(
model_EligibilityVerifier_ClaimsProvider_with_verification, mocked_session_verifier_oauth
def mocked_session_verifier_uses_claims_verification(
model_EligibilityVerifier_ClaimsProvider_with_scope_and_claim, mocked_session_verifier_oauth
):
mock_verifier = model_EligibilityVerifier_ClaimsProvider_with_verification
mock_verifier.name = model_EligibilityVerifier_ClaimsProvider_with_verification.name
mock_verifier = model_EligibilityVerifier_ClaimsProvider_with_scope_and_claim
mock_verifier.name = model_EligibilityVerifier_ClaimsProvider_with_scope_and_claim.name
mock_verifier.claims_provider.sign_out_button_template = (
model_EligibilityVerifier_ClaimsProvider_with_verification.claims_provider.sign_out_button_template
model_EligibilityVerifier_ClaimsProvider_with_scope_and_claim.claims_provider.sign_out_button_template
)
mock_verifier.claims_provider.sign_out_link_template = (
model_EligibilityVerifier_ClaimsProvider_with_verification.claims_provider.sign_out_link_template
model_EligibilityVerifier_ClaimsProvider_with_scope_and_claim.claims_provider.sign_out_link_template
)
mocked_session_verifier_oauth.return_value = mock_verifier
return mocked_session_verifier_oauth


@pytest.fixture
def mocked_session_verifier_does_not_use_auth_verification(
mocked_session_verifier_uses_auth_verification, model_ClaimsProvider_without_verification
def mocked_session_verifier_does_not_use_claims_verification(
mocked_session_verifier_uses_claims_verification, model_ClaimsProvider_no_scope_and_claim
):
mocked_verifier = mocked_session_verifier_uses_auth_verification
mocked_verifier.claims_provider = model_ClaimsProvider_without_verification
mocked_verifier = mocked_session_verifier_uses_claims_verification
mocked_verifier.claims_provider = model_ClaimsProvider_no_scope_and_claim
return mocked_verifier


Expand Down
6 changes: 3 additions & 3 deletions tests/pytest/core/test_middleware_login_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def decorated_view(mocked_view):

@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_session_verifier_oauth")
def test_login_auth_required(app_request, mocked_view, decorated_view):
def test_login_verifier_uses_claims_verification(app_request, mocked_view, decorated_view):
response = decorated_view(app_request)

mocked_view.assert_not_called()
Expand All @@ -26,9 +26,9 @@ def test_login_auth_required(app_request, mocked_view, decorated_view):


@pytest.mark.django_db
def test_login_auth_not_required(app_request, model_EligibilityVerifier, mocked_view, decorated_view):
def test_login_verifier_does_not_use_claims_verification(app_request, model_EligibilityVerifier, mocked_view, decorated_view):
model_EligibilityVerifier.claims_provider = None
assert not model_EligibilityVerifier.uses_auth_verification
assert not model_EligibilityVerifier.uses_claims_verification
session.update(app_request, verifier=model_EligibilityVerifier)

decorated_view(app_request)
Expand Down
56 changes: 28 additions & 28 deletions tests/pytest/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,25 @@ def test_model_ClaimsProvider_client_id(model_ClaimsProvider, mock_models_get_se


@pytest.mark.django_db
def test_model_ClaimsProvider_with_verification(model_ClaimsProvider_with_verification):
assert model_ClaimsProvider_with_verification.supports_claims_verification
def test_model_ClaimsProvider_with_scope_and_claim(model_ClaimsProvider_with_scope_and_claim):
assert model_ClaimsProvider_with_scope_and_claim.supports_claims_verification


@pytest.mark.django_db
def test_model_ClaimsProvider_with_verification_no_sign_out(model_ClaimsProvider_with_verification_no_sign_out):
assert model_ClaimsProvider_with_verification_no_sign_out.supports_claims_verification
assert not model_ClaimsProvider_with_verification_no_sign_out.supports_sign_out
def test_model_ClaimsProvider_with_scope_and_claim_no_sign_out(model_ClaimsProvider_with_scope_and_claim_no_sign_out):
assert model_ClaimsProvider_with_scope_and_claim_no_sign_out.supports_claims_verification
assert not model_ClaimsProvider_with_scope_and_claim_no_sign_out.supports_sign_out


@pytest.mark.django_db
def test_model_ClaimsProvider_without_verification(model_ClaimsProvider_without_verification):
assert not model_ClaimsProvider_without_verification.supports_claims_verification
def test_model_ClaimsProvider_no_scope_and_claim(model_ClaimsProvider_no_scope_and_claim):
assert not model_ClaimsProvider_no_scope_and_claim.supports_claims_verification


@pytest.mark.django_db
def test_model_ClaimsProvider_without_verification_no_sign_out(model_ClaimsProvider_without_verification_no_sign_out):
assert not model_ClaimsProvider_without_verification_no_sign_out.supports_claims_verification
assert not model_ClaimsProvider_without_verification_no_sign_out.supports_sign_out
def test_model_ClaimsProvider_no_scope_and_claim_no_sign_out(model_ClaimsProvider_no_scope_and_claim_no_sign_out):
assert not model_ClaimsProvider_no_scope_and_claim_no_sign_out.supports_claims_verification
assert not model_ClaimsProvider_no_scope_and_claim_no_sign_out.supports_sign_out


@pytest.mark.django_db
Expand Down Expand Up @@ -292,46 +292,46 @@ def test_EligibilityVerifier_by_id_nonmatching():


@pytest.mark.django_db
def test_EligibilityVerifier_with_ClaimsProvider_with_verification(
model_EligibilityVerifier, model_ClaimsProvider_with_verification
def test_EligibilityVerifier_with_ClaimsProvider_with_scope_and_claim(
model_EligibilityVerifier, model_ClaimsProvider_with_scope_and_claim
):
model_EligibilityVerifier.claims_provider = model_ClaimsProvider_with_verification
model_EligibilityVerifier.claims_provider = model_ClaimsProvider_with_scope_and_claim

assert model_EligibilityVerifier.uses_auth_verification
assert model_EligibilityVerifier.uses_claims_verification


@pytest.mark.django_db
def test_EligibilityVerifier_with_ClaimsProvider_with_verification_no_sign_out(
model_EligibilityVerifier, model_ClaimsProvider_with_verification_no_sign_out
def test_EligibilityVerifier_with_ClaimsProvider_with_scope_and_claim_no_sign_out(
model_EligibilityVerifier, model_ClaimsProvider_with_scope_and_claim_no_sign_out
):
model_EligibilityVerifier.claims_provider = model_ClaimsProvider_with_verification_no_sign_out
model_EligibilityVerifier.claims_provider = model_ClaimsProvider_with_scope_and_claim_no_sign_out

assert model_EligibilityVerifier.uses_auth_verification
assert model_EligibilityVerifier.uses_claims_verification


@pytest.mark.django_db
def test_EligibilityVerifier_with_ClaimsProvider_without_verification(
model_EligibilityVerifier, model_ClaimsProvider_without_verification
def test_EligibilityVerifier_with_ClaimsProvider_no_scope_and_claim(
model_EligibilityVerifier, model_ClaimsProvider_no_scope_and_claim
):
model_EligibilityVerifier.claims_provider = model_ClaimsProvider_without_verification
model_EligibilityVerifier.claims_provider = model_ClaimsProvider_no_scope_and_claim

assert not model_EligibilityVerifier.uses_auth_verification
assert not model_EligibilityVerifier.uses_claims_verification


@pytest.mark.django_db
def test_EligibilityVerifier_with_ClaimsProvider_without_verification_no_sign_out(
model_EligibilityVerifier, model_ClaimsProvider_without_verification_no_sign_out
def test_EligibilityVerifier_with_ClaimsProvider_no_scope_and_claim_no_sign_out(
model_EligibilityVerifier, model_ClaimsProvider_no_scope_and_claim_no_sign_out
):
model_EligibilityVerifier.claims_provider = model_ClaimsProvider_without_verification_no_sign_out
model_EligibilityVerifier.claims_provider = model_ClaimsProvider_no_scope_and_claim_no_sign_out

assert not model_EligibilityVerifier.uses_auth_verification
assert not model_EligibilityVerifier.uses_claims_verification


@pytest.mark.django_db
def test_EligibilityVerifier_without_ClaimsProvider(model_EligibilityVerifier):
def test_EligibilityVerifier_no_ClaimsProvider(model_EligibilityVerifier):
model_EligibilityVerifier.claims_provider = None

assert not model_EligibilityVerifier.uses_auth_verification
assert not model_EligibilityVerifier.uses_claims_verification


@pytest.mark.django_db
Expand Down
24 changes: 12 additions & 12 deletions tests/pytest/eligibility/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,37 +52,37 @@ def test_eligibility_from_api_no_verified_types(


@pytest.mark.django_db
def test_eligibility_from_oauth_does_not_use_auth_verification(
mocked_session_verifier_does_not_use_auth_verification, model_TransitAgency
def test_eligibility_from_oauth_does_not_use_claims_verification(
mocked_session_verifier_does_not_use_claims_verification, model_TransitAgency
):
# mocked_session_verifier_does_not_use_auth_verification is Mocked version of the session.verifier() function
# mocked_session_verifier_does_not_use_claims_verification is Mocked version of the session.verifier() function
# call it (with a None request) to return a verifier object
verifier = mocked_session_verifier_does_not_use_auth_verification(None)
verifier = mocked_session_verifier_does_not_use_claims_verification(None)

types = eligibility_from_oauth(verifier, "claim", model_TransitAgency)

assert types == []


@pytest.mark.django_db
def test_eligibility_from_oauth_auth_claim_mismatch(mocked_session_verifier_uses_auth_verification, model_TransitAgency):
# mocked_session_verifier_uses_auth_verification is Mocked version of the session.verifier() function
def test_eligibility_from_oauth_claim_mismatch(mocked_session_verifier_uses_claims_verification, model_TransitAgency):
# mocked_session_verifier_uses_claims_verification is Mocked version of the session.verifier() function
# call it (with a None request) to return a verifier object
verifier = mocked_session_verifier_uses_auth_verification(None)
verifier.auth_claim = "claim"
verifier = mocked_session_verifier_uses_claims_verification(None)
verifier.claim = "claim"

types = eligibility_from_oauth(verifier, "some_other_claim", model_TransitAgency)

assert types == []


@pytest.mark.django_db
def test_eligibility_from_oauth_auth_claim_match(
mocked_session_verifier_uses_auth_verification, model_EligibilityType, model_TransitAgency
def test_eligibility_from_oauth_claim_match(
mocked_session_verifier_uses_claims_verification, model_EligibilityType, model_TransitAgency
):
# mocked_session_verifier_uses_auth_verification is Mocked version of the session.verifier() function
# mocked_session_verifier_uses_claims_verification is Mocked version of the session.verifier() function
# call it (with a None request) to return a verifier object
verifier = mocked_session_verifier_uses_auth_verification.return_value
verifier = mocked_session_verifier_uses_claims_verification.return_value
verifier.claims_provider.claim = "claim"
verifier.eligibility_type = model_EligibilityType

Expand Down
12 changes: 6 additions & 6 deletions tests/pytest/eligibility/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ def test_index_calls_session_logout(client, session_logout_spy):

@pytest.mark.django_db
@pytest.mark.usefixtures(
"mocked_session_agency", "mocked_verifier_selection_form", "mocked_session_verifier_uses_auth_verification"
"mocked_session_agency", "mocked_verifier_selection_form", "mocked_session_verifier_uses_claims_verification"
)
def test_start_verifier_auth_required_logged_in(mocker, client):
def test_start_verifier_uses_claims_verification_logged_in(mocker, client):
mock_session = mocker.patch("benefits.eligibility.views.session")
mock_session.logged_in.return_value = True

Expand All @@ -186,9 +186,9 @@ def test_start_verifier_auth_required_logged_in(mocker, client):

@pytest.mark.django_db
@pytest.mark.usefixtures(
"mocked_session_agency", "mocked_verifier_selection_form", "mocked_session_verifier_uses_auth_verification"
"mocked_session_agency", "mocked_verifier_selection_form", "mocked_session_verifier_uses_claims_verification"
)
def test_start_verifier_auth_required_not_logged_in(mocker, client):
def test_start_verifier_uses_claims_verification_not_logged_in(mocker, client):
mock_session = mocker.patch("benefits.eligibility.views.session")
mock_session.logged_in.return_value = False

Expand All @@ -200,9 +200,9 @@ def test_start_verifier_auth_required_not_logged_in(mocker, client):

@pytest.mark.django_db
@pytest.mark.usefixtures(
"mocked_session_agency", "mocked_verifier_selection_form", "mocked_session_verifier_does_not_use_auth_verification"
"mocked_session_agency", "mocked_verifier_selection_form", "mocked_session_verifier_does_not_use_claims_verification"
)
def test_start_verifier_auth_not_required(client):
def test_start_verifier_does_not_use_claims_verification(client):
path = reverse(ROUTE_START)
response = client.get(path)

Expand Down
6 changes: 3 additions & 3 deletions tests/pytest/enrollment/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ def test_success_no_verifier(client):


@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_session_verifier_uses_auth_verification", "mocked_session_eligibility")
@pytest.mark.usefixtures("mocked_session_verifier_uses_claims_verification", "mocked_session_eligibility")
def test_success_authentication_logged_in(mocker, client, model_TransitAgency, model_EligibilityType, mocked_analytics_module):
mock_session = mocker.patch("benefits.enrollment.views.session")
mock_session.logged_in.return_value = True
Expand All @@ -856,7 +856,7 @@ def test_success_authentication_logged_in(mocker, client, model_TransitAgency, m


@pytest.mark.django_db
@pytest.mark.usefixtures("mocked_session_verifier_uses_auth_verification", "mocked_session_eligibility")
@pytest.mark.usefixtures("mocked_session_verifier_uses_claims_verification", "mocked_session_eligibility")
def test_success_authentication_not_logged_in(
mocker, client, model_TransitAgency, model_EligibilityType, mocked_analytics_module
):
Expand All @@ -875,7 +875,7 @@ def test_success_authentication_not_logged_in(

@pytest.mark.django_db
@pytest.mark.usefixtures(
"mocked_session_agency", "mocked_session_verifier_does_not_use_auth_verification", "mocked_session_eligibility"
"mocked_session_agency", "mocked_session_verifier_does_not_use_claims_verification", "mocked_session_eligibility"
)
def test_success_no_authentication(mocker, client, model_EligibilityType, mocked_analytics_module):
mock_session = mocker.patch("benefits.enrollment.views.session")
Expand Down
Loading

0 comments on commit 6508029

Please sign in to comment.