Skip to content

Commit

Permalink
fix: resolve linter and test case errors in workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikeysemwal committed Aug 27, 2024
1 parent 6a6bfb4 commit 3ad8778
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions internal/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func ReadFile(inputFile string) []string {
for scanner.Scan() {
text = append(text, scanner.Text())
}

file.Close()

return text
Expand Down
1 change: 1 addition & 0 deletions pkg/crawler/colly.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func New(scan *Scan) *Results {
if scan.StoreResp {
var err error
outputPath, err = output.StoreHTTPResponse(r, scan.OutputDir)

if err != nil {
log.Println(err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/crawler/useragents.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ func GenerateRandomUserAgent() string {
source := rand.NewSource(time.Now().UnixNano())
rng := rand.New(source)

decision := rng.Intn(100)
const maxRandomValue = 100
decision := rng.Intn(maxRandomValue)

var ua string
if decision%2 == 0 {
Expand Down
14 changes: 7 additions & 7 deletions pkg/output/jsonl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestJSONOutput(t *testing.T) {
filetype: filetype,
errors: errors,
infos: infos,
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
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
outputPath: "C:\\testDir1\\testDir2",
},
{
Expand All @@ -134,7 +134,7 @@ func TestJSONOutput(t *testing.T) {
filetype: filetype,
errors: errors,
infos: infos,
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
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
outputPath: "C:\\testDir1\\testDir2",
},
{
Expand All @@ -145,7 +145,7 @@ func TestJSONOutput(t *testing.T) {
filetype: &scanner.FileType{},
errors: []scanner.ErrorMatched{},
infos: []scanner.InfoMatched{},
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
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
outputPath: "C:\\testDir1\\testDir2",
},
{
Expand All @@ -156,7 +156,7 @@ func TestJSONOutput(t *testing.T) {
filetype: &scanner.FileType{},
errors: []scanner.ErrorMatched{},
infos: []scanner.InfoMatched{},
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
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
outputPath: "C:\\testDir1\\testDir2",
},
{
Expand All @@ -167,7 +167,7 @@ func TestJSONOutput(t *testing.T) {
filetype: &scanner.FileType{},
errors: []scanner.ErrorMatched{},
infos: []scanner.InfoMatched{},
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
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
outputPath: "C:\\testDir1\\testDir2",
},
{
Expand All @@ -178,7 +178,7 @@ func TestJSONOutput(t *testing.T) {
filetype: &scanner.FileType{},
errors: errors,
infos: []scanner.InfoMatched{},
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
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
outputPath: "C:\\testDir1\\testDir2",
},
{
Expand All @@ -189,7 +189,7 @@ func TestJSONOutput(t *testing.T) {
filetype: &scanner.FileType{},
errors: []scanner.ErrorMatched{},
infos: infos,
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
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
outputPath: "C:\\testDir1\\testDir2",
},
{
Expand Down
4 changes: 1 addition & 3 deletions pkg/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/edoardottt/cariddi/pkg/scanner"
)

// constant defined in file.go as well, for circular dependency
// constant defined in file.go as well, redefining here for circular dependency.
const (
CariddiOutputFolder = "output-cariddi"
)
Expand All @@ -53,7 +53,6 @@ func PrintSimpleOutput(out []string) {
func TxtOutput(flags input.Input, finalResults []string, finalSecret []scanner.SecretMatched,
finalEndpoints []scanner.EndpointMatched, finalExtensions []scanner.FileTypeMatched,
finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched, outputDir string) {

exists, err := fileUtils.ElementExists(outputDir)
if err != nil {
fmt.Println("Error while creating the output directory.")
Expand Down Expand Up @@ -126,7 +125,6 @@ func TxtOutput(flags input.Input, finalResults []string, finalSecret []scanner.S
func HTMLOutput(flags input.Input, resultFilename string, finalResults []string, finalSecret []scanner.SecretMatched,
finalEndpoints []scanner.EndpointMatched, finalExtensions []scanner.FileTypeMatched,
finalErrors []scanner.ErrorMatched, finalInfos []scanner.InfoMatched, outputDir string) {

exists, err := fileUtils.ElementExists(outputDir)

if err != nil {
Expand Down

0 comments on commit 3ad8778

Please sign in to comment.