-
-
Notifications
You must be signed in to change notification settings - Fork 199
/
blocking_test.go
117 lines (101 loc) · 3.26 KB
/
blocking_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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
package e2e
import (
. "github.com/0xERR0R/blocky/helpertest"
"github.com/0xERR0R/blocky/util"
"github.com/miekg/dns"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/testcontainers/testcontainers-go"
)
var _ = Describe("External lists and query blocking", func() {
var blocky, httpServer, moka testcontainers.Container
var err error
BeforeEach(func() {
moka, err = createDNSMokkaContainer("moka", `A google/NOERROR("A 1.2.3.4 123")`)
Expect(err).Should(Succeed())
DeferCleanup(moka.Terminate)
})
Describe("List download on startup", func() {
When("external blacklist ist not available", func() {
Context("startStrategy = blocking", func() {
BeforeEach(func() {
blocky, err = createBlockyContainer(tmpDir,
"logLevel: warn",
"upstream:",
" default:",
" - moka",
"blocking:",
" startStrategy: blocking",
" blackLists:",
" ads:",
" - http://wrong.domain.url/list.txt",
" clientGroupsBlock:",
" default:",
" - ads",
)
Expect(err).Should(Succeed())
DeferCleanup(blocky.Terminate)
})
It("should start with warning in log work without errors", func() {
msg := util.NewMsgWithQuestion("google.com.", dns.Type(dns.TypeA))
Expect(doDNSRequest(blocky, msg)).Should(BeDNSRecord("google.com.", dns.TypeA, 123, "1.2.3.4"))
Expect(getContainerLogs(blocky)).Should(ContainElement(ContainSubstring("error during file processing")))
})
})
Context("startStrategy = failOnError", func() {
BeforeEach(func() {
blocky, err = createBlockyContainer(tmpDir,
"logLevel: warn",
"upstream:",
" default:",
" - moka",
"blocking:",
" startStrategy: failOnError",
" blackLists:",
" ads:",
" - http://wrong.domain.url/list.txt",
" clientGroupsBlock:",
" default:",
" - ads",
)
Expect(err).Should(HaveOccurred())
DeferCleanup(blocky.Terminate)
})
It("should fail to start", func() {
Expect(blocky.IsRunning()).Should(BeFalse())
Expect(getContainerLogs(blocky)).
Should(ContainElement(ContainSubstring("Error: can't start server: 1 error occurred")))
})
})
})
})
Describe("Query blocking against external blacklists", func() {
When("external blacklists are defined and available", func() {
BeforeEach(func() {
httpServer, err = createHTTPServerContainer("httpserver", tmpDir, "list.txt", "blockeddomain.com")
Expect(err).Should(Succeed())
DeferCleanup(httpServer.Terminate)
blocky, err = createBlockyContainer(tmpDir,
"logLevel: warn",
"upstream:",
" default:",
" - moka",
"blocking:",
" blackLists:",
" ads:",
" - http://httpserver:8080/list.txt",
" clientGroupsBlock:",
" default:",
" - ads",
)
Expect(err).Should(Succeed())
DeferCleanup(blocky.Terminate)
})
It("should download external list on startup and block queries", func() {
msg := util.NewMsgWithQuestion("blockeddomain.com.", dns.Type(dns.TypeA))
Expect(doDNSRequest(blocky, msg)).Should(BeDNSRecord("blockeddomain.com.", dns.TypeA, 6*60*60, "0.0.0.0"))
Expect(getContainerLogs(blocky)).Should(BeEmpty())
})
})
})
})