Remove responsibility for Attack methods to declare no attack success as an error

This commit is contained in:
Brendan Le Glaunec
2018-03-12 14:15:07 +01:00
parent 20daf73371
commit 08fcfcdac8
2 changed files with 20 additions and 38 deletions
-10
View File
@@ -166,16 +166,11 @@ func AttackCredentials(c Curler, targets []Stream, credentials Credentials, time
attackResults = append(attackResults, <-attacks) attackResults = append(attackResults, <-attacks)
} }
found := 0
for _, result := range attackResults { for _, result := range attackResults {
if result.CredentialsFound == true { if result.CredentialsFound == true {
targets = replace(targets, result) targets = replace(targets, result)
found++
} }
} }
if found == 0 {
return targets, errors.New("no credentials found")
}
return targets, nil return targets, nil
} }
@@ -201,16 +196,11 @@ func AttackRoute(c Curler, targets []Stream, routes Routes, timeout time.Duratio
attackResults = append(attackResults, <-attacks) attackResults = append(attackResults, <-attacks)
} }
found := 0
for _, result := range attackResults { for _, result := range attackResults {
if result.RouteFound == true { if result.RouteFound == true {
targets = replace(targets, result) targets = replace(targets, result)
found++
} }
} }
if found == 0 {
return targets, errors.New("no routes found")
}
return targets, nil return targets, nil
} }
+20 -28
View File
@@ -110,7 +110,6 @@ func TestAttackCredentials(t *testing.T) {
performErr: errors.New("dummy error"), performErr: errors.New("dummy error"),
expectedStreams: fakeTargets, expectedStreams: fakeTargets,
expectedErrMsg: "no credentials found",
}, },
// curl getinfo fails // curl getinfo fails
{ {
@@ -121,19 +120,6 @@ func TestAttackCredentials(t *testing.T) {
getInfoErr: errors.New("dummy error"), getInfoErr: errors.New("dummy error"),
expectedStreams: fakeTargets, expectedStreams: fakeTargets,
expectedErrMsg: "no credentials found",
},
// Credentials not found
{
targets: fakeTargets,
credentials: fakeCredentials,
timeout: 1 * time.Millisecond,
log: true,
status: 403,
expectedStreams: fakeTargets,
expectedErrMsg: "no credentials found",
}, },
// Logging disabled // Logging disabled
{ {
@@ -145,7 +131,17 @@ func TestAttackCredentials(t *testing.T) {
status: 403, status: 403,
expectedStreams: fakeTargets, expectedStreams: fakeTargets,
expectedErrMsg: "no credentials found", },
// Logging enabled
{
targets: fakeTargets,
credentials: fakeCredentials,
timeout: 1 * time.Millisecond,
log: true,
status: 403,
expectedStreams: fakeTargets,
}, },
} }
for i, test := range testCases { for i, test := range testCases {
@@ -272,7 +268,6 @@ func TestAttackRoute(t *testing.T) {
performErr: errors.New("dummy error"), performErr: errors.New("dummy error"),
expectedStreams: fakeTargets, expectedStreams: fakeTargets,
expectedErrMsg: "no routes found",
}, },
// curl getinfo fails // curl getinfo fails
{ {
@@ -283,17 +278,6 @@ func TestAttackRoute(t *testing.T) {
getInfoErr: errors.New("dummy error"), getInfoErr: errors.New("dummy error"),
expectedStreams: fakeTargets, expectedStreams: fakeTargets,
expectedErrMsg: "no routes found",
},
// Routes not found
{
targets: fakeTargets,
routes: fakeRoutes,
timeout: 1 * time.Millisecond,
log: true,
expectedStreams: fakeTargets,
expectedErrMsg: "no routes found",
}, },
// Logs disabled // Logs disabled
{ {
@@ -303,7 +287,15 @@ func TestAttackRoute(t *testing.T) {
log: false, log: false,
expectedStreams: fakeTargets, expectedStreams: fakeTargets,
expectedErrMsg: "no routes found", },
// Logs enabled
{
targets: fakeTargets,
routes: fakeRoutes,
timeout: 1 * time.Millisecond,
log: true,
expectedStreams: fakeTargets,
}, },
} }
for i, test := range testCases { for i, test := range testCases {