Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 7e6e5f7

Browse files
committed
refactor: change xeipuuv/gojsonschema to santhosh-tekuri/jsonschema package inside verifiable presentation. Refactor related unit tests
Signed-off-by: Abdulbois <[email protected]>
1 parent 5d09324 commit 7e6e5f7

File tree

12 files changed

+41
-26
lines changed

12 files changed

+41
-26
lines changed

cmd/aries-agent-mobile/go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ go 1.19
88

99
require (
1010
github.com/google/uuid v1.3.0
11-
github.com/hyperledger/aries-framework-go v0.1.8-0.20220322085443-50e8f9bd208b
12-
github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220322085443-50e8f9bd208b
11+
github.com/hyperledger/aries-framework-go v0.1.9-0.20221007132211-6233891ce372
12+
github.com/hyperledger/aries-framework-go/component/storageutil v0.1.9-0.20221007132211-6233891ce372
1313
github.com/hyperledger/aries-framework-go/spi v0.0.0-20220606124520-53422361c38c
1414
github.com/hyperledger/aries-framework-go/test/component v0.0.0-20220428211718-66cc046674a1
1515
github.com/piprate/json-gold v0.4.1
@@ -49,6 +49,7 @@ require (
4949
github.com/pmezard/go-difflib v1.0.0 // indirect
5050
github.com/pquerna/cachecontrol v0.1.0 // indirect
5151
github.com/rs/cors v1.7.0 // indirect
52+
github.com/santhosh-tekuri/jsonschema v1.2.4 // indirect
5253
github.com/spaolacci/murmur3 v1.1.0 // indirect
5354
github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 // indirect
5455
github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8 // indirect

cmd/aries-agent-mobile/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
270270
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
271271
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
272272
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
273+
github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis=
274+
github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4=
273275
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
274276
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
275277
github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 h1:wD1IWQwAhdWclCwaf6DdzgCAe9Bfz1M+4AHRd7N786Y=

cmd/aries-agent-rest/go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ go 1.19
99
require (
1010
github.com/cenkalti/backoff/v4 v4.1.2
1111
github.com/gorilla/mux v1.7.3
12-
github.com/hyperledger/aries-framework-go v0.1.8-0.20220322085443-50e8f9bd208b
13-
github.com/hyperledger/aries-framework-go/component/storage/leveldb v0.0.0-20220322085443-50e8f9bd208b
14-
github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220322085443-50e8f9bd208b
12+
github.com/hyperledger/aries-framework-go v0.1.9-0.20221007132211-6233891ce372
13+
github.com/hyperledger/aries-framework-go/component/storage/leveldb v0.1.9-0.20221007132211-6233891ce372
14+
github.com/hyperledger/aries-framework-go/component/storageutil v0.1.9-0.20221007132211-6233891ce372
1515
github.com/hyperledger/aries-framework-go/spi v0.0.0-20220606124520-53422361c38c
1616
github.com/rs/cors v1.7.0
1717
github.com/spf13/cobra v1.0.0
@@ -65,6 +65,7 @@ require (
6565
github.com/pkg/errors v0.9.1 // indirect
6666
github.com/pmezard/go-difflib v1.0.0 // indirect
6767
github.com/pquerna/cachecontrol v0.1.0 // indirect
68+
github.com/santhosh-tekuri/jsonschema v1.2.4 // indirect
6869
github.com/spaolacci/murmur3 v1.1.0 // indirect
6970
github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 // indirect
7071
github.com/syndtr/goleveldb v1.0.0 // indirect

cmd/aries-agent-rest/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,8 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb
632632
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
633633
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
634634
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
635+
github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis=
636+
github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4=
635637
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
636638
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
637639
github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=

cmd/aries-js-worker/go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ go 1.19
88

99
require (
1010
github.com/google/uuid v1.3.0
11-
github.com/hyperledger/aries-framework-go v0.1.8-0.20220322085443-50e8f9bd208b
12-
github.com/hyperledger/aries-framework-go/component/storage/indexeddb v0.1.8-0.20220322085443-50e8f9bd208b
11+
github.com/hyperledger/aries-framework-go v0.1.9-0.20221007132211-6233891ce372
12+
github.com/hyperledger/aries-framework-go/component/storage/indexeddb v0.1.9-0.20221007132211-6233891ce372
1313
github.com/hyperledger/aries-framework-go/spi v0.0.0-20220606124520-53422361c38c
1414
github.com/mitchellh/mapstructure v1.3.0
1515
github.com/stretchr/testify v1.7.2
@@ -48,6 +48,7 @@ require (
4848
github.com/pmezard/go-difflib v1.0.0 // indirect
4949
github.com/pquerna/cachecontrol v0.1.0 // indirect
5050
github.com/rs/cors v1.7.0 // indirect
51+
github.com/santhosh-tekuri/jsonschema v1.2.4 // indirect
5152
github.com/spaolacci/murmur3 v1.1.0 // indirect
5253
github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 // indirect
5354
github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8 // indirect

cmd/aries-js-worker/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
269269
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
270270
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
271271
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
272+
github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis=
273+
github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4=
272274
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
273275
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
274276
github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 h1:wD1IWQwAhdWclCwaf6DdzgCAe9Bfz1M+4AHRd7N786Y=

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ require (
3030
github.com/piprate/json-gold v0.4.1
3131
github.com/pkg/errors v0.9.1
3232
github.com/rs/cors v1.7.0
33+
github.com/santhosh-tekuri/jsonschema v1.2.4
3334
github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693
3435
github.com/stretchr/testify v1.7.2
3536
github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
317317
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
318318
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
319319
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
320+
github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis=
321+
github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4=
320322
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
321323
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
322324
github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 h1:wD1IWQwAhdWclCwaf6DdzgCAe9Bfz1M+4AHRd7N786Y=

pkg/doc/verifiable/presentation.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ SPDX-License-Identifier: Apache-2.0
66
package verifiable
77

88
import (
9+
"bytes"
910
"encoding/json"
1011
"errors"
1112
"fmt"
13+
"strings"
1214

1315
jsonld "github.com/piprate/json-gold/ld"
14-
"github.com/xeipuuv/gojsonschema"
16+
"github.com/santhosh-tekuri/jsonschema"
1517

1618
"github.com/hyperledger/aries-framework-go/pkg/doc/jose"
1719
docjsonld "github.com/hyperledger/aries-framework-go/pkg/doc/jsonld"
@@ -157,7 +159,12 @@ const basePresentationSchema = `
157159
`
158160

159161
//nolint:gochecknoglobals
160-
var basePresentationSchemaLoader = gojsonschema.NewStringLoader(basePresentationSchema)
162+
var (
163+
schemaName = "presentationSchema"
164+
schemaCompiler = jsonschema.NewCompiler()
165+
_ = schemaCompiler.AddResource(schemaName, strings.NewReader(basePresentationSchema))
166+
presentationSchema = schemaCompiler.MustCompile(schemaName)
167+
)
161168

162169
// MarshalledCredential defines marshalled Verifiable Credential enclosed into Presentation.
163170
// MarshalledCredential can be passed to verifiable.ParseCredential().
@@ -568,16 +575,9 @@ func validateVPJSONLD(vpBytes []byte, opts *presentationOpts) error {
568575
}
569576

570577
func validateVPJSONSchema(data []byte) error {
571-
loader := gojsonschema.NewStringLoader(string(data))
572-
573-
result, err := gojsonschema.Validate(basePresentationSchemaLoader, loader)
578+
err := presentationSchema.Validate(bytes.NewReader(data))
574579
if err != nil {
575-
return fmt.Errorf("validation of verifiable credential: %w", err)
576-
}
577-
578-
if !result.Valid() {
579-
errMsg := describeSchemaValidationError(result, "verifiable presentation")
580-
return errors.New(errMsg)
580+
return fmt.Errorf("verifiable presentation is not valid: %w", err)
581581
}
582582

583583
return nil

pkg/doc/verifiable/presentation_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func TestValidateVP_Context(t *testing.T) {
304304
require.NoError(t, err)
305305
vp, err := newTestPresentation(t, bytes)
306306
require.Error(t, err)
307-
require.Contains(t, err.Error(), "@context is required")
307+
require.Contains(t, err.Error(), "missing properties: \"@context\"")
308308
require.Nil(t, vp)
309309
})
310310

@@ -319,7 +319,7 @@ func TestValidateVP_Context(t *testing.T) {
319319
require.NoError(t, err)
320320
vp, err := newTestPresentation(t, bytes)
321321
require.Error(t, err)
322-
require.Contains(t, err.Error(), "does not match: \"https://www.w3.org/2018/credentials/v1\"")
322+
require.Contains(t, err.Error(), "must be \"https://www.w3.org/2018/credentials/v1\"")
323323
require.Nil(t, vp)
324324
})
325325

@@ -342,7 +342,7 @@ func TestValidateVP_Context(t *testing.T) {
342342
require.NoError(t, err)
343343
vp, err := newTestPresentation(t, bytes)
344344
require.Error(t, err)
345-
require.Contains(t, err.Error(), "does not match: \"https://www.w3.org/2018/credentials/v1\"")
345+
require.Contains(t, err.Error(), "must be \"https://www.w3.org/2018/credentials/v1\"")
346346
require.Nil(t, vp)
347347
})
348348
}
@@ -356,7 +356,7 @@ func TestValidateVP_ID(t *testing.T) {
356356
require.NoError(t, err)
357357
vp, err := newTestPresentation(t, bytes)
358358
require.Error(t, err)
359-
require.Contains(t, err.Error(), "id: Does not match format 'uri'")
359+
require.Contains(t, err.Error(), "\"not valid presentation ID URL\" is not valid \"uri\"")
360360
require.Nil(t, vp)
361361
})
362362
}
@@ -402,7 +402,7 @@ func TestValidateVP_Type(t *testing.T) {
402402
require.NoError(t, err)
403403
vp, err := newTestPresentation(t, bytes)
404404
require.Error(t, err)
405-
require.Contains(t, err.Error(), "type is required")
405+
require.Contains(t, err.Error(), "missing properties: \"type\"")
406406
require.Nil(t, vp)
407407
})
408408

@@ -414,7 +414,7 @@ func TestValidateVP_Type(t *testing.T) {
414414
require.NoError(t, err)
415415
vp, err := newTestPresentation(t, bytes)
416416
require.Error(t, err)
417-
require.Contains(t, err.Error(), "Does not match pattern '^VerifiablePresentation$'")
417+
require.Contains(t, err.Error(), "does not match pattern \"^VerifiablePresentation$\"")
418418
require.Nil(t, vp)
419419
})
420420
}
@@ -428,7 +428,7 @@ func TestValidateVP_Holder(t *testing.T) {
428428
require.NoError(t, err)
429429
vp, err := newTestPresentation(t, bytes)
430430
require.Error(t, err)
431-
require.Contains(t, err.Error(), "holder: Does not match format 'uri'")
431+
require.Contains(t, err.Error(), "not valid presentation Holder URL\" is not valid \"uri\"")
432432
require.Nil(t, vp)
433433
})
434434
}

