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] 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 }