github.com/zmap/zcrypto@v0.0.0-20240512203510-0fef58d9a9db/x509/pkix/pkix_test.go (about) 1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package pkix 6 7 import ( 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestNameString(t *testing.T) { 14 tests := []struct { 15 name Name 16 expected string 17 legacy string 18 }{ 19 { 20 name: Name{}, 21 expected: "", 22 legacy: "", 23 }, 24 { 25 name: Name{ 26 SerialNumber: "12345", 27 CommonName: "common", 28 Country: []string{"US", "RU"}, 29 Organization: []string{"University of Michigan"}, 30 OrganizationalUnit: []string{"0x21"}, 31 Locality: []string{"Ann Arbor"}, 32 Province: []string{"Michigan"}, 33 StreetAddress: []string{"2260 Hayward St"}, 34 PostalCode: []string{"48109"}, 35 DomainComponent: nil, 36 ExtraNames: []AttributeTypeAndValue{{Type: oidCommonName, Value: "name"}, {Type: oidSerialNumber, Value: "67890"}}, 37 }, 38 expected: "serialNumber=67890, CN=name, serialNumber=12345, C=US, C=RU, postalCode=48109, ST=Michigan, L=Ann Arbor, street=2260 Hayward St, O=University of Michigan, OU=0x21, CN=common", 39 legacy: "CN=common, OU=0x21, O=University of Michigan, street=2260 Hayward St, L=Ann Arbor, ST=Michigan, postalCode=48109, C=US, C=RU, serialNumber=12345, CN=name, serialNumber=67890", 40 }, 41 { 42 name: Name{ 43 SerialNumber: "12345", 44 CommonName: "common", 45 PostalCode: []string{"48109"}, 46 OriginalRDNS: RDNSequence{ 47 []AttributeTypeAndValue{ 48 {Type: oidPostalCode, Value: "48109"}, 49 {Type: oidSerialNumber, Value: "12345"}, 50 {Type: oidCommonName, Value: "common"}, 51 {Type: oidGivenName, Value: "given"}, 52 {Type: oidDomainComponent, Value: "domain"}, 53 {Type: oidDNEmailAddress, Value: "user@dn.com"}, 54 {Type: oidJurisdictionLocality, Value: "Locality"}, 55 {Type: oidJurisdictionProvince, Value: "Prov"}, 56 {Type: oidJurisdictionCountry, Value: "Canada"}, 57 {Type: oidOrganizationID, Value: "QWACS"}, 58 }, 59 }, 60 }, 61 expected: "postalCode=48109, serialNumber=12345, CN=common, GN=given, DC=domain, emailAddress=user@dn.com, jurisdictionLocality=Locality, jurisdictionStateOrProvince=Prov, jurisdictionCountry=Canada, organizationIdentifier=QWACS", 62 legacy: "postalCode=48109, serialNumber=12345, CN=common, GN=given, DC=domain, emailAddress=user@dn.com, jurisdictionLocality=Locality, jurisdictionStateOrProvince=Prov, jurisdictionCountry=Canada, organizationIdentifier=QWACS", 63 }, 64 } 65 for _, test := range tests { 66 s := test.name.String() 67 assert.Equal(t, test.expected, s) 68 } 69 LegacyNameString = true 70 for _, test := range tests { 71 s := test.name.String() 72 assert.Equal(t, test.legacy, s) 73 } 74 }