Test debug mode in attack & remove unnecessary aliases & newlines
This commit is contained in:
committed by
Brendan Le Glaunec
parent
96928ac43c
commit
6486d04e61
@@ -366,6 +366,7 @@ func (s *Scanner) validateStream(stream Stream) bool {
|
|||||||
if s.debug {
|
if s.debug {
|
||||||
s.term.Debugln("SETUP", attackURL, "RTSP/1.0 >", rc)
|
s.term.Debugln("SETUP", attackURL, "RTSP/1.0 >", rc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's a 200, the stream is accessed successfully.
|
// If it's a 200, the stream is accessed successfully.
|
||||||
if rc == httpOK {
|
if rc == httpOK {
|
||||||
return true
|
return true
|
||||||
|
|||||||
+101
-2
@@ -7,7 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Ullaakut/disgo"
|
"github.com/Ullaakut/disgo"
|
||||||
curl "github.com/Ullaakut/go-curl"
|
"github.com/Ullaakut/go-curl"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
@@ -109,7 +109,8 @@ func TestAttack(t *testing.T) {
|
|||||||
term: disgo.NewTerminal(disgo.WithDefaultOutput(ioutil.Discard)),
|
term: disgo.NewTerminal(disgo.WithDefaultOutput(ioutil.Discard)),
|
||||||
curl: curlerMock,
|
curl: curlerMock,
|
||||||
timeout: time.Millisecond,
|
timeout: time.Millisecond,
|
||||||
verbose: false,
|
verbose: true,
|
||||||
|
debug: true,
|
||||||
credentials: fakeCredentials,
|
credentials: fakeCredentials,
|
||||||
routes: fakeRoutes,
|
routes: fakeRoutes,
|
||||||
}
|
}
|
||||||
@@ -251,6 +252,7 @@ func TestAttackCredentials(t *testing.T) {
|
|||||||
curl: curlerMock,
|
curl: curlerMock,
|
||||||
timeout: test.timeout,
|
timeout: test.timeout,
|
||||||
verbose: test.verbose,
|
verbose: test.verbose,
|
||||||
|
debug: test.verbose,
|
||||||
credentials: test.credentials,
|
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{
|
scanner := &Scanner{
|
||||||
term: disgo.NewTerminal(disgo.WithDefaultOutput(ioutil.Discard)),
|
term: disgo.NewTerminal(disgo.WithDefaultOutput(ioutil.Discard)),
|
||||||
curl: curlerMock,
|
curl: curlerMock,
|
||||||
@@ -534,6 +632,7 @@ func TestValidateStreams(t *testing.T) {
|
|||||||
curl: curlerMock,
|
curl: curlerMock,
|
||||||
timeout: test.timeout,
|
timeout: test.timeout,
|
||||||
verbose: test.verbose,
|
verbose: test.verbose,
|
||||||
|
debug: test.verbose,
|
||||||
}
|
}
|
||||||
|
|
||||||
results := scanner.ValidateStreams(test.targets)
|
results := scanner.ValidateStreams(test.targets)
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ func TestScan(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInternalScan(t *testing.T) {
|
func TestInternalScan(t *testing.T) {
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
description string
|
description string
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user