Skip to content

Commit

Permalink
VCR: Make VCR.SearchVCs() according to spec (#1051)
Browse files Browse the repository at this point in the history
Co-authored-by: Rein Krul <[email protected]>
  • Loading branch information
reinkrul and reinkrul authored Apr 29, 2022
1 parent 710253d commit 78c1928
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
27 changes: 17 additions & 10 deletions vcr/api/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,11 @@ func (w *Wrapper) SearchIssuedVCs(ctx echo.Context, params SearchIssuedVCsParams
if err != nil {
return err
}
result := make([]SearchVCResult, len(foundVCs))
for i, resolvedVC := range foundVCs {
var revocation *Revocation
revocation, err = w.VCR.Verifier().GetRevocation(*resolvedVC.ID)
if err != nil && !errors.Is(err, verifier.ErrNotFound) {
return err
}
result[i] = SearchVCResult{VerifiableCredential: resolvedVC, Revocation: revocation}
result, err := w.vcsWithRevocationsToSearchResults(foundVCs)
if err != nil {
return err
}

return ctx.JSON(http.StatusOK, SearchVCResults{VerifiableCredentials: result})
return ctx.JSON(http.StatusOK, SearchVCResults{result})
}

// VerifyVC handles API request to verify a Verifiable Credential.
Expand Down Expand Up @@ -335,6 +329,19 @@ func (w *Wrapper) ListUntrusted(ctx echo.Context, credentialType string) error {
return ctx.JSON(http.StatusOK, result)
}

func (w *Wrapper) vcsWithRevocationsToSearchResults(foundVCs []vc.VerifiableCredential) ([]SearchVCResult, error) {
result := make([]SearchVCResult, len(foundVCs))
for i, resolvedVC := range foundVCs {
var revocation *Revocation
revocation, err := w.VCR.Verifier().GetRevocation(*resolvedVC.ID)
if err != nil && !errors.Is(err, verifier.ErrNotFound) {
return nil, nil
}
result[i] = SearchVCResult{VerifiableCredential: resolvedVC, Revocation: revocation}
}
return result, nil
}

type trustChangeFunc func(ssi.URI, ssi.URI) error

func changeTrust(ctx echo.Context, f trustChangeFunc) error {
Expand Down
7 changes: 5 additions & 2 deletions vcr/api/v2/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ func (w *Wrapper) searchOrgs(ctx echo.Context, allowUntrusted bool, vcQuery vc.V
if err != nil {
return err
}

return ctx.JSON(http.StatusOK, results)
searchResults, err := w.vcsWithRevocationsToSearchResults(results)
if err != nil {
return err
}
return ctx.JSON(http.StatusOK, SearchVCResults{searchResults})
}

func (w *Wrapper) searchAuths(ctx echo.Context, allowUntrusted bool, vcQuery vc.VerifiableCredential) error {
Expand Down
4 changes: 2 additions & 2 deletions vcr/api/v2/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestWrapper_SearchVCs(t *testing.T) {
return []VerifiableCredential{}, nil
},
)
ctx.echo.EXPECT().JSON(http.StatusOK, []VerifiableCredential{})
ctx.echo.EXPECT().JSON(http.StatusOK, SearchVCResults{[]SearchVCResult{}})

err := ctx.client.SearchVCs(ctx.echo)

Expand Down Expand Up @@ -179,7 +179,7 @@ func TestWrapper_SearchVCs(t *testing.T) {
_ = json.Unmarshal([]byte(untrustedOrganizationQuery), f)
})
ctx.vcr.EXPECT().Search(context.Background(), gomock.Any(), true, nil).Return([]VerifiableCredential{}, nil)
ctx.echo.EXPECT().JSON(http.StatusOK, []VerifiableCredential{})
ctx.echo.EXPECT().JSON(http.StatusOK, SearchVCResults{[]SearchVCResult{}})

err := ctx.client.SearchVCs(ctx.echo)

Expand Down

0 comments on commit 78c1928

Please sign in to comment.