Skip to content

Commit

Permalink
Fix: Common name got not set in CSR
Browse files Browse the repository at this point in the history
  • Loading branch information
dvob committed Apr 25, 2020
1 parent bbe906d commit 551ac95
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/pcert/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func newRequestCmd(cfg *app) *cobra.Command {
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
defaultSetting(&cfg.cert.Subject.CommonName, name)
defaultSetting(&csr.Subject.CommonName, name)
defaultSetting(&csrFile, name+csrFileSuffix)
cfg.defaultOutputSettings(name)

Expand Down
36 changes: 36 additions & 0 deletions cmd/pcert/request_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"crypto/x509"
"os"
"testing"

"github.com/dsbrng25b/pcert"
)

func runRequestAndLoad(name string, args []string, env map[string]string) (*x509.CertificateRequest, error) {
defer os.Remove(name + ".csr")
defer os.Remove(name + ".key")
fullArgs := []string{"request", name}
fullArgs = append(fullArgs, args...)
err := runCmd(fullArgs, env)
if err != nil {
return nil, err
}

csr, err := pcert.LoadCSR(name + ".csr")
return csr, err
}

func Test_request(t *testing.T) {
name := "csr1"
csr, err := runRequestAndLoad(name, []string{}, nil)
if err != nil {
t.Error(err)
return
}

if csr.Subject.CommonName != name {
t.Errorf("common name no set correctly: got: %s, want: %s", csr.Subject.CommonName, name)
}
}

0 comments on commit 551ac95

Please sign in to comment.