@@ -2,6 +2,7 @@ package incapsula
2
2
3
3
import (
4
4
"fmt"
5
+ "io"
5
6
"net/http"
6
7
"net/http/httptest"
7
8
"strings"
@@ -380,3 +381,72 @@ func TestClientDeleteSiteValidSite(t *testing.T) {
380
381
t .Errorf ("Should not have received an error" )
381
382
}
382
383
}
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