-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathcredential_testsuite_test.go
102 lines (84 loc) · 2.8 KB
/
credential_testsuite_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//go:build testsuite
// +build testsuite
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
This is not actually a test but rather a stand-alone generator application
that is used by VC Test Suite (https://github.com/w3c/vc-test-suite).
To run VC Test Suite, execute `make vc-test-suite`.
*/
package verifiable
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
)
// nolint:lll
const validEmptyPresentation = `
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1",
"https://trustbloc.github.io/context/vc/examples-v1.jsonld"
],
"id": "urn:uuid:3978344f-8596-4c3a-a978-8fcaba3903c5",
"type": "VerifiablePresentation",
"holder": "did:example:ebfeb1f712ebc6f1c276e12ec21"
}
`
func TestWithNoProofCheck(t *testing.T) {
credentialOpt := WithNoProofCheck()
require.NotNil(t, credentialOpt)
opts := &credentialOpts{}
credentialOpt(opts)
require.True(t, opts.disabledProofCheck)
}
func TestWithPresSkippedEmbeddedProofCheck(t *testing.T) {
vpOpt := WithPresNoProofCheck()
require.NotNil(t, vpOpt)
opts := &presentationOpts{}
vpOpt(opts)
require.True(t, opts.disabledProofCheck)
}
func TestWithPresRequireVC(t *testing.T) {
vpOpt := WithPresRequireVC()
require.NotNil(t, vpOpt)
opts := &presentationOpts{}
vpOpt(opts)
require.True(t, opts.requireVC)
}
func TestWithPresRequireProof(t *testing.T) {
vpOpt := WithPresRequireProof()
require.NotNil(t, vpOpt)
opts := &presentationOpts{}
vpOpt(opts)
require.True(t, opts.requireProof)
var raw rawPresentation
require.NoError(t, json.Unmarshal([]byte(validPresentation), &raw))
raw.Proof = nil
bytes, err := json.Marshal(raw)
require.NoError(t, err)
vp, err := newTestPresentation(bytes, WithPresRequireProof())
require.Error(t, err)
require.Contains(t, err.Error(), "embedded proof is missing")
require.Nil(t, vp)
}
func TestNewPresentationWithEmptyFields(t *testing.T) {
t.Run("creates a new Verifiable Presentation from JSON with valid empty VC structure", func(t *testing.T) {
vp, err := newTestPresentation([]byte(validEmptyPresentation))
require.NoError(t, err)
require.NotNil(t, vp)
})
t.Run("creates a new Verifiable Presentation from JSON with invalid empty VC structure", func(t *testing.T) {
vp, err := newTestPresentation([]byte(validEmptyPresentation), WithPresRequireVC())
require.Error(t, err)
require.Contains(t, err.Error(), "verifiableCredential is required")
require.Nil(t, vp)
})
t.Run("creates a new Verifiable Presentation from JSON with invalid empty proof structure", func(t *testing.T) {
vp, err := newTestPresentation([]byte(validEmptyPresentation), WithPresRequireProof())
require.Error(t, err)
require.Contains(t, err.Error(), "embedded proof is missing")
require.Nil(t, vp)
})
}