Skip to content

Commit

Permalink
code review: rename Description to Name
Browse files Browse the repository at this point in the history
  • Loading branch information
christophetd committed Nov 21, 2022
1 parent 2e80cc8 commit aaf8c50
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/cli-usage/scenarios.threatest.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
scenarios:
# Example 1: Remote detonation over SSH
# Note: SSH configuration is provided using the --ssh-host, --ssh-username and --ssh-keyfile CLI arguments
- description: curl metadata service
- name: curl metadata service
detonate:
remoteDetonator:
commands: ["curl http://169.254.169.254 --connect-timeout 1"]
Expand All @@ -14,7 +14,7 @@ scenarios:
# Example 2: Stratus Red Team detonation
# Note: You must be authenticated to the relevant cloud provider before running it
# The example below is equivalent to manually running "stratus detonate aws.exfiltration.ec2-security-group-open-port-22-ingress"
- description: opening a security group to the Internet
- name: opening a security group to the Internet
detonate:
stratusRedTeamDetonator:
attackTechnique: aws.exfiltration.ec2-security-group-open-port-22-ingress
Expand Down
16 changes: 11 additions & 5 deletions pkg/threatest/parser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func buildScenarios(parsed *ThreatestSchemaJson, sshHostname string, sshUsername

for _, parsedScenario := range parsed.Scenarios {
scenario := threatest.Scenario{}
scenario.Name = parsedScenario.Description
scenario.Name = parsedScenario.Name

if parsedScenario.Detonate == nil {
return nil, fmt.Errorf("scenario '%s' has no detonation defined", parsedScenario.Description)
if !hasDetonation(parsedScenario) {
return nil, fmt.Errorf("scenario '%s' has no detonation defined", parsedScenario.Name)
}

// Detonation
Expand All @@ -59,7 +59,7 @@ func buildScenarios(parsed *ThreatestSchemaJson, sshHostname string, sshUsername

// Assertions
if len(parsedScenario.Expectations) == 0 {
return nil, fmt.Errorf("scenario '%s' has no assertions defined", parsedScenario.Description)
return nil, fmt.Errorf("scenario '%s' has no assertions defined", parsedScenario.Name)
}
for _, parsedAssertion := range parsedScenario.Expectations {
if datadogMatcher := parsedAssertion.DatadogSecuritySignal; datadogMatcher != nil {
Expand All @@ -76,11 +76,17 @@ func buildScenarios(parsed *ThreatestSchemaJson, sshHostname string, sshUsername
rawTimeout := parsedScenario.Expectations[0].Timeout
parsedDuration, err := time.ParseDuration(rawTimeout)
if err != nil {
return nil, fmt.Errorf("scenario '%s' has an invalid timeout '%s': '%v'", parsedScenario.Description, rawTimeout, err)
return nil, fmt.Errorf("scenario '%s' has an invalid timeout '%s': '%v'", parsedScenario.Name, rawTimeout, err)
}
scenario.Timeout = parsedDuration

scenarios = append(scenarios, &scenario)
}
return scenarios, nil
}

// hasDetonation returns true if the scenario has at least 1 detonation defined
func hasDetonation(scenario ThreatestSchemaJsonScenariosElem) bool {
detonations := scenario.Detonate
return detonations.LocalDetonator != nil || detonations.RemoteDetonator != nil || detonations.StratusRedTeamDetonator != nil
}
27 changes: 19 additions & 8 deletions pkg/threatest/parser/parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions schemas/threatest.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
"type": "object",
"description": "The list of scenarios",
"required": [
"description",
"name",
"detonate",
"expectations"
],
"properties": {
"description": {
"name": {
"type": "string",
"description": "Description of the scenario"
},
Expand Down

0 comments on commit aaf8c50

Please sign in to comment.