Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes test pipeline issue tpp #539

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions pkg/venafi/tpp/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,6 @@ func TestRenewCertRestoringValues(t *testing.T) {
req.KeyType = certificate.KeyTypeECDSA
req.KeyCurve = certificate.EllipticCurveP521
req.CsrOrigin = certificate.ServiceGeneratedCSR
req.Timeout = time.Second * 10
err = tpp.GenerateRequest(&endpoint.ZoneConfiguration{}, req)
if err != nil {
t.Fatalf("err is not nil, err: %s", err)
Expand All @@ -1828,6 +1827,11 @@ func TestRenewCertRestoringValues(t *testing.T) {
req.FetchPrivateKey = true
req.KeyPassword = os.Getenv("TPP_PASSWORD")

req.Timeout = time.Second * 30 // explicitly setting this value here
// to make sure we only wait for certificate issuance for 30 seconds because
// setting it before the RequestCertificate function, will override
// workToDoTimeout to only wait to 30 seconds

pcc, err := tpp.RetrieveCertificate(req)
if err != nil {
t.Fatal(err)
Expand All @@ -1847,11 +1851,11 @@ func TestRenewCertRestoringValues(t *testing.T) {
renewReq := certificate.RenewalRequest{
CertificateDN: req.PickupID,
}
pickupdID, err := tpp.RenewCertificate(&renewReq)
pickupID, err := tpp.RenewCertificate(&renewReq)
if err != nil {
t.Fatal(err)
}
req = &certificate.Request{PickupID: pickupdID, Timeout: 30 * time.Second}
req = &certificate.Request{PickupID: pickupID, Timeout: 30 * time.Second}
pcc, err = tpp.RetrieveCertificate(req)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -2288,7 +2292,6 @@ func TestEnrollWithLocation(t *testing.T) {

req := certificate.Request{}
req.Subject.CommonName = cn
req.Timeout = time.Second * 10
req.Location = &certificate.Location{
Instance: "instance",
Workload: workload,
Expand All @@ -2305,7 +2308,6 @@ func TestEnrollWithLocation(t *testing.T) {
}
req = certificate.Request{}
req.Subject.CommonName = cn
req.Timeout = time.Second * 10
req.Location = &certificate.Location{
Instance: "instance",
Workload: workload,
Expand All @@ -2322,7 +2324,6 @@ func TestEnrollWithLocation(t *testing.T) {
}
req = certificate.Request{}
req.Subject.CommonName = cn
req.Timeout = time.Second * 10
req.Location = &certificate.Location{
Instance: "instance",
Workload: workload,
Expand Down Expand Up @@ -2862,6 +2863,9 @@ func TestSetPolicyValuesAndValidate(t *testing.T) {
func TestCreateSshCertServiceGeneratedKP(t *testing.T) {

tpp, err := getTestConnector(ctx.TPPurl, ctx.TPPZone)
if err != nil {
t.Fatalf("err is not nil, err: %s", err)
}

duration := 4

Expand All @@ -2880,7 +2884,6 @@ func TestCreateSshCertServiceGeneratedKP(t *testing.T) {
req.ValidityPeriod = fmt.Sprint(duration, "h")
req.Template = os.Getenv("TPP_SSH_CA")
req.SourceAddresses = []string{"test.com"}
req.Timeout = time.Second * 10

respData, err := tpp.RequestSSHCertificate(req)

Expand Down Expand Up @@ -2928,6 +2931,10 @@ func TestCreateSshCertLocalGeneratedKP(t *testing.T) {

tpp, err := getTestConnector(ctx.TPPurl, ctx.TPPZone)

if err != nil {
t.Fatalf("err is not nil, err: %s", err)
}

duration := 4

tpp.verbose = true
Expand Down Expand Up @@ -2959,7 +2966,6 @@ func TestCreateSshCertLocalGeneratedKP(t *testing.T) {
req.ValidityPeriod = fmt.Sprint(duration, "h")
req.Template = os.Getenv("TPP_SSH_CA")
req.SourceAddresses = []string{"test.com"}
req.Timeout = time.Second * 10

sPubKey := string(pub)

Expand Down
4 changes: 3 additions & 1 deletion pkg/venafi/tpp/sshCertUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func RequestSshCertificate(c *Connector, req *certificate.SshCertRequest) (*cert
}

//TODO: Maybe, there is a better way to set the timeout.
c.client.Timeout = time.Duration(req.Timeout) * time.Second
if req.Timeout > 0 {
c.client.Timeout = req.Timeout * time.Second
}
statusCode, status, body, err := c.request("POST", urlResourceSshCertReq, sshCertReq)
if err != nil {
return nil, err
Expand Down