forked from MetaMask/go-did-it
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice_test.go
More file actions
107 lines (102 loc) · 2.64 KB
/
service_test.go
File metadata and controls
107 lines (102 loc) · 2.64 KB
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
103
104
105
106
107
package did
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
)
func TestServicesJsonRountrip(t *testing.T) {
tests := []struct {
name string
input string
}{
{
name: "LinkedDomains",
input: `[
{
"id":"did:example:123#foo",
"type": "LinkedDomains",
"serviceEndpoint": {
"origins": ["https://foo.example.com", "https://identity.foundation"]
}
},
{
"id":"did:example:123#bar",
"type": "LinkedDomains",
"serviceEndpoint": "https://bar.example.com"
}
]`,
},
{
name: "LinkedVerifiablePresentation",
input: `[
{
"id": "did:example:123#foo",
"type": "LinkedVerifiablePresentation",
"serviceEndpoint": "https://bar.example.com/verifiable-presentation.jsonld"
},
{
"id": "did:example:123#baz",
"type": "LinkedVerifiablePresentation",
"serviceEndpoint": "ipfs://bafybeihkoviema7g3gxyt6la7vd5ho32ictqbilu3wnlo3rs7ewhnp7lly/verifiable-presentation.jwt"
}
]`,
},
{
name: "WotThing",
input: `[{
"id": "did:example:wotdiscoveryexample#td",
"type": "WotThing",
"serviceEndpoint":
"https://wot.example.com/.well-known/wot"
}]`,
},
{
name: "multi types",
input: `[
{
"id": "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK#node",
"type": [
"DIDCommMessaging",
"CredentialRepositoryService",
"RevocationList2020Status",
"TrustRegistryService"
],
"serviceEndpoint": "https://node.blockchain-network.com/api/v1"
}
]`,
},
{
name: "multi types, map values",
input: `[
{
"id": "did:web:wallet.example.com#wallet-service",
"type": [
"VerifiableCredentialService",
"OpenIdConnectVersion1.0Service",
"DIDCommMessaging",
"CredentialRepositoryService"
],
"serviceEndpoint": {
"credentialIssue": "https://wallet.example.com/credentials/issue",
"credentialVerify": "https://wallet.example.com/credentials/verify",
"credentialStore": "https://wallet.example.com/vault",
"oidcAuth": "https://wallet.example.com/auth",
"oidcToken": "https://wallet.example.com/token",
"didcommInbox": "https://wallet.example.com/didcomm/inbox",
"didcommOutbox": "https://wallet.example.com/didcomm/outbox"
}
}
]`,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var services []Service
err := json.Unmarshal([]byte(tc.input), &services)
require.NoError(t, err)
rt, err := json.Marshal(services)
require.NoError(t, err)
require.JSONEq(t, tc.input, string(rt))
})
}
}