Skip to content

Commit 3ad8778

Browse files
fix: resolve linter and test case errors in workflow
1 parent 6a6bfb4 commit 3ad8778

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

internal/file/file.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func ReadFile(inputFile string) []string {
161161
for scanner.Scan() {
162162
text = append(text, scanner.Text())
163163
}
164+
164165
file.Close()
165166

166167
return text

pkg/crawler/colly.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func New(scan *Scan) *Results {
139139
if scan.StoreResp {
140140
var err error
141141
outputPath, err = output.StoreHTTPResponse(r, scan.OutputDir)
142+
142143
if err != nil {
143144
log.Println(err)
144145
}

pkg/crawler/useragents.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ func GenerateRandomUserAgent() string {
151151
source := rand.NewSource(time.Now().UnixNano())
152152
rng := rand.New(source)
153153

154-
decision := rng.Intn(100)
154+
const maxRandomValue = 100
155+
decision := rng.Intn(maxRandomValue)
155156

156157
var ua string
157158
if decision%2 == 0 {

pkg/output/jsonl_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func TestJSONOutput(t *testing.T) {
123123
filetype: filetype,
124124
errors: errors,
125125
infos: infos,
126-
want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"filetype":{"extension":"pdf","severity":7},"parameters":[{"name":"id","attacks":[]}],"errors":[{"name":"MySQL error","match":"it is a MySQL error happening"}],"infos":[{"name":"info1","match":"its my pleasure to inform you on this great day"}],"secrets":[{"name":"mysecret","match":"it's a random day for my secret regex to be found"}]}}`, //nolint:lll
126+
want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"filetype":{"extension":"pdf","severity":7},"parameters":[{"name":"id","attacks":[]}],"errors":[{"name":"MySQL error","match":"it is a MySQL error happening"}],"infos":[{"name":"info1","match":"its my pleasure to inform you on this great day"}],"secrets":[{"name":"mysecret","match":"it's a random day for my secret regex to be found"}]},"output_path":"C:\\testDir1\\testDir2"}`, //nolint:lll
127127
outputPath: "C:\\testDir1\\testDir2",
128128
},
129129
{
@@ -134,7 +134,7 @@ func TestJSONOutput(t *testing.T) {
134134
filetype: filetype,
135135
errors: errors,
136136
infos: infos,
137-
want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"matches":{"filetype":{"extension":"pdf","severity":7},"parameters":[{"name":"id","attacks":[]}],"errors":[{"name":"MySQL error","match":"it is a MySQL error happening"}],"infos":[{"name":"info1","match":"its my pleasure to inform you on this great day"}],"secrets":[{"name":"mysecret","match":"it's a random day for my secret regex to be found"}]}}`, //nolint:lll
137+
want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"matches":{"filetype":{"extension":"pdf","severity":7},"parameters":[{"name":"id","attacks":[]}],"errors":[{"name":"MySQL error","match":"it is a MySQL error happening"}],"infos":[{"name":"info1","match":"its my pleasure to inform you on this great day"}],"secrets":[{"name":"mysecret","match":"it's a random day for my secret regex to be found"}]},"output_path":"C:\\testDir1\\testDir2"}`, //nolint:lll
138138
outputPath: "C:\\testDir1\\testDir2",
139139
},
140140
{
@@ -145,7 +145,7 @@ func TestJSONOutput(t *testing.T) {
145145
filetype: &scanner.FileType{},
146146
errors: []scanner.ErrorMatched{},
147147
infos: []scanner.InfoMatched{},
148-
want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128}`, //nolint: all
148+
want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"output_path":"C:\\testDir1\\testDir2"}`, //nolint: all
149149
outputPath: "C:\\testDir1\\testDir2",
150150
},
151151
{
@@ -156,7 +156,7 @@ func TestJSONOutput(t *testing.T) {
156156
filetype: &scanner.FileType{},
157157
errors: []scanner.ErrorMatched{},
158158
infos: []scanner.InfoMatched{},
159-
want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"secrets":[{"name":"mysecret","match":"it's a random day for my secret regex to be found"}]}}`, //nolint:lll
159+
want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"secrets":[{"name":"mysecret","match":"it's a random day for my secret regex to be found"}]},"output_path":"C:\\testDir1\\testDir2"}`, //nolint:lll
160160
outputPath: "C:\\testDir1\\testDir2",
161161
},
162162
{
@@ -167,7 +167,7 @@ func TestJSONOutput(t *testing.T) {
167167
filetype: &scanner.FileType{},
168168
errors: []scanner.ErrorMatched{},
169169
infos: []scanner.InfoMatched{},
170-
want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"parameters":[{"name":"id","attacks":[]}]}}`, //nolint:lll
170+
want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"parameters":[{"name":"id","attacks":[]}]},"output_path":"C:\\testDir1\\testDir2"}`, //nolint:lll
171171
outputPath: "C:\\testDir1\\testDir2",
172172
},
173173
{
@@ -178,7 +178,7 @@ func TestJSONOutput(t *testing.T) {
178178
filetype: &scanner.FileType{},
179179
errors: errors,
180180
infos: []scanner.InfoMatched{},
181-
want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"errors":[{"name":"MySQL error","match":"it is a MySQL error happening"}]}}`, //nolint:lll
181+
want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"errors":[{"name":"MySQL error","match":"it is a MySQL error happening"}]},"output_path":"C:\\testDir1\\testDir2"}`, //nolint:lll
182182
outputPath: "C:\\testDir1\\testDir2",
183183
},
184184
{
@@ -189,7 +189,7 @@ func TestJSONOutput(t *testing.T) {
189189
filetype: &scanner.FileType{},
190190
errors: []scanner.ErrorMatched{},
191191
infos: infos,
192-
want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"infos":[{"name":"info1","match":"its my pleasure to inform you on this great day"}]}}`, //nolint:lll
192+
want: `{"url":"http://test.com.pdf?id=5","method":"GET","status_code":200,"words":1,"lines":1,"content_type":"application/pdf","content_length":128,"matches":{"infos":[{"name":"info1","match":"its my pleasure to inform you on this great day"}]},"output_path":"C:\\testDir1\\testDir2"}`, //nolint:lll
193193
outputPath: "C:\\testDir1\\testDir2",
194194
},
195195
{

pkg/output/output.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"github.com/edoardottt/cariddi/pkg/scanner"
3737
)
3838

39-
// constant defined in file.go as well, for circular dependency
39+
// constant defined in file.go as well, redefining here for circular dependency.
4040
const (
4141
CariddiOutputFolder = "output-cariddi"
4242
)
@@ -53,7 +53,6 @@ func PrintSimpleOutput(out []string) {
5353
func TxtOutput(flags input.Input, finalResults []string, finalSecret []scanner.SecretMatched,
5454
finalEndpoints []scanner.EndpointMatched, finalExtensions []scanner.FileTypeMatched,
5555
finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched, outputDir string) {
56-
5756
exists, err := fileUtils.ElementExists(outputDir)
5857
if err != nil {
5958
fmt.Println("Error while creating the output directory.")
@@ -126,7 +125,6 @@ func TxtOutput(flags input.Input, finalResults []string, finalSecret []scanner.S
126125
func HTMLOutput(flags input.Input, resultFilename string, finalResults []string, finalSecret []scanner.SecretMatched,
127126
finalEndpoints []scanner.EndpointMatched, finalExtensions []scanner.FileTypeMatched,
128127
finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched, outputDir string) {
129-
130128
exists, err := fileUtils.ElementExists(outputDir)
131129

132130
if err != nil {

0 commit comments

Comments
 (0)