Skip to content

Commit b7e5530

Browse files
authored
VCR: Fix broken First() operation which breaks retrieving StatusList credential on MS SQL Server (#3452)
Signed-off-by: Rein Krul <[email protected]>
1 parent 0728580 commit b7e5530

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

e2e-tests/oauth-flow/rfc021/do-test.sh

+20-6
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ echo Vendor B DID: $VENDOR_B_DID
4545

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

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

66+
# Test regression for https://github.com/nuts-foundation/nuts-node/issues/3451
67+
# (VCR: Status List can't be retrieved when using MS SQL Server)
68+
# Get credential status URL from credentialStatus.statusListCredential property using jq
69+
STATUS_LIST_CREDENTIAL=$(echo $VENDOR_B_CREDENTIAL | jq -r .credentialStatus.statusListCredential)
70+
echo "Status list credential: $STATUS_LIST_CREDENTIAL"
71+
# Get status list credential
72+
RESPONSE=$($db_dc exec nodeB-backend curl -s -k $STATUS_LIST_CREDENTIAL)
73+
# Check response HTTP 200 OK
74+
if [ $? -eq 0 ]; then
75+
echo "Status list credential retrieved"
76+
else
77+
echo "FAILED: Could not retrieve status list credential" 1>&2
78+
echo $RESPONSE
79+
exitWithDockerLogs 1
80+
fi
81+
6682
# Register vendor B on Discovery Service
6783
echo "Registering vendor B on Discovery Service..."
6884
REQUEST="{\"registrationParameters\":{\"key\":\"value\"}}"
@@ -167,8 +183,6 @@ else
167183
exitWithDockerLogs 1
168184
fi
169185

170-
171-
172186
echo "------------------------------------"
173187
echo "Retrieving data..."
174188
echo "------------------------------------"

vcr/revocation/statuslist2021_issuer.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ func (cs *StatusList2021) loadCredential(subjectID string) (*credentialRecord, e
118118
// isManaged returns true if the StatusList2021Credential is issued by this node.
119119
// returns false on db errors, or if the StatusList2021Credential does not exist.
120120
func (cs *StatusList2021) isManaged(subjectID string) bool {
121-
var exists bool
121+
var count int
122122
cs.db.Model(new(credentialIssuerRecord)).
123-
Select("count(*) > 0").
123+
Select("count(*)").
124124
Group("subject_id").
125125
Where("subject_id = ?", subjectID).
126-
First(&exists)
127-
return exists
126+
Find(&count)
127+
return count > 0
128128
}
129129

130130
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
426426
Select("count(*) > 0").
427427
Group("subject_id").
428428
Where("subject_id = ?", entry.StatusListCredential).
429-
First(new(bool)).
429+
Find(new([]bool)).
430430
Error
431431
if err != nil {
432432
return err

0 commit comments

Comments
 (0)