From 8c06e74084cd735de7ba36a3f2dcbee42ee2eac1 Mon Sep 17 00:00:00 2001 From: Rein Krul Date: Mon, 7 Oct 2024 14:12:23 +0200 Subject: [PATCH] VCR: Fix broken First() operation which breaks retrieving StatusList credential on MS SQL Server Signed-off-by: Rein Krul --- e2e-tests/oauth-flow/rfc021/do-test.sh | 26 +++++++++++++++++++------ vcr/revocation/statuslist2021_issuer.go | 10 +++++----- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/e2e-tests/oauth-flow/rfc021/do-test.sh b/e2e-tests/oauth-flow/rfc021/do-test.sh index c28fce6bf..a91234153 100755 --- a/e2e-tests/oauth-flow/rfc021/do-test.sh +++ b/e2e-tests/oauth-flow/rfc021/do-test.sh @@ -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 @@ -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\"}}" @@ -167,8 +183,6 @@ else exitWithDockerLogs 1 fi - - echo "------------------------------------" echo "Retrieving data..." echo "------------------------------------" diff --git a/vcr/revocation/statuslist2021_issuer.go b/vcr/revocation/statuslist2021_issuer.go index 9ea538a11..cd02ca911 100644 --- a/vcr/revocation/statuslist2021_issuer.go +++ b/vcr/revocation/statuslist2021_issuer.go @@ -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) { @@ -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