Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCR: Fix broken First() operation which breaks retrieving StatusList credential on MS SQL Server #3452

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading