Skip to content

Commit a6951c9

Browse files
authored
Merge pull request #213 Better explain whitelist config
2 parents 0d57fd7 + 0077a63 commit a6951c9

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

Diff for: cmd/static/default-config.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ IPWhiteList = ""
161161
BlackList = ""
162162

163163
# Regexp in golang syntax of whitelist domains for issue certificate.
164-
# Whitelist need for allow part of domains, which excluded by blacklist.
165-
#
164+
# # Whitelist need only for allow part of domains, which excluded by blacklist.
165+
# If you want work by whitelist domains only - you have to add BlackList rule: ".*" (deny all)
166+
# Then allow what you want.
166167
WhiteList = ""
167168

168169
# Comma separated dns server, used for resolve ip:port address of domains while check it.

Diff for: internal/domain_checker/config_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/gojuno/minimock/v3"
1111

1212
"github.com/maxatome/go-testdeep"
13+
1314
"github.com/rekby/lets-proxy2/internal/th"
1415
)
1516

@@ -93,6 +94,35 @@ func TestConfig_CreateDomainCheckerWhiteListOnly(t *testing.T) {
9394
td.CmpNoError(err)
9495
}
9596

97+
func TestConfig_CreateDomainCheckerBlackAndWhiteLists(t *testing.T) {
98+
ctx, cancel := th.TestContext(t)
99+
defer cancel()
100+
101+
td := testdeep.NewT(t)
102+
cfg := Config{
103+
BlackList: `.*\.com$`,
104+
WhiteList: `^(www\.)?test\.com$`,
105+
}
106+
checker, err := cfg.CreateDomainChecker(ctx)
107+
td.CmpNoError(err)
108+
109+
res, err := checker.IsDomainAllowed(ctx, "denied.com")
110+
td.False(res)
111+
td.CmpNoError(err)
112+
113+
res, err = checker.IsDomainAllowed(ctx, "test.com")
114+
td.True(res)
115+
td.CmpNoError(err)
116+
117+
res, err = checker.IsDomainAllowed(ctx, "www.test.com")
118+
td.True(res)
119+
td.CmpNoError(err)
120+
121+
res, err = checker.IsDomainAllowed(ctx, "bad.test.com")
122+
td.False(res)
123+
td.CmpNoError(err)
124+
}
125+
96126
func TestConfig_CreateDomainCheckerSelfIPOnly(t *testing.T) {
97127
ctx, cancel := th.TestContext(t)
98128
defer cancel()

0 commit comments

Comments
 (0)