-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.go
104 lines (83 loc) · 2.04 KB
/
library.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"net/http"
"os"
"github.com/projectdiscovery/httpx/internal/testutils"
"github.com/projectdiscovery/httpx/runner"
)
var libraryTestcases = map[string]testutils.TestCase{
"sdk": &httpxLibrary{},
"sdk with stream": &httpxLibraryWithStream{},
}
type httpxLibrary struct {
}
func (h *httpxLibrary) Execute() error {
testFile := "test.txt"
err := os.WriteFile(testFile, []byte("scanme.sh"), 0644)
if err != nil {
return err
}
defer os.RemoveAll(testFile)
var got string
options := runner.Options{
Methods: http.MethodGet,
InputFile: testFile,
OnResult: func(r runner.Result) {
got = r.URL
},
}
if err := options.ValidateOptions(); err != nil {
return err
}
httpxRunner, err := runner.New(&options)
if err != nil {
return err
}
defer httpxRunner.Close()
httpxRunner.RunEnumeration()
// httpx removes default ports for simplicity Ref: https://pkg.go.dev/github.com/projectdiscovery/httpx/common/stringz#RemoveURLDefaultPort
expected := "https://scanme.sh"
if got != expected {
return errIncorrectResult(expected, got)
}
return nil
}
type httpxLibraryWithStream struct {
}
func (h *httpxLibraryWithStream) Execute() error {
testFile := "test.txt"
err := os.WriteFile(testFile, []byte("scanme.sh"), 0644)
if err != nil {
return err
}
defer os.RemoveAll(testFile)
var got string
options := runner.Options{
Methods: http.MethodGet,
InputFile: testFile,
RateLimit: 150,
Retries: 2,
Timeout: 10,
TechDetect: "true",
Stream: true,
SkipDedupe: true,
OnResult: func(r runner.Result) {
got = r.URL
},
}
if err := options.ValidateOptions(); err != nil {
return err
}
httpxRunner, err := runner.New(&options)
if err != nil {
return err
}
defer httpxRunner.Close()
httpxRunner.RunEnumeration()
// httpx removes default ports for simplicity Ref: https://pkg.go.dev/github.com/projectdiscovery/httpx/common/stringz#RemoveURLDefaultPort
expected := "https://scanme.sh"
if got != expected {
return errIncorrectResult(expected, got)
}
return nil
}