Skip to content

Commit

Permalink
Changed to use antijoke tests (no BDD)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddie-knight committed Feb 6, 2023
1 parent 19c7ccf commit 0983778
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 147 deletions.
28 changes: 0 additions & 28 deletions .github/ISSUE_TEMPLATE/bdd_request.md

This file was deleted.

2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
go mod download
go get -u golang.org/x/lint/golint
go get -t .
go get github.com/markbates/pkger/cmd/pkger
- name: Lint
run: |
Expand All @@ -36,5 +35,4 @@ jobs:
- name: Build
run: |
pkger
go build -o wireframe
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ config.yml
wireframe
wireframe-darwin
!internal/wireframe
# Ignoring pkger buffer, as it should be regenerated on every build
pkged.go

# Dir may be created during dev/debugging
main/
11 changes: 3 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ BUILD_WIN=@env GOOS=windows GOARCH=amd64 go build -o $(PACKNAME).exe
BUILD_LINUX=@env GOOS=linux GOARCH=amd64 go build -o $(PACKNAME)
BUILD_MAC=@env GOOS=darwin GOARCH=amd64 go build -o $(PACKNAME)-darwin

release: go-package go-release pkgr-clean
release-candidate: go-package go-release-candidate pkgr-clean
binary: go-package go-build pkgr-clean
release: go-package go-release
release-candidate: go-package go-release-candidate
binary: go-package go-build

go-release: release-nix release-win release-mac

Expand All @@ -16,11 +16,6 @@ go-build:

go-package: go-tidy go-test
@echo " > Packaging static files..."
@pkger

pkgr-clean:
@echo " > Removing pkged.go to avoid accidental re-use of old files..."
@rm pkged.go

go-test:
@echo " > Validating code ..."
Expand Down
Binary file removed assets/images/probr.png
Binary file not shown.
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ module github.com/privateerproj/privateer-pack-wireframe
go 1.14

require (
github.com/cucumber/godog v0.11.0
github.com/cucumber/godog v0.12.6
github.com/hashicorp/go-hclog v0.15.0 // indirect
github.com/markbates/pkger v0.17.1
github.com/privateerproj/privateer-sdk v0.0.0
)

// For Development Only
replace github.com/privateerproj/privateer-sdk => ../privateer-sdk
replace github.com/privateerproj/privateer-sdk => ../privateer-sdk
106 changes: 33 additions & 73 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func (ctx *varOptions) Init() (err error) {
}
sdkConfig.GlobalConfig.VarsFile = ctx.VarsFile
sdkConfig.GlobalConfig.Init()
sdkConfig.GlobalConfig.PrepareOutputDirectory("audit", "cucumber")

ctx.Raids.Wireframe.setEnvAndDefaults()

