// TestGenerator ensures that a valid request is processed properly
// and returns a certificate request and key.
TestGenerator ensures that a valid request is processed properly
and returns a certificate request and key.
// TestGenerator ensures that a valid request is processed properly // and returns a certificate request and key .
func TestGenerator(t *testing.T) {
	g := &Generator{testValidator}
	var req = &CertificateRequest{
		Names: []Name{
			{
				C:  "US",
				ST: "California",
				L:  "San Francisco",
				O:  "CloudFlare",
				OU: "Systems Engineering",
			},
		},
		CN:         "cloudflare.com",
		Hosts:      []string{"cloudflare.com", "www.cloudflare.com", "192.168.0.1", "jdoe@example.com", "https://www.cloudflare.com"},
		KeyRequest: &KeyRequest{"rsa", 2048},
	}
	csrBytes, _, err := g.ProcessRequest(req)
	if err != nil {
		t.Fatal(err)
	}
	block, _ := pem.Decode([]byte(csrBytes))
	if block == nil {
		t.Fatalf("bad CSR in PEM")
	}
	if block.Type != "CERTIFICATE REQUEST" {
		t.Fatalf("bad CSR in PEM")
	}
	csr, err := x509.ParseCertificateRequest(block.Bytes)
	if err != nil {
		t.Fatal(err)
	}
	if len(csr.DNSNames) != 2 {
		t.Fatal("SAN parsing error")
	}
	if len(csr.IPAddresses) != 1 {
		t.Fatal("SAN parsing error")
	}
	if len(csr.EmailAddresses) != 1 {
		t.Fatal("SAN parsing error")
	}
	if len(csr.URIs) != 1 {
		t.Fatal("SAN parsing error")
	}
}
func TestGenerator ( t * testing . T ) { g := & Generator { testValidator } var req = & CertificateRequest { Names : [ ] Name { { C : " " , ST : " " , L : " " , O : " " , OU : " " , } , } , CN : " " , Hosts : [ ] string { " " , " " , " " , " " , " " } , KeyRequest : & KeyRequest { " " , 2048 } , } csrBytes , _ , err := g . ProcessRequest ( req ) if err != nil { t . Fatal ( err ) } block , _ := pem . Decode ( [ ] byte ( csrBytes ) ) if block == nil { t . Fatalf ( " " ) } if block . Type != " " { t . Fatalf ( " " ) } csr , err := x509 . ParseCertificateRequest ( block . Bytes ) if err != nil { t . Fatal ( err ) } if len ( csr . DNSNames ) != 2 { t . Fatal ( " " ) } if len ( csr . IPAddresses ) != 1 { t . Fatal ( " " ) } if len ( csr . EmailAddresses ) != 1 { t . Fatal ( " " ) } if len ( csr . URIs ) != 1 { t . Fatal ( " " ) } }
TestGenerator ensures that a valid request is processed properly
and returns a certificate request and key.
TestGenerator ensures that a valid request is processed properly and returns a certificate request and key .