Cameradar 3.0.0: Uses ullaakut/nmap, runs faster, removed legacy code (#188)
Unit tests functional and coverage back to 100% Add more routes to dictionary, add more credentials, add default port 5554, rename cameradar logs ENV variable, improve unit test readability, remove tmp file
This commit is contained in:
committed by
GitHub
parent
878ca9f032
commit
5849898283
+26
-6
@@ -122,6 +122,7 @@ func TestLoadCredentials(t *testing.T) {
|
||||
input: []byte("{\"invalid\":\"json\"}"),
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range testCases {
|
||||
filePath := "/tmp/cameradar_test_load_credentials_" + fmt.Sprint(i) + ".xml"
|
||||
// create file
|
||||
@@ -145,12 +146,14 @@ func TestLoadCredentials(t *testing.T) {
|
||||
fmt.Printf("unexpected success in LoadCredentials test, iteration %d. expected error: %s\n", i, test.expectedErrMsg)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
assert.Contains(t, err.Error(), test.expectedErrMsg, "wrong error message")
|
||||
} else {
|
||||
if err != nil {
|
||||
fmt.Printf("unexpected error in LoadCredentials test, iteration %d: %v\n", i, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, expectedUsername := range test.expectedOutput.Usernames {
|
||||
foundUsername := false
|
||||
for _, username := range result.Usernames {
|
||||
@@ -158,8 +161,10 @@ func TestLoadCredentials(t *testing.T) {
|
||||
foundUsername = true
|
||||
}
|
||||
}
|
||||
|
||||
assert.Equal(t, true, foundUsername, "wrong usernames parsed")
|
||||
}
|
||||
|
||||
for _, expectedPassword := range test.expectedOutput.Passwords {
|
||||
foundPassword := false
|
||||
for _, password := range result.Passwords {
|
||||
@@ -167,6 +172,7 @@ func TestLoadCredentials(t *testing.T) {
|
||||
foundPassword = true
|
||||
}
|
||||
}
|
||||
|
||||
assert.Equal(t, true, foundPassword, "wrong passwords parsed")
|
||||
}
|
||||
}
|
||||
@@ -202,8 +208,10 @@ func TestLoadRoutes(t *testing.T) {
|
||||
input: []byte(""),
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range testCases {
|
||||
filePath := "/tmp/cameradar_test_load_routes_" + fmt.Sprint(i) + ".xml"
|
||||
|
||||
// create file
|
||||
if test.fileExists {
|
||||
_, err := os.Create(filePath)
|
||||
@@ -231,6 +239,7 @@ func TestLoadRoutes(t *testing.T) {
|
||||
fmt.Printf("unexpected error in LoadRoutes test, iteration %d: %v\n", i, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, expectedRoute := range test.expectedOutput {
|
||||
foundRoute := false
|
||||
for _, route := range result {
|
||||
@@ -238,6 +247,7 @@ func TestLoadRoutes(t *testing.T) {
|
||||
foundRoute = true
|
||||
}
|
||||
}
|
||||
|
||||
assert.Equal(t, true, foundRoute, "wrong routes parsed")
|
||||
}
|
||||
}
|
||||
@@ -352,7 +362,7 @@ func TestParseTargetsFile(t *testing.T) {
|
||||
openError bool
|
||||
readError bool
|
||||
|
||||
expectedResult string
|
||||
expectedResult []string
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
@@ -360,7 +370,7 @@ func TestParseTargetsFile(t *testing.T) {
|
||||
|
||||
fileExists: false,
|
||||
|
||||
expectedResult: "0.0.0.0",
|
||||
expectedResult: []string{"0.0.0.0"},
|
||||
expectedError: nil,
|
||||
},
|
||||
{
|
||||
@@ -368,7 +378,7 @@ func TestParseTargetsFile(t *testing.T) {
|
||||
|
||||
fileExists: true,
|
||||
|
||||
expectedResult: "0.0.0.0 localhost 192.17.0.0/16 192.168.1.140-255 192.168.2-3.0-255",
|
||||
expectedResult: []string{"0.0.0.0", "localhost", "192.17.0.0/16", "192.168.1.140-255", "192.168.2-3.0-255"},
|
||||
expectedError: nil,
|
||||
},
|
||||
{
|
||||
@@ -377,7 +387,7 @@ func TestParseTargetsFile(t *testing.T) {
|
||||
fileExists: true,
|
||||
openError: true,
|
||||
|
||||
expectedResult: "test_does_not_really_exist",
|
||||
expectedResult: []string{"test_does_not_really_exist"},
|
||||
expectedError: os.ErrNotExist,
|
||||
},
|
||||
{
|
||||
@@ -386,7 +396,7 @@ func TestParseTargetsFile(t *testing.T) {
|
||||
fileExists: true,
|
||||
readError: true,
|
||||
|
||||
expectedResult: "test_does_not_really_exist",
|
||||
expectedResult: []string{"test_does_not_really_exist"},
|
||||
expectedError: os.ErrNotExist,
|
||||
},
|
||||
}
|
||||
@@ -399,10 +409,20 @@ func TestParseTargetsFile(t *testing.T) {
|
||||
readError: test.readError,
|
||||
}
|
||||
mfs.fileMock.On("Close").Return(nil)
|
||||
mfs.fileMock.WriteString("0.0.0.0 localhost 192.17.0.0/16 192.168.1.140-255 192.168.2-3.0-255")
|
||||
mfs.fileMock.WriteString("0.0.0.0\nlocalhost\n192.17.0.0/16\n192.168.1.140-255\n192.168.2-3.0-255")
|
||||
|
||||
result, err := ParseTargetsFile(test.input)
|
||||
assert.Equal(t, test.expectedResult, result, "unexpected result, parse error")
|
||||
assert.Equal(t, test.expectedError, err, "unexpected error")
|
||||
}
|
||||
}
|
||||
|
||||
// This is completely useless and just lets me
|
||||
// not look at these two red lines on the coverage
|
||||
// any longer.
|
||||
func TestFS(t *testing.T) {
|
||||
fs := osFS{}
|
||||
|
||||
fs.Open("test")
|
||||
fs.Stat("test")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user