Skip to content

Commit

Permalink
Test debug mode in attack & remove unnecessary aliases & newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
Ullaakut committed May 4, 2020
1 parent 96928ac commit 6486d04
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 3 deletions.
1 change: 1 addition & 0 deletions attack.go
Expand Up @@ -366,6 +366,7 @@ func (s *Scanner) validateStream(stream Stream) bool {
if s.debug {
s.term.Debugln("SETUP", attackURL, "RTSP/1.0 >", rc)
}

// If it's a 200, the stream is accessed successfully.
if rc == httpOK {
return true
Expand Down
103 changes: 101 additions & 2 deletions attack_test.go
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/Ullaakut/disgo"
curl "github.com/Ullaakut/go-curl"
"github.com/Ullaakut/go-curl"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
Expand Down Expand Up @@ -109,7 +109,8 @@ func TestAttack(t *testing.T) {
term: disgo.NewTerminal(disgo.WithDefaultOutput(ioutil.Discard)),
curl: curlerMock,
timeout: time.Millisecond,
verbose: false,
verbose: true,
debug: true,
credentials: fakeCredentials,
routes: fakeRoutes,
}
Expand Down Expand Up @@ -251,6 +252,7 @@ func TestAttackCredentials(t *testing.T) {
curl: curlerMock,
timeout: test.timeout,
verbose: test.verbose,
debug: test.verbose,
credentials: test.credentials,
}

Expand Down Expand Up @@ -389,6 +391,102 @@ func TestAttackRoute(t *testing.T) {
}
}

scanner := &Scanner{
term: disgo.NewTerminal(disgo.WithDefaultOutput(ioutil.Discard)),
curl: curlerMock,
timeout: test.timeout,
verbose: test.verbose,
debug: test.verbose,
routes: test.routes,
}

results := scanner.AttackRoute(test.targets)

assert.Len(t, results, len(test.expectedStreams))

curlerMock.AssertExpectations(t)
})
}
}

func TestAttackRoute_NoDummyRoute(t *testing.T) {
var (
stream1 = Stream{
Device: "fakeDevice",
Address: "fakeAddress",
Port: 1337,
Available: true,
}

stream2 = Stream{
Device: "fakeDevice",
Address: "differentFakeAddress",
Port: 1337,
Available: true,
}

fakeTargets = []Stream{stream1, stream2}
fakeRoutes = Routes{"live.sdp", "media.amp"}
)

tests := []struct {
description string

targets []Stream
routes Routes
timeout time.Duration
verbose bool

status int

expectedStreams []Stream
expectedErr error
}{
{
description: "Route found",

targets: fakeTargets,
routes: fakeRoutes,
timeout: 1 * time.Millisecond,

status: 403,

expectedStreams: fakeTargets,
},
{
description: "Route found",

targets: fakeTargets,
routes: fakeRoutes,
timeout: 1 * time.Millisecond,

status: 401,

expectedStreams: fakeTargets,
},
{
description: "Camera accessed",

targets: fakeTargets,
routes: fakeRoutes,
timeout: 1 * time.Millisecond,

status: 200,

expectedStreams: fakeTargets,
},
}

for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
curlerMock := &CurlerMock{}
curlerMock.On("Setopt", mock.Anything, mock.Anything).Return(nil)
curlerMock.On("Perform").Return(nil)

// 404 on first call to the dummy route.
curlerMock.On("Getinfo", mock.Anything).Return(404, nil).Once()
curlerMock.On("Getinfo", mock.Anything).Return(test.status, nil)

scanner := &Scanner{
term: disgo.NewTerminal(disgo.WithDefaultOutput(ioutil.Discard)),
curl: curlerMock,
Expand Down Expand Up @@ -534,6 +632,7 @@ func TestValidateStreams(t *testing.T) {
curl: curlerMock,
timeout: test.timeout,
verbose: test.verbose,
debug: test.verbose,
}

results := scanner.ValidateStreams(test.targets)
Expand Down
1 change: 0 additions & 1 deletion scan_test.go
Expand Up @@ -103,7 +103,6 @@ func TestScan(t *testing.T) {
}

func TestInternalScan(t *testing.T) {

tests := []struct {
description string

Expand Down

0 comments on commit 6486d04

Please sign in to comment.