Skip to content

Commit

Permalink
simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
skhalsa-sigsci committed Jan 23, 2025
1 parent 269f3b7 commit dcb2b52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
30 changes: 15 additions & 15 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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)
}
8 changes: 4 additions & 4 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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=<script>alert(1)</script> 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
}
Expand Down

0 comments on commit dcb2b52

Please sign in to comment.