Skip to content

Commit f02f568

Browse files
Handle the duration field as string
Signed-off-by: Sidharth Surana <[email protected]>
1 parent 282553e commit f02f568

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

govc/test/vcsim.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ EOF
644644
csr="${output//$'\n'/\\n}"
645645

646646
run govc session.login -r -X POST /rest/vcenter/certificate-authority/sign-cert <<EOF
647-
{ "csr": "$csr", "duration": 30}
647+
{ "csr": "$csr", "duration": "30"}
648648
EOF
649649
assert_success
650650

vapi/simulator/simulator.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ func (s *handler) certificateAuthority(w http.ResponseWriter, r *http.Request) {
628628
}
629629

630630
var req struct {
631-
Duration int64 `json:"duration"`
631+
Duration string `json:"duration"`
632632
CSR string `json:"csr"`
633633
}
634634

@@ -639,6 +639,11 @@ func (s *handler) certificateAuthority(w http.ResponseWriter, r *http.Request) {
639639
BadRequest(w, err.Error())
640640
return
641641
}
642+
duration, err := strconv.ParseInt(req.Duration, 10, 64)
643+
if err != nil {
644+
BadRequest(w, err.Error())
645+
return
646+
}
642647

643648
serialNumber, _ := rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128))
644649
now := time.Now()
@@ -648,7 +653,7 @@ func (s *handler) certificateAuthority(w http.ResponseWriter, r *http.Request) {
648653
DNSNames: csr.DNSNames,
649654
IPAddresses: csr.IPAddresses,
650655
NotBefore: now,
651-
NotAfter: now.Add(time.Hour * 24 * time.Duration(req.Duration)),
656+
NotAfter: now.Add(time.Hour * 24 * time.Duration(duration)),
652657
AuthorityKeyId: signer.Leaf.SubjectKeyId,
653658
}
654659

0 commit comments

Comments
 (0)