From 269f3b7b66af5dd869b9cd6d5c4063265d55aecf Mon Sep 17 00:00:00 2001
From: Simran Khalsa <68570441+skhalsa-sigsci@users.noreply.github.com>
Date: Thu, 23 Jan 2025 11:26:12 -0800
Subject: [PATCH 1/4] add support for simulator api
---
api.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++
api_test.go | 25 +++++++++++++++++++++++++
2 files changed, 71 insertions(+)
diff --git a/api.go b/api.go
index e0eeb8b..e0dae28 100644
--- a/api.go
+++ b/api.go
@@ -3039,3 +3039,49 @@ func (sc *Client) UpdateEdgeDeploymentBackends(corpName, siteName, fastlySID str
return err
}
+
+// Simulation request the sample request and response for the simulation test
+type SimulationBody struct {
+ SampleRequest string `json:"sample_request"`
+ SampleResponse string `json:"sample_response"`
+}
+
+// SimulationResponse the response of the simulation test
+type ResponseSimulationBody struct {
+ Data struct {
+ WafResponse int `json:"waf_response"`
+ ResponseCode int `json:"response_code"`
+ ResponseSize int `json:"response_size"`
+ Signals []struct {
+ Type string `json:"type"`
+ Location string `json:"location"`
+ Name string `json:"name"`
+ Value string `json:"value"`
+ Detector string `json:"detector"`
+ Redaction int `json:"redaction"`
+ } `json:"signals"`
+ } `json:"data"`
+}
+
+// getSimulationOutput gets the simulation output
+func getResponseSimulationBody(response []byte) (ResponseSimulationBody, error) {
+ var responseSimulation ResponseSimulationBody
+ err := json.Unmarshal(response, &responseSimulation)
+ if err != nil {
+ return ResponseSimulationBody{}, err
+ }
+ return responseSimulation, nil
+}
+
+// SendSimulation sends a simulation test to
+func (sc *Client) SendSimulation(corpName, siteName string, body SimulationBody) (ResponseSimulationBody, error) {
+ b, err := json.Marshal(body)
+ if err != nil {
+ return ResponseSimulationBody{}, err
+ }
+ resp, err := sc.doRequest("POST", fmt.Sprintf("/v0/corps/%s/sites/%s/simulator", corpName, siteName), string(b))
+ if err != nil {
+ return ResponseSimulationBody{}, err
+ }
+ return getResponseSimulationBody(resp)
+}
diff --git a/api_test.go b/api_test.go
index c7b3721..a7251d7 100644
--- a/api_test.go
+++ b/api_test.go
@@ -1886,3 +1886,28 @@ func TestCRUDSiteRequestRule(t *testing.T) {
t.Fatal(err)
}
}
+
+func TestSendSimulation(t *testing.T) {
+ sc := NewTokenClient(testcreds.email, testcreds.token)
+ corp := testcreds.corp
+ site := testcreds.site
+ body := SimulationBody{
+ // sample request with xss paylaod
+ SampleRequest: `POST /?q= HTTP/1.1\nHost: sample.foo\n\n`,
+ SampleResponse: `HTTP/1.1 200 OK`,
+ }
+ responseSimulation, err := sc.SendSimulation(corp, site, body)
+ if err != nil {
+ t.Fatal(err)
+ }
+ // check for XSS signal
+ found := false
+ for _, signal := range responseSimulation.Data.Signals {
+ if signal.Type == "XSS" {
+ found = true
+ }
+ }
+ if !found {
+ t.Errorf("XSS signal expected, but not found")
+ }
+}
From dcb2b52062a868777e8ff8755790d4ccda7398ae Mon Sep 17 00:00:00 2001
From: Simran Khalsa <68570441+skhalsa-sigsci@users.noreply.github.com>
Date: Thu, 23 Jan 2025 11:32:34 -0800
Subject: [PATCH 2/4] simulator
---
api.go | 30 +++++++++++++++---------------
api_test.go | 8 ++++----
2 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/api.go b/api.go
index e0dae28..e3002d6 100644
--- a/api.go
+++ b/api.go
@@ -3040,14 +3040,14 @@ func (sc *Client) UpdateEdgeDeploymentBackends(corpName, siteName, fastlySID str
return err
}
-// Simulation request the sample request and response for the simulation test
-type SimulationBody struct {
+// Simulator request the sample request and response for the simulator test
+type SimulatorBody struct {
SampleRequest string `json:"sample_request"`
SampleResponse string `json:"sample_response"`
}
-// SimulationResponse the response of the simulation test
-type ResponseSimulationBody struct {
+// SimulatorResponse the response of the simulator test
+type ResponseSimulatorBody struct {
Data struct {
WafResponse int `json:"waf_response"`
ResponseCode int `json:"response_code"`
@@ -3063,25 +3063,25 @@ type ResponseSimulationBody struct {
} `json:"data"`
}
-// getSimulationOutput gets the simulation output
-func getResponseSimulationBody(response []byte) (ResponseSimulationBody, error) {
- var responseSimulation ResponseSimulationBody
- err := json.Unmarshal(response, &responseSimulation)
+// getSimulatorOutput gets the simulator output
+func getResponseSimulatorBody(response []byte) (ResponseSimulatorBody, error) {
+ var responseSimulator ResponseSimulatorBody
+ err := json.Unmarshal(response, &responseSimulator)
if err != nil {
- return ResponseSimulationBody{}, err
+ return ResponseSimulatorBody{}, err
}
- return responseSimulation, nil
+ return responseSimulator, nil
}
-// SendSimulation sends a simulation test to
-func (sc *Client) SendSimulation(corpName, siteName string, body SimulationBody) (ResponseSimulationBody, error) {
+// SendSimulator sends a simulator test to
+func (sc *Client) SendSimulator(corpName, siteName string, body SimulatorBody) (ResponseSimulatorBody, error) {
b, err := json.Marshal(body)
if err != nil {
- return ResponseSimulationBody{}, err
+ return ResponseSimulatorBody{}, err
}
resp, err := sc.doRequest("POST", fmt.Sprintf("/v0/corps/%s/sites/%s/simulator", corpName, siteName), string(b))
if err != nil {
- return ResponseSimulationBody{}, err
+ return ResponseSimulatorBody{}, err
}
- return getResponseSimulationBody(resp)
+ return getResponseSimulatorBody(resp)
}
diff --git a/api_test.go b/api_test.go
index a7251d7..b8c255b 100644
--- a/api_test.go
+++ b/api_test.go
@@ -1887,22 +1887,22 @@ func TestCRUDSiteRequestRule(t *testing.T) {
}
}
-func TestSendSimulation(t *testing.T) {
+func TestSendSimulator(t *testing.T) {
sc := NewTokenClient(testcreds.email, testcreds.token)
corp := testcreds.corp
site := testcreds.site
- body := SimulationBody{
+ body := SimulatorBody{
// sample request with xss paylaod
SampleRequest: `POST /?q= HTTP/1.1\nHost: sample.foo\n\n`,
SampleResponse: `HTTP/1.1 200 OK`,
}
- responseSimulation, err := sc.SendSimulation(corp, site, body)
+ responseSimulator, err := sc.SendSimulator(corp, site, body)
if err != nil {
t.Fatal(err)
}
// check for XSS signal
found := false
- for _, signal := range responseSimulation.Data.Signals {
+ for _, signal := range responseSimulator.Data.Signals {
if signal.Type == "XSS" {
found = true
}
From 489610636262eee23169dc3436ba85eb7e6e3f8e Mon Sep 17 00:00:00 2001
From: Simran Khalsa <68570441+skhalsa-sigsci@users.noreply.github.com>
Date: Thu, 23 Jan 2025 12:02:00 -0800
Subject: [PATCH 3/4] update
---
api.go | 30 +++++++++++++++---------------
api_test.go | 8 ++++----
2 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/api.go b/api.go
index e3002d6..e0dae28 100644
--- a/api.go
+++ b/api.go
@@ -3040,14 +3040,14 @@ func (sc *Client) UpdateEdgeDeploymentBackends(corpName, siteName, fastlySID str
return err
}
-// Simulator request the sample request and response for the simulator test
-type SimulatorBody struct {
+// Simulation request the sample request and response for the simulation test
+type SimulationBody struct {
SampleRequest string `json:"sample_request"`
SampleResponse string `json:"sample_response"`
}
-// SimulatorResponse the response of the simulator test
-type ResponseSimulatorBody struct {
+// SimulationResponse the response of the simulation test
+type ResponseSimulationBody struct {
Data struct {
WafResponse int `json:"waf_response"`
ResponseCode int `json:"response_code"`
@@ -3063,25 +3063,25 @@ type ResponseSimulatorBody struct {
} `json:"data"`
}
-// getSimulatorOutput gets the simulator output
-func getResponseSimulatorBody(response []byte) (ResponseSimulatorBody, error) {
- var responseSimulator ResponseSimulatorBody
- err := json.Unmarshal(response, &responseSimulator)
+// getSimulationOutput gets the simulation output
+func getResponseSimulationBody(response []byte) (ResponseSimulationBody, error) {
+ var responseSimulation ResponseSimulationBody
+ err := json.Unmarshal(response, &responseSimulation)
if err != nil {
- return ResponseSimulatorBody{}, err
+ return ResponseSimulationBody{}, err
}
- return responseSimulator, nil
+ return responseSimulation, nil
}
-// SendSimulator sends a simulator test to
-func (sc *Client) SendSimulator(corpName, siteName string, body SimulatorBody) (ResponseSimulatorBody, error) {
+// SendSimulation sends a simulation test to
+func (sc *Client) SendSimulation(corpName, siteName string, body SimulationBody) (ResponseSimulationBody, error) {
b, err := json.Marshal(body)
if err != nil {
- return ResponseSimulatorBody{}, err
+ return ResponseSimulationBody{}, err
}
resp, err := sc.doRequest("POST", fmt.Sprintf("/v0/corps/%s/sites/%s/simulator", corpName, siteName), string(b))
if err != nil {
- return ResponseSimulatorBody{}, err
+ return ResponseSimulationBody{}, err
}
- return getResponseSimulatorBody(resp)
+ return getResponseSimulationBody(resp)
}
diff --git a/api_test.go b/api_test.go
index b8c255b..a7251d7 100644
--- a/api_test.go
+++ b/api_test.go
@@ -1887,22 +1887,22 @@ func TestCRUDSiteRequestRule(t *testing.T) {
}
}
-func TestSendSimulator(t *testing.T) {
+func TestSendSimulation(t *testing.T) {
sc := NewTokenClient(testcreds.email, testcreds.token)
corp := testcreds.corp
site := testcreds.site
- body := SimulatorBody{
+ body := SimulationBody{
// sample request with xss paylaod
SampleRequest: `POST /?q= HTTP/1.1\nHost: sample.foo\n\n`,
SampleResponse: `HTTP/1.1 200 OK`,
}
- responseSimulator, err := sc.SendSimulator(corp, site, body)
+ responseSimulation, err := sc.SendSimulation(corp, site, body)
if err != nil {
t.Fatal(err)
}
// check for XSS signal
found := false
- for _, signal := range responseSimulator.Data.Signals {
+ for _, signal := range responseSimulation.Data.Signals {
if signal.Type == "XSS" {
found = true
}
From a4ccc6c2e8828ce5f52d2b4b7bc067e227c9d891 Mon Sep 17 00:00:00 2001
From: Simran Khalsa <68570441+skhalsa-sigsci@users.noreply.github.com>
Date: Thu, 23 Jan 2025 12:03:57 -0800
Subject: [PATCH 4/4] update comments
---
api.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/api.go b/api.go
index e0dae28..c3dd7b3 100644
--- a/api.go
+++ b/api.go
@@ -3063,7 +3063,7 @@ type ResponseSimulationBody struct {
} `json:"data"`
}
-// getSimulationOutput gets the simulation output
+// getResponseSimulationBody gets the simulation response
func getResponseSimulationBody(response []byte) (ResponseSimulationBody, error) {
var responseSimulation ResponseSimulationBody
err := json.Unmarshal(response, &responseSimulation)
@@ -3073,7 +3073,7 @@ func getResponseSimulationBody(response []byte) (ResponseSimulationBody, error)
return responseSimulation, nil
}
-// SendSimulation sends a simulation test to
+// SendSimulation sends a simulation test and returns the response
func (sc *Client) SendSimulation(corpName, siteName string, body SimulationBody) (ResponseSimulationBody, error) {
b, err := json.Marshal(body)
if err != nil {