-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deduplicate oapi ssi schema definitions (#1123)
* move schemas to common and validate against used code
- Loading branch information
Showing
10 changed files
with
372 additions
and
301 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package ssiTypes | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
"time" | ||
|
||
ssi "github.com/nuts-foundation/go-did" | ||
vcr "github.com/nuts-foundation/nuts-node/vcr/api/v2" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSsiTypes_VerifiableCredential(t *testing.T) { | ||
t.Run("required fields only", func(t *testing.T) { | ||
remarshallTest(t, createVerifiableCredential(), VerifiableCredential{}) | ||
}) | ||
|
||
t.Run("all fields", func(t *testing.T) { | ||
vc := createVerifiableCredential() | ||
id := ssi.MustParseURI("did:nuts:CuE3qeFGGLhEAS3gKzhMCeqd1dGa9at5JCbmCfyMU2Ey#c4199b74-0c0a-4e09-a463-6927553e65f5") | ||
vc.ID = &id | ||
expirationDate := time.Now().Add(time.Hour) | ||
vc.ExpirationDate = &expirationDate | ||
|
||
remarshallTest(t, vc, VerifiableCredential{}) | ||
}) | ||
} | ||
|
||
func TestSsiTypes_VerifiablePresentation(t *testing.T) { | ||
t.Run("required fields only", func(t *testing.T) { | ||
remarshallTest(t, createVerifiablePresentation(), VerifiableCredential{}) | ||
}) | ||
|
||
t.Run("all fields", func(t *testing.T) { | ||
id := ssi.MustParseURI("did:nuts:CuE3qeFGGLhEAS3gKzhMCeqd1dGa9at5JCbmCfyMU2Ey#c4199b74-0c0a-4e09-a463-6927553e65f5") | ||
holder := ssi.MustParseURI("did:nuts:CuE3qeFGGLhEAS3gKzhMCeqd1dGa9at5JCbmCfyMU2Ey") | ||
|
||
vp := createVerifiablePresentation() | ||
vp.ID = &id | ||
vp.Holder = &holder | ||
vp.VerifiableCredential = []vcr.VerifiableCredential{createVerifiableCredential()} | ||
vp.Proof = []interface{}{"because"} | ||
|
||
remarshallTest(t, vp, VerifiablePresentation{}) | ||
}) | ||
} | ||
|
||
func createVerifiableCredential() vcr.VerifiableCredential { | ||
return vcr.VerifiableCredential{ | ||
Context: []ssi.URI{ssi.MustParseURI("https://www.w3.org/2018/credentials/v1")}, | ||
Type: []ssi.URI{ | ||
ssi.MustParseURI("NutsOrganizationCredential"), | ||
ssi.MustParseURI("VerifiableCredential"), | ||
}, | ||
Issuer: ssi.MustParseURI("did:nuts:CuE3qeFGGLhEAS3gKzhMCeqd1dGa9at5JCbmCfyMU2Ey"), | ||
IssuanceDate: time.Now(), | ||
CredentialSubject: []interface{}{"subject"}, | ||
Proof: []interface{}{"because"}, | ||
} | ||
} | ||
|
||
func createVerifiablePresentation() vcr.VerifiablePresentation { | ||
return vcr.VerifiablePresentation{ | ||
Context: []ssi.URI{ | ||
ssi.MustParseURI("https://www.w3.org/2018/credentials/v1"), | ||
ssi.MustParseURI("https://nuts.nl/credentials/v1"), | ||
}, | ||
Type: []ssi.URI{ssi.MustParseURI("VerifiablePresentation")}, | ||
} | ||
} | ||
|
||
func remarshallTest(t *testing.T, source, target any) { | ||
jsonSource, err := json.Marshal(source) | ||
if !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
err = json.Unmarshal(jsonSource, &target) | ||
if !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
jsonTarget, err := json.Marshal(target) | ||
if !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
assert.JSONEq(t, string(jsonSource), string(jsonTarget)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.