Esempio n. 1
0
func TestBackgroundAndScenarios(t *testing.T) {
	s := `
Attack: Parsing multiple scenarios
  @tag_on_background
  Background:
    Given there is some background

	Scenario: Scenario name here
    Given some precondition
    And then something else
    Then something happens

  Scenario: Another scenario
    Given another precondition
    Then something happens
`
	// Scenario: The scenario is a thing
	//   When there is an action
	//   Then something happens

	// Scenario: Another thing
	//   When there is another action
	//   Then something else happens
	attacks, err := Parse(s)
	assert.NoError(t, err)
	// assert.Equal(t, "@tag_on_background", attacks[0].Background.Tags[0])
	// assert.Equal(t, "there is some background", attacks[0].Background.Steps[0].Text)

	if len(attacks[0].Scenarios) != 2 {
		t.Error("Got length of", len(attacks[0].Scenarios))
	}
	assert.Equal(t, 2, len(attacks[0].Scenarios))
}
Esempio n. 2
0
func TestMultipleScenarios(t *testing.T) {
	s := `
Attack: Parsing multiple scenarios
  Scenario: Scenario name here
    Given some precondition
    Then something happens

  Scenario: The second scenario
    Given a condition
    Then something happens
`
	attacks, err := Parse(s)
	assert.NoError(t, err)
	assert.Equal(t, 2, len(attacks[0].Scenarios))
	assert.Equal(t, 2, len(attacks[0].Scenarios[0].Steps))
	assert.Equal(t, 2, len(attacks[0].Scenarios[1].Steps))
}
Esempio n. 3
0
func TestParseSingleScenario(t *testing.T) {
	s := `
# a line comment
@tag1 @tag2
Attack: Basic attack

  # a comment embedded in the description
  A multiline description of the Attack
  that can contain any text like
  Rules:
  - a
  - b

  @tag3 @tag4
  Scenario: The title of the scenario
    Given an attack tool is installed
    When the tool is run
    And some other condition
    Then there should not be vulnerabilities

# End of file comment with some empty lines below

`
	attacks, err := Parse(s)

	assert.NoError(t, err)
	assert.Equal(t, 1, len(attacks))
	assert.Equal(t, "Basic attack", attacks[0].Title)
	assert.Equal(t, "@tag1", attacks[0].Tags[0])
	assert.Equal(t, "@tag2", attacks[0].Tags[1])
	assert.Equal(t, 1, len(attacks[0].Scenarios))
	assert.Equal(t, "A multiline description of the Attack\nthat can contain any text like\nRules:\n- a\n- b", attacks[0].Description)
	assert.Equal(t, "The title of the scenario", attacks[0].Scenarios[0].Title)
	assert.Equal(t, 4, len(attacks[0].Scenarios[0].Steps))
	assert.Equal(t, "@tag3", attacks[0].Scenarios[0].Tags[0])
	assert.Equal(t, "@tag4", attacks[0].Scenarios[0].Tags[1])
	assert.Equal(t, StepType("Given"), attacks[0].Scenarios[0].Steps[0].Type)
	assert.Equal(t, "an attack tool is installed", attacks[0].Scenarios[0].Steps[0].Text)
	assert.Equal(t, StepType("When"), attacks[0].Scenarios[0].Steps[1].Type)
	assert.Equal(t, "the tool is run", attacks[0].Scenarios[0].Steps[1].Text)
	assert.Equal(t, StepType("And"), attacks[0].Scenarios[0].Steps[2].Type)
	assert.Equal(t, "some other condition", attacks[0].Scenarios[0].Steps[2].Text)
	assert.Equal(t, StepType("Then"), attacks[0].Scenarios[0].Steps[3].Type)
	assert.Equal(t, "there should not be vulnerabilities", attacks[0].Scenarios[0].Steps[3].Text)
}