Skip to content

Commit

Permalink
Discovery: fix GetActivationStatus on MS SQL Server (#3443)
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul authored Oct 4, 2024
1 parent d888d2c commit c39b68c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
11 changes: 9 additions & 2 deletions discovery/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ type presentationRefreshRecord struct {
// Parameters is a serialized JSON object containing parameters that should be used when registering the subject on the service.
Parameters []byte
// PresentationRefreshError is the error message that occurred during the refresh attempt.
PresentationRefreshError presentationRefreshError `gorm:"foreignKey:ServiceID,SubjectID"`
// It's loaded using a spearate query instead of using GORM's Preload, which fails on MS SQL Server if it spans multiple columns
// See https://github.com/nuts-foundation/nuts-node/issues/3442
PresentationRefreshError presentationRefreshError `gorm:"-"`
}

// TableName returns the table name for this DTO.
Expand Down Expand Up @@ -353,12 +355,17 @@ func (s *sqlStore) updatePresentationRefreshTime(serviceID string, subjectID str

func (s *sqlStore) getPresentationRefreshRecord(serviceID string, subjectID string) (*presentationRefreshRecord, error) {
var row presentationRefreshRecord
if err := s.db.Preload("PresentationRefreshError").Find(&row, "service_id = ? AND subject_id = ?", serviceID, subjectID).Error; err != nil {
if err := s.db.Find(&row, "service_id = ? AND subject_id = ?", serviceID, subjectID).Error; err != nil {
return nil, err
}
if row.NextRefresh == 0 {
return nil, nil
}
// Load presentationRefreshError using a spearate query instead of using GORM's Preload, which fails on MS SQL Server if it spans multiple columns
// See https://github.com/nuts-foundation/nuts-node/issues/3442
if err := s.db.Find(&row.PresentationRefreshError, "service_id = ? AND subject_id = ?", serviceID, subjectID).Error; err != nil {
return nil, err
}
return &row, nil
}

Expand Down
13 changes: 13 additions & 0 deletions e2e-tests/oauth-flow/rfc021/do-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ else
exitWithDockerLogs 1
fi

# Test regression for https://github.com/nuts-foundation/nuts-node/issues/3442
# (Discovery: GetActivationStatus fails on MS SQL Server)
echo "Getting activation status from Discovery Service..."
RESPONSE=$(curl -s http://localhost:28081/internal/discovery/v1/e2e-test/vendorB)
echo $RESPONSE
if echo $RESPONSE | grep -q "true"; then
echo "Activation status OK"
else
echo "FAILED: Could not get activation status of vendor B on Discovery Service" 1>&2
echo $RESPONSE
exitWithDockerLogs 1
fi

echo "---------------------------------------"
echo "Perform OAuth 2.0 rfc021 flow..."
echo "---------------------------------------"
Expand Down
6 changes: 4 additions & 2 deletions e2e-tests/oauth-flow/rfc021/shared/discovery/definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@
},
{
"path": [
"$.credentialSubject.organization.name"
"$.credentialSubject.organization.name",
"$.credentialSubject[0].organization.name"
],
"filter": {
"type": "string"
}
},
{
"path": [
"$.credentialSubject.organization.city"
"$.credentialSubject.organization.city",
"$.credentialSubject[0].organization.city"
],
"filter": {
"type": "string"
Expand Down
2 changes: 2 additions & 0 deletions vcr/revocation/statuslist2021_issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (cs *StatusList2021) isManaged(subjectID string) bool {
var exists bool
cs.db.Model(new(credentialIssuerRecord)).
Select("count(*) > 0").
Group("subject_id").
Where("subject_id = ?", subjectID).
First(&exists)
return exists
Expand Down Expand Up @@ -423,6 +424,7 @@ func (cs *StatusList2021) Revoke(ctx context.Context, credentialID ssi.URI, entr
err = tx.Model(new(credentialRecord)).
Clauses(clause.Locking{Strength: clause.LockingStrengthUpdate}).
Select("count(*) > 0").
Group("subject_id").
Where("subject_id = ?", entry.StatusListCredential).
First(new(bool)).
Error
Expand Down

0 comments on commit c39b68c

Please sign in to comment.