Debian Codegraph @

pkg/output/audit_test.go

raw symbols SCIP
1 package outputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/output`/
2
3 import (
4 "osscip-go gomod github.com/golang/go/src go1.18 os/"
5 "testingscip-go gomod github.com/golang/go/src go1.18 testing/"
6
7 "github.com/ffuf/ffuf/v2/pkg/ffufscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/"
8 )
9
10 func TestAuditLoggerscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/output`/TestAuditLogger().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
11 file, _ := osscip-go gomod github.com/golang/go/src go1.18 os/.CreateTempscip-go gomod github.com/golang/go/src go1.18 os/CreateTemp().("", "prefix")
12 filename := file.Namescip-go gomod github.com/golang/go/src go1.18 os/File#Name().()
13 file.Closescip-go gomod github.com/golang/go/src go1.18 os/File#Close().()
14 audit, err := NewAuditLoggerscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/output`/NewAuditLogger().(filename)
15
16 if err != nil {
17 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Error creating audit logger: %s", err)
18 }
19
20 if audit == nil {
21 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Audit was nil, expected non-nil")
22 }
23
24 defer audit.Closescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/output`/AuditLogger#Close().()
25
26 err = osscip-go gomod github.com/golang/go/src go1.18 os/.Chmodscip-go gomod github.com/golang/go/src go1.18 os/Chmod().(filename, 000)
27 if err != nil {
28 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Error executing Chmod: %s", err)
29 }
30
31 audit, err = NewAuditLoggerscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/output`/NewAuditLogger().(filename)
32
33 if err == nil {
34 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Error was nil, expected non-nil")
35 }
36
37 if audit != nil {
38 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Audit was non-nil, expected nil")
39 }
40
41 err = osscip-go gomod github.com/golang/go/src go1.18 os/.Chmodscip-go gomod github.com/golang/go/src go1.18 os/Chmod().(filename, 6550)
42 if err != nil {
43 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Error executing Chmod: %s", err)
44 }
45
46 err = osscip-go gomod github.com/golang/go/src go1.18 os/.Removescip-go gomod github.com/golang/go/src go1.18 os/Remove().(filename)
47 if err != nil {
48 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Error executing Remove: %s", err)
49 }
50
51 }
52
53 func TestAuditLogWritescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/output`/TestAuditLogWrite().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) {
54 expected := `{"Type":"ffuf.Config","Data":{"auditlog":"","autocalibration":false,"autocalibration_keyword":"","autocalibration_perhost":false,"autocalibration_strategies":null,"autocalibration_strings":null,"colors":false,"cmdline":"","configfile":"","postdata":"{\"quote\":\"I'll still be here tomorrow to high five you yesterday, my friend. Peace.\"}","debuglog":"","delay":{"Min":0,"Max":0,"IsRange":false,"HasDelay":false},"dirsearch_compatibility":false,"encoders":null,"extensions":null,"fmode":"","follow_redirects":false,"headers":{"Content-Type":"application/json","baz":"wibble","foo":"bar"},"ignorebody":false,"ignore_wordlist_comments":false,"inputmode":"","cmd_inputnum":0,"inputproviders":null,"inputshell":"","json":false,"matchers":null,"mmode":"","maxtime":0,"maxtime_job":0,"method":"POST","noninteractive":false,"outputdirectory":"","outputfile":"","outputformat":"","OutputSkipEmptyFile":false,"proxyurl":"","quiet":false,"rate":0,"raw":false,"recursion":false,"recursion_depth":0,"recursion_strategy":"","replayproxyurl":"","requestfile":"","requestproto":"","scraperfile":"","scrapers":"","sni":"","stop_403":false,"stop_all":false,"stop_errors":false,"threads":0,"timeout":0,"url":"http://example.com/aaaa","verbose":false,"wordlists":null,"http2":false,"client-cert":"","client-key":""}}
55 {"Type":"ffuf.Request","Data":{"Method":"POST","Host":"","Url":"http://example.com/aaaa","Headers":{"Content-Type":"application/json","baz":"wibble","foo":"bar"},"Data":"eyJxdW90ZSI6IkknbGwgc3RpbGwgYmUgaGVyZSB0b21vcnJvdyB0byBoaWdoIGZpdmUgeW91IHllc3RlcmRheSwgbXkgZnJpZW5kLiBQZWFjZS4ifQ==","Input":null,"Position":0,"Raw":"","Error":"","Timestamp":"0001-01-01T00:00:00Z"}}
56 `
57
58 headers := make(map[string]string)
59 headers["foo"] = "bar"
60 headers["baz"] = "wibble"
61 headers["Content-Type"] = "application/json"
62
63 data := "{\"quote\":\"I'll still be here tomorrow to high five you yesterday, my friend. Peace.\"}"
64
65 req := ffufscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/.Requestscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Request#{Methodscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Request#Method.: "POST", Urlscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Request#Url.: "http://example.com/aaaa", Headersscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Request#Headers.: headers, Datascip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Request#Data.: []byte(data)}
66 config := ffufscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/.Configscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Config#{Methodscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Config#Method.: "POST", Urlscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Config#Url.: "http://example.com/aaaa", Headersscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Config#Headers.: headers, Datascip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Config#Data.: data}
67
68 file, _ := osscip-go gomod github.com/golang/go/src go1.18 os/.CreateTempscip-go gomod github.com/golang/go/src go1.18 os/CreateTemp().("", "prefix")
69 filename := file.Namescip-go gomod github.com/golang/go/src go1.18 os/File#Name().()
70 file.Closescip-go gomod github.com/golang/go/src go1.18 os/File#Close().()
71 audit, err := NewAuditLoggerscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/output`/NewAuditLogger().(filename)
72
73 if err != nil {
74 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Error creating audit logger: %s", err)
75 }
76
77 if audit == nil {
78 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Audit was nil, expected non-nil")
79 }
80
81 // test attempting to log a bung object and erroring
82 type A struct{ A *A } // cyclic struct to break JSON Marshalling
83 a := A{}
84 a.A = &a
85
86 err = audit.Writescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/output`/AuditLogger#Write().(a)
87 if err == nil {
88 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Error was nil, expected non-nil")
89 }
90
91 // test writing the config and request objects
92 err = audit.Writescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/output`/AuditLogger#Write().(config)
93 if err != nil {
94 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Error was not nil, expected nil")
95 }
96
97 err = audit.Writescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/output`/AuditLogger#Write().(req)
98 if err != nil {
99 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Error was not nil, expected nil")
100 }
101
102 audit.Closescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/output`/AuditLogger#Close().()
103
104 // re-read and check the audit log
105 f, err := osscip-go gomod github.com/golang/go/src go1.18 os/.ReadFilescip-go gomod github.com/golang/go/src go1.18 os/ReadFile().(filename)
106 if err != nil {
107 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Error reading audit log: %s", err)
108 }
109
110 if string(f) != expected {
111 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Audit write did not produce the expected logfile.")
112 }
113
114 // writing to a closed audit log should fail
115 err = audit.Writescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/output`/AuditLogger#Write().(config)
116 if err == nil {
117 t.Errorfscip-go gomod github.com/golang/go/src go1.18 testing/common#Errorf().("Error was nil, expected non-nil")
118 }
119 }