Skip to content

Commit

Permalink
Switch v1 support to ver_config level
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <jamiehalebc@gmail.com>
  • Loading branch information
jamshale committed Sep 26, 2023
1 parent 7dc6b36 commit ee42694
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
1 change: 0 additions & 1 deletion oidc-controller/api/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ class GlobalConfig(BaseSettings):
os.environ.get("USE_OOB_LOCAL_DID_SERVICE", False)
)
SET_NON_REVOKED: bool = bool(os.environ.get("SET_NON_REVOKED", True))
USE_V1_COMPATIBILITY: bool = bool(os.environ.get("USE_V1_COMPATIBILITY", False))

class Config:
case_sensitive = True
Expand Down
3 changes: 1 addition & 2 deletions oidc-controller/api/core/oidc/issue_token_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from ...authSessions.models import AuthSession
from ...verificationConfigs.models import ReqAttr, VerificationConfig
from ..models import RevealedAttribute
from ..config import settings

logger = structlog.getLogger(__name__)

Expand Down Expand Up @@ -111,7 +110,7 @@ def get_claims(

# TODO: Remove after full transistion to v2.0
# Add the presentation claims to the result as keys for backwards compatibility [v1.0]
if settings.USE_V1_COMPATIBILITY:
if ver_config.include_v1_attributes:
for key, value in presentation_claims.items():
result[key] = value.value

Expand Down
22 changes: 11 additions & 11 deletions oidc-controller/api/core/oidc/tests/test_issue_token_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from api.core.oidc.issue_token_service import Token
from api.core.oidc.tests.__mocks__ import auth_session, presentation, ver_config
from api.test_utils import is_valid_uuid
from api.core.config import settings

basic_valid_requested_attributes = {
"req_attr_0": {
Expand Down Expand Up @@ -116,26 +115,26 @@ async def test_valid_proof_presentation_with_multiple_attributes_returns_claims(


@pytest.mark.asyncio
@mock.patch.object(settings, "USE_V1_COMPATIBILITY", False)
async def test_use_v1_compatibility_false_does_not_add_the_named_attributes():
async def test_include_v1_attributes_false_does_not_add_the_named_attributes():
presentation['presentation_request']['requested_attributes'] = multiple_valid_requested_attributes
presentation['presentation']['requested_proof']['revealed_attr_groups'] = multiple_valid_revealed_attr_groups
with mock.patch.object(AuthSession, "presentation_exchange", presentation):
ver_config.include_v1_attributes = False
claims = Token.get_claims(auth_session, ver_config)
vc_presented_attributes_obj = eval(claims["vc_presented_attributes"])
assert claims is not None
assert vc_presented_attributes_obj["email_1"] == 'jamiehalebc@gmail.com'
assert vc_presented_attributes_obj["age_1"] == '30'
assert hasattr(claims, "email_1") is False
assert hasattr(claims, "age_1") is False
assert "email_1" not in claims
assert "age_1" not in claims


@pytest.mark.asyncio
@mock.patch.object(settings, "USE_V1_COMPATIBILITY", True)
async def test_use_v1_compatibility_true_adds_the_named_attributes():
async def test_include_v1_attributes_true_adds_the_named_attributes():
presentation['presentation_request']['requested_attributes'] = multiple_valid_requested_attributes
presentation['presentation']['requested_proof']['revealed_attr_groups'] = multiple_valid_revealed_attr_groups
with mock.patch.object(AuthSession, "presentation_exchange", presentation):
ver_config.include_v1_attributes = True
claims = Token.get_claims(auth_session, ver_config)
vc_presented_attributes_obj = eval(claims["vc_presented_attributes"])
assert claims is not None
Expand All @@ -145,18 +144,19 @@ async def test_use_v1_compatibility_true_adds_the_named_attributes():
assert claims["age_1"] == '30'

@pytest.mark.asyncio
@mock.patch.object(settings, "USE_V1_COMPATIBILITY", None)
async def test_use_v1_compatibility_none_does_not_add_the_named_attributes():
async def test_include_v1_attributes_none_does_not_add_the_named_attributes():
presentation['presentation_request']['requested_attributes'] = multiple_valid_requested_attributes
presentation['presentation']['requested_proof']['revealed_attr_groups'] = multiple_valid_revealed_attr_groups
with mock.patch.object(AuthSession, "presentation_exchange", presentation):
ver_config.include_v1_attributes = None
print(ver_config.include_v1_attributes)
claims = Token.get_claims(auth_session, ver_config)
vc_presented_attributes_obj = eval(claims["vc_presented_attributes"])
assert claims is not None
assert vc_presented_attributes_obj["email_1"] == 'jamiehalebc@gmail.com'
assert vc_presented_attributes_obj["age_1"] == '30'
assert hasattr(claims, "email_1") is False
assert hasattr(claims, "age_1") is False
assert "email_1" not in claims
assert "age_1" not in claims


@pytest.mark.asyncio
Expand Down
1 change: 1 addition & 0 deletions oidc-controller/api/verificationConfigs/examples.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ex_ver_config = {
"ver_config_id": "test-request-config",
"include_v1_attributes": False,
"subject_identifier": "first_name",
"proof_request": {
"name": "Basic Proof",
Expand Down
1 change: 1 addition & 0 deletions oidc-controller/api/verificationConfigs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class VerificationProofRequest(BaseModel):
class VerificationConfigBase(BaseModel):
subject_identifier: str = Field()
proof_request: VerificationProofRequest = Field()
include_v1_attributes: Optional[bool] = Field(default=False)

def generate_proof_request(self):
result = {
Expand Down

0 comments on commit ee42694

Please sign in to comment.