@@ -5,10 +5,10 @@ import (
5
5
"crypto/x509"
6
6
"crypto/x509/pkix"
7
7
"github.com/lestrrat-go/jwx/v2/jws"
8
+ ssi "github.com/nuts-foundation/go-did"
8
9
"github.com/nuts-foundation/go-didx509-toolkit/internal"
9
10
"testing"
10
11
11
- ssi "github.com/nuts-foundation/go-did"
12
12
"github.com/nuts-foundation/go-didx509-toolkit/x509_cert"
13
13
"github.com/stretchr/testify/assert"
14
14
"github.com/stretchr/testify/require"
@@ -79,38 +79,67 @@ func TestIssue(t *testing.T) {
79
79
validKey , err := internal .ParseRSAPrivateKeyFromPEM ([]byte (internal .TestSigningKey ))
80
80
require .NoError (t , err , "failed to parse signing key" )
81
81
t .Run ("ok - happy path" , func (t * testing.T ) {
82
- validChain , err := internal .ParseCertificatesFromPEM ([]byte (internal .TestCertificateChain ))
83
- require .NoError (t , err , "failed to parse chain" )
82
+ t .Run ("include all" , func (t * testing.T ) {
83
+ validChain , err := internal .ParseCertificatesFromPEM ([]byte (internal .TestCertificateChain ))
84
+ require .NoError (t , err , "failed to parse chain" )
85
+
86
+ vc , err := Issue (validChain , validChain [3 ], validKey , "did:example:123" ,
87
+ SubjectAttributes (x509_cert .SubjectTypeCountry , x509_cert .SubjectTypeOrganization , x509_cert .SubjectTypeLocality ),
88
+ SANAttributes (x509_cert .SanTypeOtherName , x509_cert .SanTypePermanentIdentifierAssigner , x509_cert .SanTypePermanentIdentifierValue ),
89
+ )
90
+
91
+ require .NoError (t , err , "failed to issue verifiable credential" )
92
+ require .NotNil (t , vc , "verifiable credential is nil" )
93
+
94
+ assert .Equal (t , "https://www.w3.org/2018/credentials/v1" , vc .Context [0 ].String ())
95
+ assert .True (t , vc .IsType (ssi .MustParseURI ("VerifiableCredential" )))
96
+ assert .True (t , vc .IsType (ssi .MustParseURI ("X509Credential" )))
97
+ assert .Equal (t , "did:x509:0:sha256:DwXSf2_jaUod7cezXBGJBM4AaaoA8DI9j7aPMDTI-mQ::san:otherName:2.16.528.1.1007.99.2110-1-1111111-S-2222222-00.000-333333:permanentIdentifier.assigner:2.16.528.1.1007.3.3:permanentIdentifier.value:2222222::subject:L:Testland:O:Faux%20Care" , vc .Issuer .String ())
98
+
99
+ expectedCredentialSubject := []interface {}{map [string ]interface {}{
100
+ "id" : "did:example:123" ,
101
+ "subject" : map [string ]interface {}{
102
+ "O" : "Faux Care" ,
103
+ "L" : "Testland" ,
104
+ },
105
+ "san" : map [string ]interface {}{
106
+ "otherName" : "2.16.528.1.1007.99.2110-1-1111111-S-2222222-00.000-333333" ,
107
+ "permanentIdentifier.assigner" : "2.16.528.1.1007.3.3" ,
108
+ "permanentIdentifier.value" : "2222222" ,
109
+ },
110
+ }}
111
+
112
+ assert .Equal (t , expectedCredentialSubject , vc .CredentialSubject )
113
+ assert .Equal (t , validChain [0 ].NotAfter , * vc .ExpirationDate , "expiration date of VC must match signing certificate" )
114
+ parsedJWT , err := jws .Parse ([]byte (vc .Raw ()))
115
+ require .NoError (t , err )
116
+ assert .Equal (t , "v4nyg4rKy6MBIxnutabaUwXCxYY" , parsedJWT .Signatures ()[0 ].ProtectedHeaders ().X509CertThumbprint ())
117
+ assert .Equal (t , "XC-vUEDhKsMrtpwtYEQty5PgSj4ZphDLNDG_Rg9hQDk" , parsedJWT .Signatures ()[0 ].ProtectedHeaders ().X509CertThumbprintS256 ())
118
+ })
119
+ t .Run ("only include san/otherName" , func (t * testing.T ) {
120
+ validChain , err := internal .ParseCertificatesFromPEM ([]byte (internal .TestCertificateChain ))
121
+ require .NoError (t , err , "failed to parse chain" )
84
122
85
- vc , err := Issue (validChain , validChain [3 ], validKey , "did:example:123" , SubjectAttributes ( x509_cert . SubjectTypeCountry , x509_cert . SubjectTypeOrganization , x509_cert . SubjectTypeLocality ) )
123
+ vc , err := Issue (validChain , validChain [3 ], validKey , "did:example:123" )
86
124
87
- require .NoError (t , err , "failed to issue verifiable credential" )
88
- require .NotNil (t , vc , "verifiable credential is nil" )
125
+ require .NoError (t , err , "failed to issue verifiable credential" )
126
+ require .NotNil (t , vc , "verifiable credential is nil" )
89
127
90
- assert .Equal (t , "https://www.w3.org/2018/credentials/v1" , vc .Context [0 ].String ())
91
- assert .True (t , vc .IsType (ssi .MustParseURI ("VerifiableCredential" )))
92
- assert .True (t , vc .IsType (ssi .MustParseURI ("X509Credential" )))
93
- assert .Equal (t , "did:x509:0:sha256:DwXSf2_jaUod7cezXBGJBM4AaaoA8DI9j7aPMDTI-mQ::san:otherName:2.16.528.1.1007.99.2110-1-1111111-S-2222222-00.000-333333::subject:L:Testland:O:Faux%20Care " , vc .Issuer .String ())
128
+ assert .Equal (t , "https://www.w3.org/2018/credentials/v1" , vc .Context [0 ].String ())
129
+ assert .True (t , vc .IsType (ssi .MustParseURI ("VerifiableCredential" )))
130
+ assert .True (t , vc .IsType (ssi .MustParseURI ("X509Credential" )))
131
+ assert .Equal (t , "did:x509:0:sha256:DwXSf2_jaUod7cezXBGJBM4AaaoA8DI9j7aPMDTI-mQ::san:otherName:2.16.528.1.1007.99.2110-1-1111111-S-2222222-00.000-333333" , vc .Issuer .String ())
94
132
95
- expectedCredentialSubject := []interface {}{map [string ]interface {}{
96
- "id" : "did:example:123" ,
97
- "subject" : map [string ]interface {}{
98
- "O" : "Faux Care" ,
99
- "L" : "Testland" ,
100
- },
101
- "san" : map [string ]interface {}{
102
- "otherName" : "2.16.528.1.1007.99.2110-1-1111111-S-2222222-00.000-333333" ,
103
- "permanentIdentifier.assigner" : "2.16.528.1.1007.3.3" ,
104
- "permanentIdentifier.value" : "2222222" ,
105
- },
106
- }}
133
+ expectedCredentialSubject := []interface {}{map [string ]interface {}{
134
+ "id" : "did:example:123" ,
135
+ "san" : map [string ]interface {}{
136
+ "otherName" : "2.16.528.1.1007.99.2110-1-1111111-S-2222222-00.000-333333" ,
137
+ },
138
+ }}
107
139
108
- assert .Equal (t , expectedCredentialSubject , vc .CredentialSubject )
109
- assert .Equal (t , validChain [0 ].NotAfter , * vc .ExpirationDate , "expiration date of VC must match signing certificate" )
110
- parsedJWT , err := jws .Parse ([]byte (vc .Raw ()))
111
- require .NoError (t , err )
112
- assert .Equal (t , "v4nyg4rKy6MBIxnutabaUwXCxYY" , parsedJWT .Signatures ()[0 ].ProtectedHeaders ().X509CertThumbprint ())
113
- assert .Equal (t , "XC-vUEDhKsMrtpwtYEQty5PgSj4ZphDLNDG_Rg9hQDk" , parsedJWT .Signatures ()[0 ].ProtectedHeaders ().X509CertThumbprintS256 ())
140
+ assert .Equal (t , expectedCredentialSubject , vc .CredentialSubject )
141
+ assert .Equal (t , validChain [0 ].NotAfter , * vc .ExpirationDate )
142
+ })
114
143
})
115
144
116
145
t .Run ("ok - correct escaping of special characters" , func (t * testing.T ) {
0 commit comments