Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
komuw committed Jun 18, 2024
1 parent 6a9ee19 commit 2b0675a
Showing 1 changed file with 42 additions and 41 deletions.
83 changes: 42 additions & 41 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TestNewMiddlewareOpts(t *testing.T) {
t.Parallel()

opt := tt.opt()
o := newMiddlewareOpts(
o, err := newMiddlewareOpts(
opt.Domain,
opt.HttpsPort,
string(opt.SecretKey),
Expand All @@ -149,70 +149,70 @@ func TestNewMiddlewareOpts(t *testing.T) {
opt.SessionCookieDuration,
opt.SessionAntiReplyFunc,
)
attest.Ok(t, err)
tt.assert(o)
})
}
}

func TestNewMiddlewareOptsPanics(t *testing.T) {
func TestNewMiddlewareOptsDomain(t *testing.T) {
t.Parallel()

tests := []struct {
name string
domain string
expectPanic bool
name string
domain string
expectErr bool
}{
// Some of them are taken from; https://github.com/golang/go/blob/go1.20.5/src/net/dnsname_test.go#L19-L34
{
name: "good domain",
domain: "localhost",
expectPanic: false,
name: "good domain",
domain: "localhost",
expectErr: false,
},
{
name: "good domain B",
domain: "foo.com",
expectPanic: false,
name: "good domain B",
domain: "foo.com",
expectErr: false,
},
{
name: "good domain C",
domain: "bar.foo.com",
expectPanic: false,
name: "good domain C",
domain: "bar.foo.com",
expectErr: false,
},
{
name: "bad domain",
domain: "a.b-.com",
expectPanic: true,
name: "bad domain",
domain: "a.b-.com",
expectErr: true,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if tt.expectPanic {
attest.Panics(t, func() {
newMiddlewareOpts(
tt.domain,
443,
tst.SecretKey(),
clientip.DirectIpStrategy,
slog.Default(),
DefaultRateShedSamplePercent,
DefaultRateLimit,
DefaultLoadShedSamplingPeriod,
DefaultLoadShedMinSampleSize,
DefaultLoadShedBreachLatency,
nil,
nil,
nil,
false,
DefaultCorsCacheDuration,
DefaultCsrfCookieDuration,
DefaultSessionCookieDuration,
DefaultSessionAntiReplyFunc,
)
})
if tt.expectErr {
_, err := newMiddlewareOpts(
tt.domain,
443,
tst.SecretKey(),
clientip.DirectIpStrategy,
slog.Default(),
DefaultRateShedSamplePercent,
DefaultRateLimit,
DefaultLoadShedSamplingPeriod,
DefaultLoadShedMinSampleSize,
DefaultLoadShedBreachLatency,
nil,
nil,
nil,
false,
DefaultCorsCacheDuration,
DefaultCsrfCookieDuration,
DefaultSessionCookieDuration,
DefaultSessionAntiReplyFunc,
)
attest.Error(t, err)
} else {
newMiddlewareOpts(
_, err := newMiddlewareOpts(
tt.domain,
443,
tst.SecretKey(),
Expand All @@ -232,6 +232,7 @@ func TestNewMiddlewareOptsPanics(t *testing.T) {
DefaultSessionCookieDuration,
DefaultSessionAntiReplyFunc,
)
attest.Ok(t, err)
}
})
}
Expand Down

0 comments on commit 2b0675a

Please sign in to comment.