forked from projectdiscovery/cdncheck
-
Notifications
You must be signed in to change notification settings - Fork 3
/
other_test.go
73 lines (56 loc) · 2.59 KB
/
other_test.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
package cdncheck
import (
"testing"
"github.com/projectdiscovery/retryabledns"
"github.com/stretchr/testify/require"
)
func TestCheckSuffix(t *testing.T) {
client := New()
valid, provider, _, err := client.CheckSuffix("test.cloudfront.net")
require.Nil(t, err, "could not check cname")
require.True(t, valid, "could not get valid cname")
require.Equal(t, "amazon", provider, "could not get correct provider")
valid, _, _, err = client.CheckSuffix("test.provider.net")
require.Nil(t, err, "could not check cname")
require.False(t, valid, "could get valid cname")
}
func TestCheckWappalyzer(t *testing.T) {
client := New()
valid, provider, err := client.CheckWappalyzer(map[string]struct{}{"imperva": {}})
require.Nil(t, err, "could not check wappalyzer")
require.True(t, valid, "could not get valid cname")
require.Equal(t, "imperva", provider, "could not get correct provider")
valid, provider, err = client.CheckWappalyzer(map[string]struct{}{"imperva:4.5.6": {}})
require.Nil(t, err, "could not check wappalyzer")
require.True(t, valid, "could not get valid cname")
require.Equal(t, "imperva", provider, "could not get correct provider")
valid, _, err = client.CheckWappalyzer(map[string]struct{}{"php": {}})
require.Nil(t, err, "could not check cname")
require.False(t, valid, "could get valid cname")
}
func TestCheckDomainWithFallback(t *testing.T) {
client := New()
valid, provider, itemType, err := client.CheckDomainWithFallback("www.gap.com")
require.Nil(t, err, "could not check")
require.True(t, valid, "could not check domain")
require.Equal(t, "akamai", provider, "could not get correct provider")
require.Equal(t, "waf", itemType, "could not get correct itemType")
}
func TestCheckDNSResponse(t *testing.T) {
client := New()
defaultResolvers := []string{"8.8.8.8", "8.8.0.0"}
defaultMaxRetries := 3
retryabledns, _ := retryabledns.New(defaultResolvers, defaultMaxRetries)
dnsData, _ := retryabledns.Resolve("hackerone.com")
valid, provider, itemType, err := client.CheckDNSResponse(dnsData)
require.Nil(t, err, "could not check cname")
require.True(t, valid, "could not get valid cname")
require.Equal(t, "cloudflare", provider, "could not get correct provider")
require.Equal(t, "waf", itemType, "could not get correct itemType")
dnsData, _ = retryabledns.CNAME("www.gap.com")
valid, provider, itemType, err = client.CheckDNSResponse(dnsData)
require.Nil(t, err, "could not check")
require.True(t, valid, "could not check domain")
require.Equal(t, "akamai", provider, "could not get correct provider")
require.Equal(t, "waf", itemType, "could not get correct itemType")
}