Skip to content

Commit

Permalink
Further changes to conform with codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisCooney committed Sep 2, 2017
1 parent ba4969a commit 268f91b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions attacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
)

// Response is a struct representing the outcome of an attack.
type Response struct {
Passed bool
Report string
Expand Down Expand Up @@ -81,7 +82,7 @@ func readResponseFromChannel(responses []*http.Response, c chan *http.Response)
return append(responses, response)
}

// Fires off the requested number of concurrent messages at an endpoint and tests response.
// RunHTTPSpam fires off the requested number of concurrent messages at an endpoint and tests response.
func RunHTTPSpam(endpointConfig EndpointConfig, attackConfig AttackConfig, responseChannel chan Response) error {
c := make(chan *http.Response)

Expand All @@ -108,7 +109,7 @@ func RunHTTPSpam(endpointConfig EndpointConfig, attackConfig AttackConfig, respo
return nil
}

// Fires off a Corrupted HTTP request at the specific endpoint.
// RunCorruptHTTP fires off a Corrupted HTTP request at the specific endpoint.
func RunCorruptHTTP(endpointConfig EndpointConfig, attackConfig AttackConfig, responseChannel chan Response) error {
c := make(chan string)
endpoint := BuildNetworkPath("", endpointConfig.Host, endpointConfig.Port, "")
Expand All @@ -129,7 +130,7 @@ func RunCorruptHTTP(endpointConfig EndpointConfig, attackConfig AttackConfig, re
return nil
}

// Hits an endpoint with a set of dodgy values in parameters.
// RunURLQuery hits an endpoint with a set of dodgy values in parameters.
func RunURLQuery(endpointConfig EndpointConfig, attackConfig AttackConfig, responseChannel chan Response) error {
c := make(chan *http.Response)

Expand Down
4 changes: 2 additions & 2 deletions attacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestRunHTTPSpam(t *testing.T) {

func TestRunCorruptHTTP(t *testing.T) {
t.Run("Test run Corrupt HTTP correctly reports on endpoints", func(t *testing.T) {
go createMockTcpServer()
go createMockTCPServer()
c := createResponseChannel()
endpoint, attack := CreateTestEndpointAndAttackConfiguration("200", "CORRUPT_HTTP")

Expand Down Expand Up @@ -97,7 +97,7 @@ func createMockHTTPServer(status int) {
httpmock.NewStringResponder(status, `[{"something": 1}]`))
}

func createMockTcpServer() {
func createMockTCPServer() {
l, _ := net.Listen("tcp", ":8080")
count := 0
defer l.Close()
Expand Down
6 changes: 3 additions & 3 deletions monkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"math/rand"
"time"
"errors"
"os"
)

Expand All @@ -25,6 +24,7 @@ func main() {
}
}

// PerformSequentialAttack runs through each attack in config and run them in sequence.
func PerformSequentialAttack(config *Config) {
isFailure := false;

Expand Down Expand Up @@ -66,7 +66,7 @@ func logResponse(response Response) {
}
}

// Sets up the targets in the config file for attack.
// SetupTargets initialises the threads for each of the attacks.
func SetupTargets(config *Config, responseChannel chan Response) {
for _,endpoint := range config.Endpoints {
fmt.Printf("🎯 Setting up %s\n", endpoint.Name)
Expand Down Expand Up @@ -105,7 +105,7 @@ func getAttackFunction(attack AttackConfig) (func(endpointConfig EndpointConfig,
attackFunc, present := AttacksStrategy[attack.Type]

if !present {
panic(errors.New(fmt.Sprintf("Unknown attack type %s", attack.Type)))
panic(fmt.Errorf("Unknown attack type %s", attack.Type))
}

return attackFunc
Expand Down

0 comments on commit 268f91b

Please sign in to comment.