forked from gophergala/sbuca
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Marshal and Unmarshal for pkix.Name types
- Loading branch information
Showing
2 changed files
with
134 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package pkix | ||
|
||
import ( | ||
"crypto/x509/pkix" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_Marshal(t *testing.T) { | ||
testdata := make(map[string]pkix.Name) | ||
|
||
testdata["O=null"] = pkix.Name{ | ||
Organization: []string{"null"}, | ||
} | ||
|
||
testdata["CN=myserver,O=myorg"] = pkix.Name{ | ||
Organization: []string{"myorg"}, | ||
CommonName: "myserver", | ||
} | ||
testdata["CN=myserver,C=merica,L=City,ST=State,SA=StreetAddress,O=myorg,OU=myorgunit"] = pkix.Name{ | ||
Organization: []string{"myorg"}, | ||
OrganizationalUnit: []string{"myorgunit"}, | ||
Country: []string{"merica"}, | ||
Locality: []string{"City"}, | ||
Province: []string{"State"}, | ||
StreetAddress: []string{"StreetAddress"}, | ||
CommonName: "myserver", | ||
} | ||
|
||
for expected, input := range testdata { | ||
output, err := Marshal(input) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if output != expected { | ||
t.Error("Failed got " + output + " expected " + expected) | ||
} | ||
} | ||
} | ||
|
||
func Test_Unmarshal(t *testing.T) { | ||
testdata := make(map[string]pkix.Name) | ||
|
||
testdata["O=null"] = pkix.Name{ | ||
Organization: []string{"null"}, | ||
} | ||
|
||
testdata["CN=myserver,O=myorg"] = pkix.Name{ | ||
Organization: []string{"myorg"}, | ||
CommonName: "myserver", | ||
} | ||
testdata["CN=myserver,C=merica,L=City,ST=State,SA=StreetAddress,O=myorg,OU=myorgunit"] = pkix.Name{ | ||
Organization: []string{"myorg"}, | ||
OrganizationalUnit: []string{"myorgunit"}, | ||
Country: []string{"merica"}, | ||
Locality: []string{"City"}, | ||
Province: []string{"State"}, | ||
StreetAddress: []string{"StreetAddress"}, | ||
CommonName: "myserver", | ||
} | ||
|
||
for dnstring, expected := range testdata { | ||
pkixName, err := Unmarshal(dnstring) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if !reflect.DeepEqual(pkixName, expected) { | ||
t.Error("Failed got ", pkixName, " expected ", expected) | ||
} | ||
} | ||
} |