// TestParseRequest ensures that a valid certificate request does not
// error.
TestParseRequest ensures that a valid certificate request does not
error.
// TestParseRequest ensures that a valid certificate request does not // error .
func TestParseRequest(t *testing.T) {
	var cr = &CertificateRequest{
		CN: "Test Common Name",
		Names: []Name{
			{
				C:  "US",
				ST: "California",
				L:  "San Francisco",
				O:  "CloudFlare, Inc.",
				OU: "Systems Engineering",
			},
			{
				C:  "GB",
				ST: "London",
				L:  "London",
				O:  "CloudFlare, Inc",
				OU: "Systems Engineering",
			},
		},
		Hosts:      []string{"cloudflare.com", "www.cloudflare.com", "192.168.0.1", "jdoe@example.com", "https://www.cloudflare.com"},
		KeyRequest: NewKeyRequest(),
		Extensions: []pkix.Extension{
			pkix.Extension{
				Id:    asn1.ObjectIdentifier{1, 2, 3, 4, 5},
				Value: []byte("AgEB"),
			},
		},
	}
	csrBytes, _, err := ParseRequest(cr)
	if err != nil {
		t.Fatalf("%v", err)
	}
	block, _ := pem.Decode(csrBytes)
	if block == nil {
		t.Fatalf("%v", err)
	}
	if block.Type != "CERTIFICATE REQUEST" {
		t.Fatalf("Incorrect block type: %s", block.Type)
	}
	csr, err := x509.ParseCertificateRequest(block.Bytes)
	if err != nil {
		t.Fatalf("%v", err)
	}
	found := false
	for _, ext := range csr.Extensions {
		if ext.Id.Equal(asn1.ObjectIdentifier{1, 2, 3, 4, 5}) {
			found = true
			break
		}
	}
	if !found {
		t.Fatalf("CSR did not include Custom Extension")
	}
}
func TestParseRequest ( t * testing . T ) { var cr = & CertificateRequest { CN : " " , Names : [ ] Name { { C : " " , ST : " " , L : " " , O : " " , OU : " " , } , { C : " " , ST : " " , L : " " , O : " " , OU : " " , } , } , Hosts : [ ] string { " " , " " , " " , " " , " " } , KeyRequest : NewKeyRequest ( ) , Extensions : [ ] pkix . Extension { pkix . Extension { Id : asn1 . ObjectIdentifier { 1 , 2 , 3 , 4 , 5 } , Value : [ ] byte ( " " ) , } , } , } csrBytes , _ , err := ParseRequest ( cr ) if err != nil { t . Fatalf ( " " , err ) } block , _ := pem . Decode ( csrBytes ) if block == nil { t . Fatalf ( " " , err ) } if block . Type != " " { t . Fatalf ( " " , block . Type ) } csr , err := x509 . ParseCertificateRequest ( block . Bytes ) if err != nil { t . Fatalf ( " " , err ) } found := false for _ , ext := range csr . Extensions { if ext . Id . Equal ( asn1 . ObjectIdentifier { 1 , 2 , 3 , 4 , 5 } ) { found = true break } } if ! found { t . Fatalf ( " " ) } }
TestParseRequest ensures that a valid certificate request does not
error.
TestParseRequest ensures that a valid certificate request does not error .