github.com/hyperledger/aries-framework-go@v0.3.2/pkg/doc/sdjwt/verifier/verifier_interop_test.go (about) 1 /* 2 Copyright SecureKey Technologies Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package verifier 8 9 import ( 10 "encoding/json" 11 "testing" 12 "time" 13 14 "github.com/stretchr/testify/require" 15 16 "github.com/hyperledger/aries-framework-go/pkg/doc/sdjwt/common" 17 "github.com/hyperledger/aries-framework-go/pkg/doc/sdjwt/holder" 18 ) 19 20 // nolint:lll 21 const specIssuanceExample1 = `eyJhbGciOiAiRVMyNTYifQ.eyJfc2QiOiBbIk5ZQ29TUktFWXdYZHBlNXlkdUpYQ3h4aHluRVU4ei1iNFR5TmlhcDc3VVkiLCAiU1k4bjJCYmtYOWxyWTNleEhsU3dQUkZYb0QwOUdGOGE5Q1BPLUc4ajIwOCIsICJUUHNHTlBZQTQ2d21CeGZ2MnpuT0poZmRvTjVZMUdrZXpicGFHWkNUMWFjIiwgIlprU0p4eGVHbHVJZFlCYjdDcWtaYkpWbTB3MlY1VXJSZU5UekFRQ1lCanciLCAibDlxSUo5SlRRd0xHN09MRUlDVEZCVnhtQXJ3OFBqeTY1ZEQ2bXRRVkc1YyIsICJvMVNBc0ozM1lNaW9POXBYNVZlQU0xbHh1SEY2aFpXMmtHZGtLS0JuVmxvIiwgInFxdmNxbmN6QU1nWXg3RXlrSTZ3d3RzcHl2eXZLNzkwZ2U3TUJiUS1OdXMiXSwgImlzcyI6ICJodHRwczovL2V4YW1wbGUuY29tL2lzc3VlciIsICJpYXQiOiAxNTE2MjM5MDIyLCAiZXhwIjogMTUxNjI0NzAyMiwgIl9zZF9hbGciOiAic2hhLTI1NiIsICJjbmYiOiB7Imp3ayI6IHsia3R5IjogIkVDIiwgImNydiI6ICJQLTI1NiIsICJ4IjogIlRDQUVSMTladnUzT0hGNGo0VzR2ZlNWb0hJUDFJTGlsRGxzN3ZDZUdlbWMiLCAieSI6ICJaeGppV1diWk1RR0hWV0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Z79qVvBR9gL4nCXBu6c--QDysTgnXk_oe-qVin6EOzHF3Oh9tbQ` 25 26 func TestInterop(t *testing.T) { 27 r := require.New(t) 28 29 t.Run("success - Example 1", func(t *testing.T) { 30 cfi := specIssuanceExample1 + common.CombinedFormatSeparator 31 32 claims, err := Parse(cfi, 33 WithIssuerSigningAlgorithms([]string{"ES256"}), 34 WithSignatureVerifier(&holder.NoopSignatureVerifier{}), 35 // expiry time for example 1 is 2018-01-17 22:43:42 -0500 EST 36 // so we have to have great leeway in order to pass test 37 WithLeewayForClaimsValidation(10*12*30*24*time.Hour)) 38 r.NoError(err) 39 40 printObject(t, "Disclosed Claims for Example 1 - All Claims Disclosed", claims) 41 42 var example1ClaimsObj map[string]interface{} 43 err = json.Unmarshal([]byte(claimsExample1), &example1ClaimsObj) 44 r.NoError(err) 45 46 var disclosedClaimsForExample1Obj map[string]interface{} 47 err = json.Unmarshal([]byte(disclosedAllClaimsForExample1), &disclosedClaimsForExample1Obj) 48 r.NoError(err) 49 50 // expected claims are example 1 claims plus exp, iat, iss, cnf 51 r.Equal(len(disclosedClaimsForExample1Obj), len(example1ClaimsObj)+4) 52 53 r.Equal(len(disclosedClaimsForExample1Obj), len(claims)) 54 }) 55 56 t.Run("success - Example 1 with Holder Binding", func(t *testing.T) { 57 claims, err := Parse(specPresentationExample1, 58 WithIssuerSigningAlgorithms([]string{"ES256"}), 59 WithHolderSigningAlgorithms([]string{"ES256"}), 60 WithSignatureVerifier(&holder.NoopSignatureVerifier{}), 61 // expiry time for example 1 is 2018-01-17 22:43:42 -0500 EST 62 // so we have to have great leeway in order to pass test 63 WithLeewayForClaimsValidation(10*12*30*24*time.Hour)) 64 r.NoError(err) 65 66 printObject(t, "Disclosed Claims For Example 1 - Partial Disclosure", claims) 67 68 var disclosedPartialClaimsForExample1Obj map[string]interface{} 69 err = json.Unmarshal([]byte(disclosedPartialClaimsForExample1), &disclosedPartialClaimsForExample1Obj) 70 r.NoError(err) 71 72 r.Equal(len(disclosedPartialClaimsForExample1Obj), len(claims)) 73 }) 74 } 75 76 const claimsExample1 = ` 77 { 78 "sub": "john_doe_42", 79 "given_name": "John", 80 "family_name": "Doe", 81 "email": "johndoe@example.com", 82 "phone_number": "+1-202-555-0101", 83 "address": { 84 "street_address": "123 Main St", 85 "locality": "Anytown", 86 "region": "Anystate", 87 "country": "US" 88 }, 89 "birthdate": "1940-01-01" 90 }` 91 92 const disclosedAllClaimsForExample1 = ` 93 { 94 "sub": "john_doe_42", 95 "given_name": "John", 96 "family_name": "Doe", 97 "email": "johndoe@example.com", 98 "phone_number": "+1-202-555-0101", 99 "address": { 100 "country": "US", 101 "locality": "Anytown", 102 "region": "Anystate", 103 "street_address": "123 Main St" 104 }, 105 "birthdate": "1940-01-01", 106 "exp": 1516247022, 107 "iat": 1516239022, 108 "iss": "https://example.com/issuer", 109 "cnf": { 110 "jwk": { 111 "crv": "P-256", 112 "kty": "EC", 113 "x": "TCAER19Zvu3OHF4j4W4vfSVoHIP1ILilDls7vCeGemc", 114 "y": "ZxjiWWbZMQGHVWKVQ4hbSIirsVfuecCE6t4jT9F2HZQ" 115 } 116 } 117 }` 118 119 const disclosedPartialClaimsForExample1 = ` 120 { 121 "family_name": "Doe", 122 "given_name": "John", 123 "address": { 124 "country": "US", 125 "locality": "Anytown", 126 "region": "Anystate", 127 "street_address": "123 Main St" 128 }, 129 "cnf": { 130 "jwk": { 131 "crv": "P-256", 132 "kty": "EC", 133 "x": "TCAER19Zvu3OHF4j4W4vfSVoHIP1ILilDls7vCeGemc", 134 "y": "ZxjiWWbZMQGHVWKVQ4hbSIirsVfuecCE6t4jT9F2HZQ" 135 } 136 }, 137 "exp": 1516247022, 138 "iat": 1516239022, 139 "iss": "https://example.com/issuer" 140 }`