Expand Down Expand Up @@ -63,5 +62,6 @@ func (ctx *wireframe) setEnvAndDefaults() {
// 2. Name of env var to check
// 3. Default value to set if flags, vars file, and env have not provided a value

setter.SetVar(&ctx.Pass, "PROBR_PASS_WIREFRAME_TESTS", "false")
setter.SetVar(&ctx.Pass, "PVTR_WIREFRAME_PASS_TESTS", "false")
setter.SetVar(&ctx.JokeName, "PVTR_WIREFRAME_JOKE_NAME", "")
}
1 change: 1 addition & 0 deletions internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type servicePacks struct {
// wireframe defines the custom vars for this service pack
type wireframe struct {
Pass string `yaml:"Pass"`
JokeName string `yaml:"JokeName"`
TagInclusions []string `yaml:"TagInclusions"`
TagExclusions []string `yaml:"TagExclusions"`
}
2 changes: 1 addition & 1 deletion internal/welcome/welcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (probe probeStruct) ScenarioInitialize(ctx *godog.ScenarioContext) {
ctx.BeforeScenario(func(s *godog.Scenario) {
scenario.name = s.Name
scenario.probe = summary.State.GetProbeLog(probe.Name())
scenario.audit = summary.State.GetProbeLog(probe.Name()).InitializeAuditor(s.Name, s.Tags)
// scenario.audit = summary.State.GetProbeLog(probe.Name()).InitializeAuditor(s.Name, s.Tags)
probeengine.LogScenarioStart(s)
})

Expand Down
29 changes: 11 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import (
"syscall"

"github.com/privateerproj/privateer-pack-wireframe/internal/config"
"github.com/privateerproj/privateer-pack-wireframe/internal/summary"
"github.com/privateerproj/privateer-pack-wireframe/pack"
"github.com/privateerproj/privateer-sdk/raidengine"

audit "github.com/privateerproj/privateer-sdk/audit"
sdkConfig "github.com/privateerproj/privateer-sdk/config"
"github.com/privateerproj/privateer-sdk/plugin"
probeengine "github.com/privateerproj/privateer-sdk/probeengine"
"github.com/privateerproj/privateer-sdk/utils"
)

Expand Down Expand Up @@ -91,7 +89,7 @@ func handleCommands(versionCmd, runCmd *flag.FlagSet) {
// Serve plugin
raid := &Raid{}
serveOpts := &plugin.ServeOpts{
Pack: raid,
Plugin: raid,
}

plugin.Serve(serveOpts)
Expand All @@ -103,7 +101,7 @@ func handleCommands(versionCmd, runCmd *flag.FlagSet) {
// our clean up procedure and exiting the program.
// Ref: https://golangcode.com/handle-ctrl-c-exit-in-terminal/
func setupCloseHandler() {
c := make(chan os.Signal)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
Expand All @@ -120,23 +118,18 @@ func PrivateerCoreLogic() (err error) {
setupCloseHandler() // Sigterm protection

config.Vars.Init()
summary.State = audit.NewSummaryState(RaidName)

store := probeengine.NewProbeStore(RaidName, config.Vars.Tags(), &summary.State)
s, err := store.RunAllProbes(pack.GetProbes())
if err != nil {
log.Printf("[ERROR] Error executing tests %v", err)
return
}
log.Printf("[INFO] Overall test completion status: %v", s)
summary.State.SetPrivateerStatus()
raids := pack.Policies["CIS"] // TODO: add a func to get a list of raids from the config & consolidate the attacks

errors := raidengine.Run(raids) // TODO handle these errors

summary.State.PrintSummary()
summary.State.WriteSummary()
output := fmt.Sprintf("%v/%v attacks succeeded. View the output logs for more details.", len(raids)-len(errors), len(raids))
log.Print(output)

if summary.State.ProbesFailed > 0 {
return utils.ReformatError("One or more probe scenarios were not successful. View the output logs for more details.")
if errors != nil {
return utils.ReformatError("Error executing tests %v", err)
}

return
}

Expand Down
39 changes: 39 additions & 0 deletions pack/antijokes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package pack

import (
"log"

"github.com/privateerproj/privateer-pack-wireframe/internal/config"
"github.com/privateerproj/privateer-sdk/utils"
)

// KnockKnock is a demo test for dev purposes
func KnockKnock() error {
name, err := getJokeName()
if err != nil {
return err
}
log.Printf("Knock Knock")
log.Printf("Who's There?")
log.Printf(name)
log.Printf("::The listener has lost interest and left::")
return nil
}

// ChickenCrossedRoad is a demo test for dev purposes
func ChickenCrossedRoad() error {
name, err := getJokeName()
if err != nil {
return err
}
log.Printf("Me: Why did the chicken cross the road?")
log.Printf("%s: I'm busy, leave me alone.", name)
return nil
}

func getJokeName() (string, error) {
if config.Vars.Raids.Wireframe.JokeName != "" {
return config.Vars.Raids.Wireframe.JokeName, nil
}
return "", utils.ReformatError("JokeName must be set in the config file or env vars (PVTR_WIREFRAME_JOKE_NAME)")
}
17 changes: 7 additions & 10 deletions pack/wireframe.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package pack

import (
"github.com/markbates/pkger"
"github.com/privateerproj/privateer-pack-wireframe/internal/welcome"
"github.com/privateerproj/privateer-sdk/probeengine"
"github.com/privateerproj/privateer-sdk/raidengine"
)

// GetProbes returns a list of probe objects
func GetProbes() []probeengine.Probe {
return []probeengine.Probe{
welcome.Probe,
}
func GetProbes() []raidengine.Strike {
return Policies["PCI"]
}

func init() {
// pkger.Include is a no-op that directs the pkger tool to include the desired file or folder.
pkger.Include("/internal/welcome/welcome.feature")
// Policies contains a list of different functions to run for each policy type
var Policies = map[string][]raidengine.Strike{
"PCI": []raidengine.Strike{KnockKnock},
"CIS": []raidengine.Strike{KnockKnock, ChickenCrossedRoad},
}

0 comments on commit 0983778

Please sign in to comment.