-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from smallstep/fix-subject-names
Populate ExtraNames from Names
- Loading branch information
Showing
3 changed files
with
82 additions
and
27 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -27,8 +27,19 @@ func Test_newName(t *testing.T) { | |
PostalCode: []string{"The postalCode"}, | ||
SerialNumber: "The serialNumber", | ||
CommonName: "The commonName", | ||
ExtraNames: []pkix.AttributeTypeAndValue{ | ||
{Type: asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: "[email protected]"}, | ||
Names: []pkix.AttributeTypeAndValue{ | ||
{Type: asn1.ObjectIdentifier{2, 5, 4, 6}, Value: "The country"}, | ||
{Type: asn1.ObjectIdentifier{2, 5, 4, 10}, Value: "The organization"}, | ||
{Type: asn1.ObjectIdentifier{2, 5, 4, 11}, Value: "The organizationalUnit 1"}, | ||
{Type: asn1.ObjectIdentifier{2, 5, 4, 11}, Value: "The organizationalUnit 2"}, | ||
{Type: asn1.ObjectIdentifier{2, 5, 4, 3}, Value: "The commonName"}, | ||
{Type: asn1.ObjectIdentifier{2, 5, 4, 5}, Value: "The serialNumber"}, | ||
{Type: asn1.ObjectIdentifier{2, 5, 4, 7}, Value: "The locality 1"}, | ||
{Type: asn1.ObjectIdentifier{2, 5, 4, 7}, Value: "The locality 2"}, | ||
{Type: asn1.ObjectIdentifier{2, 5, 4, 8}, Value: "The province"}, | ||
{Type: asn1.ObjectIdentifier{2, 5, 4, 9}, Value: "The streetAddress"}, | ||
{Type: asn1.ObjectIdentifier{2, 5, 4, 17}, Value: "The postalCode"}, | ||
{Type: asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: asn1.RawValue{Class: asn1.ClassUniversal, Tag: asn1.TagIA5String, Bytes: []byte("[email protected]")}}, | ||
}, | ||
}}, Name{ | ||
Country: []string{"The country"}, | ||
|
@@ -41,7 +52,7 @@ func Test_newName(t *testing.T) { | |
SerialNumber: "The serialNumber", | ||
CommonName: "The commonName", | ||
ExtraNames: []DistinguishedName{ | ||
{Type: ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: "[email protected]"}, | ||
{Type: ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: asn1.RawValue{Class: asn1.ClassUniversal, Tag: asn1.TagIA5String, Bytes: []byte("[email protected]")}}, | ||
}, | ||
}}, | ||
} | ||
|
@@ -127,8 +138,8 @@ func Test_newSubject(t *testing.T) { | |
PostalCode: []string{"The postalCode"}, | ||
SerialNumber: "The serialNumber", | ||
CommonName: "The commonName", | ||
ExtraNames: []pkix.AttributeTypeAndValue{ | ||
{Type: asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: "[email protected]"}, | ||
Names: []pkix.AttributeTypeAndValue{ | ||
{Type: asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: asn1.RawValue{Class: asn1.ClassUniversal, Tag: asn1.TagIA5String, Bytes: []byte("[email protected]")}}, | ||
}, | ||
}}, Subject{ | ||
Country: []string{"The country"}, | ||
|
@@ -141,7 +152,7 @@ func Test_newSubject(t *testing.T) { | |
SerialNumber: "The serialNumber", | ||
CommonName: "The commonName", | ||
ExtraNames: []DistinguishedName{ | ||
{Type: ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: "[email protected]"}, | ||
{Type: ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: asn1.RawValue{Class: asn1.ClassUniversal, Tag: asn1.TagIA5String, Bytes: []byte("[email protected]")}}, | ||
}, | ||
}}, | ||
} | ||
|
@@ -405,6 +416,7 @@ func TestIssuer_Set(t *testing.T) { | |
CommonName: "The commonName", | ||
ExtraNames: []DistinguishedName{ | ||
{Type: ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: "[email protected]"}, | ||
{Type: ObjectIdentifier{1, 2, 3, 4}, Value: "[email protected]"}, | ||
}, | ||
}, args{&x509.Certificate{}}, &x509.Certificate{ | ||
Issuer: pkix.Name{ | ||
|
@@ -418,7 +430,8 @@ func TestIssuer_Set(t *testing.T) { | |
SerialNumber: "The serialNumber", | ||
CommonName: "The commonName", | ||
ExtraNames: []pkix.AttributeTypeAndValue{ | ||
{Type: asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: "[email protected]"}, | ||
{Type: asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: asn1.RawValue{Class: asn1.ClassUniversal, Tag: asn1.TagIA5String, Bytes: []byte("[email protected]")}}, | ||
{Type: asn1.ObjectIdentifier{1, 2, 3, 4}, Value: "[email protected]"}, | ||
}, | ||
}, | ||
}}, | ||
|
@@ -452,7 +465,7 @@ func TestIssuer_Set(t *testing.T) { | |
} | ||
} | ||
|
||
func Test_newDistinguisedNames(t *testing.T) { | ||
func Test_newExtraNames(t *testing.T) { | ||
type args struct { | ||
atvs []pkix.AttributeTypeAndValue | ||
} | ||
|
@@ -462,15 +475,18 @@ func Test_newDistinguisedNames(t *testing.T) { | |
want []DistinguishedName | ||
}{ | ||
{"ok", args{[]pkix.AttributeTypeAndValue{ | ||
{Type: asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: "[email protected]"}, | ||
{Type: asn1.ObjectIdentifier{2, 5, 4, 3}, Value: "The commonName"}, | ||
{Type: asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: asn1.RawValue{Class: asn1.ClassUniversal, Tag: asn1.TagIA5String, Bytes: []byte("[email protected]")}}, | ||
{Type: asn1.ObjectIdentifier{1, 2, 3, 4}, Value: "[email protected]"}, | ||
}}, []DistinguishedName{ | ||
{Type: ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: "[email protected]"}, | ||
{Type: ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: asn1.RawValue{Class: asn1.ClassUniversal, Tag: asn1.TagIA5String, Bytes: []byte("[email protected]")}}, | ||
{Type: ObjectIdentifier{1, 2, 3, 4}, Value: "[email protected]"}, | ||
}}, | ||
{"ok nil", args{nil}, nil}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := newDistinguisedNames(tt.args.atvs); !reflect.DeepEqual(got, tt.want) { | ||
if got := newExtraNames(tt.args.atvs); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("newDistinguisedNames() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
|
@@ -488,14 +504,16 @@ func Test_fromDistinguisedNames(t *testing.T) { | |
}{ | ||
{"ok", args{[]DistinguishedName{ | ||
{Type: ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: "[email protected]"}, | ||
{Type: ObjectIdentifier{1, 2, 3, 4}, Value: "[email protected]"}, | ||
}}, []pkix.AttributeTypeAndValue{ | ||
{Type: asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: "[email protected]"}, | ||
{Type: asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}, Value: asn1.RawValue{Class: asn1.ClassUniversal, Tag: asn1.TagIA5String, Bytes: []byte("[email protected]")}}, | ||
{Type: asn1.ObjectIdentifier{1, 2, 3, 4}, Value: "[email protected]"}, | ||
}}, | ||
{"ok nil", args{nil}, nil}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := fromDistinguisedNames(tt.args.dns); !reflect.DeepEqual(got, tt.want) { | ||
if got := fromDistinguishedNames(tt.args.dns); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("fromDistinguisedNames() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
|