From 268f91b05e91cdc051b18d57d1dfaa05d2d4aad4 Mon Sep 17 00:00:00 2001 From: Chris Cooney Date: Sat, 2 Sep 2017 09:39:11 +0100 Subject: [PATCH] Further changes to conform with codacy --- attacks.go | 7 ++++--- attacks_test.go | 4 ++-- monkey.go | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/attacks.go b/attacks.go index 6d8f8fa..c275857 100644 --- a/attacks.go +++ b/attacks.go @@ -6,6 +6,7 @@ import ( "strings" ) +// Response is a struct representing the outcome of an attack. type Response struct { Passed bool Report string @@ -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) @@ -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, "") @@ -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) diff --git a/attacks_test.go b/attacks_test.go index 3b84a23..2c9fdd6 100644 --- a/attacks_test.go +++ b/attacks_test.go @@ -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") @@ -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() diff --git a/monkey.go b/monkey.go index fef0834..a80e97e 100644 --- a/monkey.go +++ b/monkey.go @@ -4,7 +4,6 @@ import ( "fmt" "math/rand" "time" - "errors" "os" ) @@ -25,6 +24,7 @@ func main() { } } +// PerformSequentialAttack runs through each attack in config and run them in sequence. func PerformSequentialAttack(config *Config) { isFailure := false; @@ -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) @@ -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