// TestParseRequestCA ensures that a valid CA certificate request does not
// error and the resulting CSR includes the BasicConstraint extension
TestParseRequestCA ensures that a valid CA certificate request does not
error and the resulting CSR includes the BasicConstraint extension
// TestParseRequestCA ensures that a valid CA certificate request does not // error and the resulting CSR includes the BasicConstraint extension
func TestParseRequestCA(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",
			},
		},
		CA: &CAConfig{
			PathLength:  0,
			PathLenZero: true,
		},
		KeyRequest: NewKeyRequest(),
	}
	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{2, 5, 29, 19}) {
			found = true
			break
		}
	}
	if !found {
		t.Fatalf("CSR did not include BasicConstraint Extension")
	}
}
func TestParseRequestCA ( t * testing . T ) { var cr = & CertificateRequest { CN : " " , Names : [ ] Name { { C : " " , ST : " " , L : " " , O : " " , OU : " " , } , { C : " " , ST : " " , L : " " , O : " " , OU : " " , } , } , CA : & CAConfig { PathLength : 0 , PathLenZero : true , } , KeyRequest : NewKeyRequest ( ) , } 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 { 2 , 5 , 29 , 19 } ) { found = true break } } if ! found { t . Fatalf ( " " ) } }
TestParseRequestCA ensures that a valid CA certificate request does not
error and the resulting CSR includes the BasicConstraint extension
TestParseRequestCA ensures that a valid CA certificate request does not error and the resulting CSR includes the BasicConstraint extension