Skip to content

Commit

Permalink
VCR: Fix broken First() operation which breaks retrieving StatusList …
Browse files Browse the repository at this point in the history
…credential on MS SQL Server (#3452)

Signed-off-by: Rein Krul <[email protected]>
  • Loading branch information
reinkrul authored Oct 7, 2024
1 parent 0728580 commit b7e5530
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
26 changes: 20 additions & 6 deletions e2e-tests/oauth-flow/rfc021/do-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ echo Vendor B DID: $VENDOR_B_DID

# Issue NutsOrganizationCredential for Vendor B
REQUEST="{\"type\":\"NutsOrganizationCredential\",\"issuer\":\"${VENDOR_B_DID}\", \"credentialSubject\": {\"id\":\"${VENDOR_B_DID}\", \"organization\":{\"name\":\"Caresoft B.V.\", \"city\":\"Caretown\"}},\"withStatusList2021Revocation\": true}"
RESPONSE=$(echo $REQUEST | curl -X POST --data-binary @- http://localhost:28081/internal/vcr/v2/issuer/vc -H "Content-Type:application/json")
if echo $RESPONSE | grep -q "VerifiableCredential"; then
VENDOR_B_CREDENTIAL=$(echo $REQUEST | curl -X POST --data-binary @- http://localhost:28081/internal/vcr/v2/issuer/vc -H "Content-Type:application/json")
if echo $VENDOR_B_CREDENTIAL | grep -q "VerifiableCredential"; then
echo "VC issued"
else
echo "FAILED: Could not issue NutsOrganizationCredential to node-B" 1>&2
echo $RESPONSE
echo $VENDOR_B_CREDENTIAL
exitWithDockerLogs 1
fi

RESPONSE=$(echo $RESPONSE | curl -X POST --data-binary @- http://localhost:28081/internal/vcr/v2/holder/vendorB/vc -H "Content-Type:application/json")
RESPONSE=$(echo $VENDOR_B_CREDENTIAL | curl -X POST --data-binary @- http://localhost:28081/internal/vcr/v2/holder/vendorB/vc -H "Content-Type:application/json")
if echo $RESPONSE == ""; then
echo "VC stored in wallet"
else
Expand All @@ -63,6 +63,22 @@ else
exitWithDockerLogs 1
fi

# Test regression for https://github.com/nuts-foundation/nuts-node/issues/3451
# (VCR: Status List can't be retrieved when using MS SQL Server)
# Get credential status URL from credentialStatus.statusListCredential property using jq
STATUS_LIST_CREDENTIAL=$(echo $VENDOR_B_CREDENTIAL | jq -r .credentialStatus.statusListCredential)
echo "Status list credential: $STATUS_LIST_CREDENTIAL"
# Get status list credential
RESPONSE=$($db_dc exec nodeB-backend curl -s -k $STATUS_LIST_CREDENTIAL)
# Check response HTTP 200 OK
if [ $? -eq 0 ]; then
echo "Status list credential retrieved"
else
echo "FAILED: Could not retrieve status list credential" 1>&2
echo $RESPONSE
exitWithDockerLogs 1
fi

# Register vendor B on Discovery Service
echo "Registering vendor B on Discovery Service..."
REQUEST="{\"registrationParameters\":{\"key\":\"value\"}}"
Expand Down Expand Up @@ -167,8 +183,6 @@ else
exitWithDockerLogs 1
fi



echo "------------------------------------"
echo "Retrieving data..."
echo "------------------------------------"
Expand Down
10 changes: 5 additions & 5 deletions vcr/revocation/statuslist2021_issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ func (cs *StatusList2021) loadCredential(subjectID string) (*credentialRecord, e
// isManaged returns true if the StatusList2021Credential is issued by this node.
// returns false on db errors, or if the StatusList2021Credential does not exist.
func (cs *StatusList2021) isManaged(subjectID string) bool {
var exists bool
var count int
cs.db.Model(new(credentialIssuerRecord)).
Select("count(*) > 0").
Select("count(*)").
Group("subject_id").
Where("subject_id = ?", subjectID).
First(&exists)
return exists
Find(&count)
return count > 0
}

func (cs *StatusList2021) Credential(ctx context.Context, issuerDID did.DID, page int) (*vc.VerifiableCredential, error) {
Expand Down Expand Up @@ -426,7 +426,7 @@ func (cs *StatusList2021) Revoke(ctx context.Context, credentialID ssi.URI, entr
Select("count(*) > 0").
Group("subject_id").
Where("subject_id = ?", entry.StatusListCredential).
First(new(bool)).
Find(new([]bool)).
Error
if err != nil {
return err
Expand Down

0 comments on commit b7e5530

Please sign in to comment.