From 6486d04e615b3fc0fb8f9b454875d520f09e3d45 Mon Sep 17 00:00:00 2001 From: Ullaakut Date: Mon, 4 May 2020 08:37:26 +0200 Subject: [PATCH] Test debug mode in attack & remove unnecessary aliases & newlines --- attack.go | 1 + attack_test.go | 103 ++++++++++++++++++++++++++++++++++++++++++++++++- scan_test.go | 1 - 3 files changed, 102 insertions(+), 3 deletions(-) diff --git a/attack.go b/attack.go index fc27ff4..900464a 100644 --- a/attack.go +++ b/attack.go @@ -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 diff --git a/attack_test.go b/attack_test.go index 008fe43..f2b9f38 100644 --- a/attack_test.go +++ b/attack_test.go @@ -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" ) @@ -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, } @@ -251,6 +252,7 @@ func TestAttackCredentials(t *testing.T) { curl: curlerMock, timeout: test.timeout, verbose: test.verbose, + debug: test.verbose, credentials: test.credentials, } @@ -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, @@ -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) diff --git a/scan_test.go b/scan_test.go index 9eb2ec6..016c8f7 100644 --- a/scan_test.go +++ b/scan_test.go @@ -103,7 +103,6 @@ func TestScan(t *testing.T) { } func TestInternalScan(t *testing.T) { - tests := []struct { description string