github.com/hyperledger/aries-framework-go@v0.3.2/pkg/doc/verifiable/presentation_jwt_test.go (about) 1 /* 2 Copyright SecureKey Technologies Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package verifiable 8 9 import ( 10 "testing" 11 12 "github.com/stretchr/testify/require" 13 ) 14 15 func TestNewJWTPresClaims(t *testing.T) { 16 vp, err := newTestPresentation(t, []byte(validPresentation)) 17 require.NoError(t, err) 18 19 audience := []string{"did:example:4a57546973436f6f6c4a4a57573"} 20 21 t.Run("new JWT claims of VP with minimization", func(t *testing.T) { 22 claims, err := newJWTPresClaims(vp, audience, true) 23 require.NoError(t, err) 24 require.NotNil(t, claims) 25 26 // issuer, ID and audience are filled in JWT claims 27 require.Equal(t, vp.Holder, claims.Issuer) 28 require.Equal(t, vp.ID, claims.ID) 29 require.Equal(t, audience[0], claims.Audience[0]) 30 31 require.NotNil(t, claims.Presentation) 32 33 // ID and Holder are cleared (minimized) in "vp" claim 34 require.Empty(t, claims.Presentation.ID) 35 require.Empty(t, claims.Presentation.Holder) 36 37 // minimization does not affect original VP 38 require.NotEqual(t, vp.ID, claims.Presentation.ID) 39 require.NotEqual(t, vp.Holder, claims.Presentation.Holder) 40 }) 41 42 t.Run("new JWT claims of VP without minimization", func(t *testing.T) { 43 claims, err := newJWTPresClaims(vp, audience, false) 44 require.NoError(t, err) 45 require.NotNil(t, claims) 46 47 // issuer, ID and audience are filled in JWT claims 48 require.Equal(t, vp.Holder, claims.Issuer) 49 require.Equal(t, vp.ID, claims.ID) 50 require.Equal(t, audience[0], claims.Audience[0]) 51 52 require.NotNil(t, claims.Presentation) 53 54 // ID and Holder are cleared (minimized) in "vp" claim 55 require.Equal(t, vp.ID, claims.Presentation.ID) 56 require.Equal(t, vp.Holder, claims.Presentation.Holder) 57 }) 58 }