test/bdd/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/fsouza/go-dockerclient v1.6.6
1414
github.com/google/uuid v1.3.0
1515
github.com/gorilla/mux v1.8.0
16-
github.com/hyperledger/aries-framework-go v0.1.8-0.20220322085443-50e8f9bd208b
16+
github.com/hyperledger/aries-framework-go v0.1.9-0.20221007132211-6233891ce372
1717
github.com/hyperledger/aries-framework-go/component/storage/leveldb v0.0.0-20220322085443-50e8f9bd208b
1818
github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220322085443-50e8f9bd208b
1919
github.com/hyperledger/aries-framework-go/spi v0.0.0-20220606124520-53422361c38c
@@ -72,6 +72,7 @@ require (
7272
github.com/pmezard/go-difflib v1.0.0 // indirect
7373
github.com/pquerna/cachecontrol v0.1.0 // indirect
7474
github.com/rs/cors v1.7.0 // indirect
75+
github.com/santhosh-tekuri/jsonschema v1.2.4 // indirect
7576
github.com/sirupsen/logrus v1.7.0 // indirect
7677
github.com/spaolacci/murmur3 v1.1.0 // indirect
7778
github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 // indirect

test/bdd/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
423423
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
424424
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
425425
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
426+
github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis=
427+
github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4=
426428
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
427429
github.com/sirupsen/logrus v1.0.4-0.20170822132746-89742aefa4b2/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
428430
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=

0 commit comments

Comments
 (0)