Skip to content

Commit c3a5d33

Browse files
authored
adding a client site test case for scenario of updating site ssl when account certificate is already exists for different site on the account (#486)
1 parent fbbcca3 commit c3a5d33

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

incapsula/client_site_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package incapsula
22

33
import (
44
"fmt"
5+
"io"
56
"net/http"
67
"net/http/httptest"
78
"strings"
@@ -380,3 +381,72 @@ func TestClientDeleteSiteValidSite(t *testing.T) {
380381
t.Errorf("Should not have received an error")
381382
}
382383
}
384+
385+
func TestClientUpdateSiteWithExistingCertificate(t *testing.T) {
386+
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
387+
388+
bytedata, _ := io.ReadAll(req.Body)
389+
reqBodyString := string(bytedata)
390+
391+
if strings.Contains(req.URL.String(), endpointSiteUpdate) {
392+
if strings.Contains(reqBodyString, "domain_validation") {
393+
rw.Write([]byte(`{"site_id":111,"res":1}`))
394+
} else {
395+
rw.Write([]byte(`{"site_id":111,"res":0}`))
396+
}
397+
398+
} else if strings.Contains(req.URL.String(), endpointCertDetails) {
399+
rw.Write([]byte(`{
400+
"data": [
401+
{
402+
"id": 222,
403+
"name": "ATLAS_661-1730205519459",
404+
"status": "IN_PROCESS",
405+
"sans": [
406+
{
407+
"sanId": 123,
408+
"sanValue": "*.test.com",
409+
"validationMethod": "CNAME",
410+
"status": "VALIDATED",
411+
"domainIds": 2333,
412+
"sitesIds": [
413+
111
414+
]
415+
}
416+
],
417+
"authType": "RSA",
418+
"level": "ACCOUNT"
419+
}
420+
]
421+
}`))
422+
}
423+
}))
424+
defer server.Close()
425+
426+
config := &Config{APIID: "foo", APIKey: "bar", BaseURL: server.URL, BaseURLAPI: server.URL}
427+
client := &Client{config: config, httpClient: &http.Client{}}
428+
429+
siteID := "111"
430+
addSiteResponse, err := client.UpdateSite(siteID, "", "")
431+
if err != nil {
432+
t.Errorf("Should not have received an error")
433+
}
434+
if addSiteResponse.Res != 0 {
435+
t.Errorf("Response code doesn't match")
436+
}
437+
438+
updateSiteResponse, err := client.UpdateSite(siteID, "domain_validation", "DNS")
439+
440+
if err != nil {
441+
t.Errorf("Should not have received an error")
442+
}
443+
if updateSiteResponse == nil {
444+
t.Errorf("Should not have received a nil updateSiteResponse instance")
445+
}
446+
if updateSiteResponse.SiteID != 111 {
447+
t.Errorf("Site ID doesn't match")
448+
}
449+
if updateSiteResponse.Res != 1 {
450+
t.Errorf("Response code doesn't match")
451+
}
452+
}

0 commit comments

Comments
 (0)