Skip to content

Commit

Permalink
Merge pull request #213 Better explain whitelist config
Browse files Browse the repository at this point in the history
  • Loading branch information
rekby committed Mar 6, 2024
2 parents 0d57fd7 + 0077a63 commit a6951c9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/static/default-config.toml
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
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

0 comments on commit a6951c9

Please sign in to comment.