Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into issue/3269
Browse files Browse the repository at this point in the history
  • Loading branch information
ianco committed Dec 17, 2024
2 parents 4d02556 + 5c1d357 commit 13a7461
Show file tree
Hide file tree
Showing 28 changed files with 428 additions and 228 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/sonar-merge-main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Sonar Scan and Coverage
name: Sonar Scan and Coverage on merge to main
on:
push:
branches:
Expand All @@ -19,12 +19,8 @@ jobs:
python-version: "3.12"
os: "ubuntu-latest"
is_pr: "false"
- name: Adjust Test Coverage Source
run: |
# Need to change source in coverage report because it was generated from another context
sed -i 's/\/home\/runner\/work\/acapy\/acapy\//\/github\/workspace\//g' test-reports/coverage.xml
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
uses: SonarSource/sonarqube-scan-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand All @@ -33,4 +29,4 @@ jobs:
-Dsonar.python.coverage.reportPaths=test-reports/coverage.xml
-Dsonar.coverage.exclusions=**/tests/**,**/demo/**,**/docs/**,**/docker/**,**/scripts/**,**/scenarios/**
-Dsonar.cpd.exclusions=**/tests/**,**/demo/**,**/docs/**,**/docker/**,**/scripts/**,**/scenarios/**
-Dsonar.sources=./
-Dsonar.sources=./
18 changes: 6 additions & 12 deletions .github/workflows/sonar-pr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Sonar Scan and Coverage
name: Sonar Scan and Coverage on PRs

on:
workflow_run:
Expand All @@ -15,7 +15,7 @@ jobs:
with:
fetch-depth: 0
- name: Download PR number artifact
uses: dawidd6/action-download-artifact@v6
uses: dawidd6/action-download-artifact@v7
with:
workflow: Tests
run_id: ${{ github.event.workflow_run.id }}
Expand All @@ -26,7 +26,7 @@ jobs:
with:
path: ./PR_NUMBER
- name: Download Test Coverage
uses: dawidd6/action-download-artifact@v6
uses: dawidd6/action-download-artifact@v7
with:
workflow: Tests
run_id: ${{ github.event.workflow_run.id }}
Expand All @@ -51,14 +51,8 @@ jobs:
echo base branch = ${{ fromJson(steps.get_pr_data.outputs.data).base.ref }}
git checkout -B temp-branch-for-scanning upstream/${{ fromJson(steps.get_pr_data.outputs.data).head.ref }}
- name: Move Coverage Report And Adjust Source
run: |
mkdir test-reports
mv coverage.xml test-reports
# Need to change source in coverage report because it was generated from another context
sed -i 's/\/home\/runner\/work\/acapy\/acapy\//\/github\/workspace\//g' test-reports/coverage.xml
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
uses: SonarSource/sonarqube-scan-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand All @@ -70,5 +64,5 @@ jobs:
-Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }}
-Dsonar.coverage.exclusions=**/tests/**,**/demo/**,**/docs/**,**/docker/**,**/scripts/**,**/scenarios/**
-Dsonar.cpd.exclusions=**/tests/**,**/demo/**,**/docs/**,**/docker/**,**/scripts/**,**/scenarios/**
-Dsonar.python.coverage.reportPaths=test-reports/coverage.xml
-Dsonar.sources=./
-Dsonar.python.coverage.reportPaths=coverage.xml
-Dsonar.sources=./
2 changes: 1 addition & 1 deletion acapy_agent/anoncreds/models/presentation_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class Meta:
},
),
},
name="AnoncredPresentationRequestNonRevokedSchema",
name="AnoncredsPresentationRequestNonRevokedSchema",
),
allow_none=True,
required=False,
Expand Down
2 changes: 1 addition & 1 deletion acapy_agent/askar/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def bind_providers(self):
VCHolder,
ClassProvider(
"acapy_agent.storage.vc_holder.askar.AskarVCHolder",
ref(self),
ClassProvider.Inject(Profile),
),
)
if (
Expand Down
19 changes: 13 additions & 6 deletions acapy_agent/messaging/valid.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,20 @@ def __init__(self):


class AnoncredsDID(Regexp):
"""Validate value against indy DID."""
"""Validate value against anoncreds DID."""

METHOD = r"([a-zA-Z0-9_]+)"
NETWORK = r"(:[a-zA-Z0-9_.%-]+)?" # Optional network
METHOD_ID = r"([a-zA-Z0-9_.%-]+(:[a-zA-Z0-9_.%-]+)*)"

EXAMPLE = "did:(method):WgWxqztrNooG92RXvxSTWv"
PATTERN = re.compile("^(did:[a-z]:.+$)?$")
PATTERN = re.compile(rf"^did:{METHOD}{NETWORK}:{METHOD_ID}")

def __init__(self):
"""Initialize the instance."""

super().__init__(
IndyDID.PATTERN,
DIDValidation.PATTERN,
error="Value {input} is not an decentralized identifier (DID)",
)

Expand All @@ -381,14 +385,17 @@ class DIDValidation(Regexp):
"""Validate value against any valid DID spec."""

METHOD = r"([a-zA-Z0-9_]+)"
NETWORK = r"(:[a-zA-Z0-9_.%-]+)?" # Optional network
METHOD_ID = r"([a-zA-Z0-9_.%-]+(:[a-zA-Z0-9_.%-]+)*)"
PARAMS = r"((;[a-zA-Z0-9_.:%-]+=[a-zA-Z0-9_.:%-]*)*)"
PATH = r"(\/[^#?]*)?"
QUERY = r"([?][^#]*)?"
FRAGMENT = r"(\#.*)?$"

EXAMPLE = "did:peer:WgWxqztrNooG92RXvxSTWv"
PATTERN = re.compile(rf"^did:{METHOD}:{METHOD_ID}{PARAMS}{PATH}{QUERY}{FRAGMENT}$")
PATTERN = re.compile(
rf"^did:{METHOD}{NETWORK}:{METHOD_ID}{PARAMS}{PATH}{QUERY}{FRAGMENT}$"
)

def __init__(self):
"""Initialize the instance."""
Expand Down Expand Up @@ -485,7 +492,7 @@ def __init__(self):
"""Initialize the instance."""

super().__init__(
IndyCredDefId.PATTERN,
AnoncredsCredDefId.PATTERN,
error="Value {input} is not an anoncreds credential definition identifier",
)

Expand Down Expand Up @@ -530,7 +537,7 @@ def __init__(self):
"""Initialize the instance."""

super().__init__(
IndySchemaId.PATTERN,
AnoncredsSchemaId.PATTERN,
error="Value {input} is not an anoncreds schema identifier",
)

Expand Down
8 changes: 4 additions & 4 deletions acapy_agent/protocols/issue_credential/v2_0/message_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,25 @@
# Format specifications
ATTACHMENT_FORMAT = {
CRED_20_PROPOSAL: {
V20CredFormat.Format.ANONCREDS.api: "anoncreds/cred-filter@v2.0",
V20CredFormat.Format.ANONCREDS.api: "anoncreds/credential-filter@v1.0",
V20CredFormat.Format.INDY.api: "hlindy/cred-filter@v2.0",
V20CredFormat.Format.LD_PROOF.api: "aries/ld-proof-vc-detail@v1.0",
V20CredFormat.Format.VC_DI.api: "didcomm/w3c-di-vc@v0.1",
},
CRED_20_OFFER: {
V20CredFormat.Format.ANONCREDS.api: "anoncreds/cred-abstract@v2.0",
V20CredFormat.Format.ANONCREDS.api: "anoncreds/credential-offer@v1.0",
V20CredFormat.Format.INDY.api: "hlindy/cred-abstract@v2.0",
V20CredFormat.Format.LD_PROOF.api: "aries/ld-proof-vc-detail@v1.0",
V20CredFormat.Format.VC_DI.api: "didcomm/w3c-di-vc-offer@v0.1",
},
CRED_20_REQUEST: {
V20CredFormat.Format.ANONCREDS.api: "anoncreds/cred-req@v2.0",
V20CredFormat.Format.ANONCREDS.api: "anoncreds/credential-request@v1.0",
V20CredFormat.Format.INDY.api: "hlindy/cred-req@v2.0",
V20CredFormat.Format.LD_PROOF.api: "aries/ld-proof-vc-detail@v1.0",
V20CredFormat.Format.VC_DI.api: "didcomm/w3c-di-vc-request@v0.1",
},
CRED_20_ISSUE: {
V20CredFormat.Format.ANONCREDS.api: "anoncreds/cred@v2.0",
V20CredFormat.Format.ANONCREDS.api: "anoncreds/credential@v1.0",
V20CredFormat.Format.INDY.api: "hlindy/cred@v2.0",
V20CredFormat.Format.LD_PROOF.api: "aries/ld-proof-vc@v1.0",
V20CredFormat.Format.VC_DI.api: "didcomm/w3c-di-vc@v0.1",
Expand Down
25 changes: 20 additions & 5 deletions acapy_agent/protocols/issue_credential/v2_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from ....messaging.models.openapi import OpenAPISchema
from ....messaging.models.paginated_query import PaginatedQuerySchema, get_limit_offset
from ....messaging.valid import (
ANONCREDS_CRED_DEF_ID_EXAMPLE,
ANONCREDS_DID_EXAMPLE,
ANONCREDS_SCHEMA_ID_EXAMPLE,
INDY_CRED_DEF_ID_EXAMPLE,
Expand Down Expand Up @@ -137,13 +138,24 @@ class V20CredStoreRequestSchema(OpenAPISchema):
class V20CredFilterAnoncredsSchema(OpenAPISchema):
"""Anoncreds credential filtration criteria."""

cred_def_id = fields.Str(
schema_issuer_id = fields.Str(
required=False,
metadata={
"description": "Credential definition identifier",
"description": "Schema issuer ID",
"example": ANONCREDS_DID_EXAMPLE,
},
)
schema_name = fields.Str(
required=False,
metadata={"description": "Schema name", "example": "preferences"},
)
schema_version = fields.Str(
required=False,
metadata={
"description": "Schema version",
"example": MAJOR_MINOR_VERSION_EXAMPLE,
},
)
schema_id = fields.Str(
required=False,
metadata={
Expand All @@ -154,13 +166,16 @@ class V20CredFilterAnoncredsSchema(OpenAPISchema):
issuer_id = fields.Str(
required=False,
metadata={
"description": "Credential issuer DID",
"description": "Credential issuer ID",
"example": ANONCREDS_DID_EXAMPLE,
},
)
epoch = fields.Str(
cred_def_id = fields.Str(
required=False,
metadata={"description": "Credential epoch time", "example": "2021-08-24"},
metadata={
"description": "Credential definition identifier",
"example": ANONCREDS_CRED_DEF_ID_EXAMPLE,
},
)


Expand Down
23 changes: 23 additions & 0 deletions acapy_agent/protocols/issue_credential/v2_0/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ async def test_validate_cred_filter_schema(self):
with self.assertRaises(test_module.ValidationError):
schema.validate_fields({"veres-one": {"no": "support"}})

async def test_validate_cred_filter_anoncreds_schema(self):
schema = test_module.V20CredFilterSchema()
schema.validate_fields({"anoncreds": {"issuer_id": TEST_DID}})
schema.validate_fields(
{"anoncreds": {"issuer_id": TEST_DID, "schema_version": "1.0"}}
)
schema.validate_fields(
{
"anoncreds": {"issuer_id": TEST_DID},
}
)
schema.validate_fields(
{
"anoncreds": {},
}
)
with self.assertRaises(test_module.ValidationError):
schema.validate_fields({})
with self.assertRaises(test_module.ValidationError):
schema.validate_fields(["hopeless", "stop"])
with self.assertRaises(test_module.ValidationError):
schema.validate_fields({"veres-one": {"no": "support"}})

async def test_validate_create_schema(self):
schema = test_module.V20IssueCredSchemaCore()
schema.validate(
Expand Down
6 changes: 3 additions & 3 deletions acapy_agent/protocols/present_proof/v2_0/message_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
# Format specifications
ATTACHMENT_FORMAT = {
PRES_20_PROPOSAL: {
V20PresFormat.Format.ANONCREDS.api: "anoncreds/proof-req@v2.0",
V20PresFormat.Format.ANONCREDS.api: "anoncreds/proof-proposal@v1.0",
V20PresFormat.Format.INDY.api: "hlindy/proof-req@v2.0",
V20PresFormat.Format.DIF.api: "dif/presentation-exchange/definitions@v1.0",
},
PRES_20_REQUEST: {
V20PresFormat.Format.ANONCREDS.api: "anoncreds/proof-req@v2.0",
V20PresFormat.Format.ANONCREDS.api: "anoncreds/proof-request@v1.0",
V20PresFormat.Format.INDY.api: "hlindy/proof-req@v2.0",
V20PresFormat.Format.DIF.api: "dif/presentation-exchange/definitions@v1.0",
},
PRES_20: {
V20PresFormat.Format.ANONCREDS.api: "anoncreds/proof@v2.0",
V20PresFormat.Format.ANONCREDS.api: "anoncreds/proof@v1.0",
V20PresFormat.Format.INDY.api: "hlindy/proof@v2.0",
V20PresFormat.Format.DIF.api: "dif/presentation-exchange/submission@v1.0",
},
Expand Down
Loading

0 comments on commit 13a7461

Please sign in to comment.