Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/utils/http_probe_test.go
2843 views
1
package utils
2
3
import (
4
"testing"
5
6
"github.com/stretchr/testify/require"
7
)
8
9
func TestDetermineSchemeOrder(t *testing.T) {
10
type testCase struct {
11
input string
12
expected []string
13
}
14
15
tests := []testCase{
16
// No port or uncommon ports should return https first
17
{"example.com", []string{"https", "http"}},
18
{"example.com:443", []string{"https", "http"}},
19
{"127.0.0.1", []string{"https", "http"}},
20
{"[fe80::1]:443", []string{"https", "http"}},
21
// Common HTTP ports should return http first
22
{"example.com:80", []string{"http", "https"}},
23
{"example.com:8080", []string{"http", "https"}},
24
{"127.0.0.1:80", []string{"http", "https"}},
25
{"127.0.0.1:8080", []string{"http", "https"}},
26
{"fe80::1", []string{"https", "http"}},
27
{"[fe80::1]:80", []string{"http", "https"}},
28
{"[fe80::1]:8080", []string{"http", "https"}},
29
}
30
31
for _, tc := range tests {
32
t.Run(tc.input, func(t *testing.T) {
33
actual := determineSchemeOrder(tc.input)
34
require.Equal(t, tc.expected, actual)
35
})
36
}
37
}
38
39
func TestDetermineSchemeOrderWithHighPorts(t *testing.T) {
40
type testCase struct {
41
input string
42
expected []string
43
}
44
45
tests := []testCase{
46
// Ports > 1024 should return http first
47
{"example.com:2048", []string{"http", "https"}},
48
{"example.com:8081", []string{"http", "https"}},
49
{"[fe80::1]:2048", []string{"http", "https"}},
50
{"[fe80::1]:12345", []string{"http", "https"}},
51
}
52
53
for _, tc := range tests {
54
t.Run(tc.input, func(t *testing.T) {
55
actual := determineSchemeOrder(tc.input)
56
require.Equal(t, tc.expected, actual)
57
})
58
}
59
}
60
61