Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better explain whitelist config #213

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/static/default-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ IPWhiteList = ""
BlackList = ""

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

# Comma separated dns server, used for resolve ip:port address of domains while check it.
Expand Down
30 changes: 30 additions & 0 deletions internal/domain_checker/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/gojuno/minimock/v3"

"github.com/maxatome/go-testdeep"

"github.com/rekby/lets-proxy2/internal/th"
)

Expand Down Expand Up @@ -93,6 +94,35 @@ func TestConfig_CreateDomainCheckerWhiteListOnly(t *testing.T) {
td.CmpNoError(err)
}

func TestConfig_CreateDomainCheckerBlackAndWhiteLists(t *testing.T) {
ctx, cancel := th.TestContext(t)
defer cancel()

td := testdeep.NewT(t)
cfg := Config{
BlackList: `.*\.com$`,
WhiteList: `^(www\.)?test\.com$`,
}
checker, err := cfg.CreateDomainChecker(ctx)
td.CmpNoError(err)

res, err := checker.IsDomainAllowed(ctx, "denied.com")
td.False(res)
td.CmpNoError(err)

res, err = checker.IsDomainAllowed(ctx, "test.com")
td.True(res)
td.CmpNoError(err)

res, err = checker.IsDomainAllowed(ctx, "www.test.com")
td.True(res)
td.CmpNoError(err)

res, err = checker.IsDomainAllowed(ctx, "bad.test.com")
td.False(res)
td.CmpNoError(err)
}

func TestConfig_CreateDomainCheckerSelfIPOnly(t *testing.T) {
ctx, cancel := th.TestContext(t)
defer cancel()
Expand Down
Loading