2023-03-12 22:14:10 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/creasty/defaults"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("QueryLogConfig", func() {
|
2023-12-20 21:38:33 +01:00
|
|
|
var cfg QueryLog
|
2023-03-12 22:14:10 +01:00
|
|
|
|
|
|
|
suiteBeforeEach()
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
2023-12-20 21:38:33 +01:00
|
|
|
cfg = QueryLog{
|
2023-03-12 22:14:10 +01:00
|
|
|
Target: "/dev/null",
|
|
|
|
Type: QueryLogTypeCsvClient,
|
|
|
|
LogRetentionDays: 0,
|
|
|
|
CreationAttempts: 1,
|
|
|
|
CreationCooldown: Duration(time.Millisecond),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("IsEnabled", func() {
|
|
|
|
It("should be true by default", func() {
|
2023-12-20 21:38:33 +01:00
|
|
|
cfg := QueryLog{}
|
2023-03-12 22:14:10 +01:00
|
|
|
Expect(defaults.Set(&cfg)).Should(Succeed())
|
|
|
|
|
|
|
|
Expect(cfg.IsEnabled()).Should(BeTrue())
|
|
|
|
})
|
|
|
|
|
|
|
|
When("enabled", func() {
|
|
|
|
It("should be true", func() {
|
|
|
|
Expect(cfg.IsEnabled()).Should(BeTrue())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
When("disabled", func() {
|
|
|
|
It("should be false", func() {
|
2023-12-20 21:38:33 +01:00
|
|
|
cfg := QueryLog{
|
2023-03-12 22:14:10 +01:00
|
|
|
Type: QueryLogTypeNone,
|
|
|
|
}
|
|
|
|
|
|
|
|
Expect(cfg.IsEnabled()).Should(BeFalse())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("LogConfig", func() {
|
|
|
|
It("should log configuration", func() {
|
|
|
|
cfg.LogConfig(logger)
|
|
|
|
|
|
|
|
Expect(hook.Calls).ShouldNot(BeEmpty())
|
|
|
|
Expect(hook.Messages).Should(ContainElement(ContainSubstring("logRetentionDays:")))
|
2024-04-05 00:31:37 +02:00
|
|
|
Expect(hook.Messages).Should(ContainElement(ContainSubstring("sudn:")))
|
2023-03-12 22:14:10 +01:00
|
|
|
})
|
2024-04-02 03:35:36 +02:00
|
|
|
|
2024-04-02 17:32:56 +02:00
|
|
|
DescribeTable("secret censoring", func(target string) {
|
2024-04-02 03:35:36 +02:00
|
|
|
cfg.Type = QueryLogTypeMysql
|
|
|
|
cfg.Target = target
|
|
|
|
|
|
|
|
cfg.LogConfig(logger)
|
|
|
|
|
|
|
|
Expect(hook.Calls).ShouldNot(BeEmpty())
|
|
|
|
Expect(hook.Messages).ShouldNot(ContainElement(ContainSubstring("password")))
|
|
|
|
},
|
|
|
|
Entry("without scheme", "user:password@localhost"),
|
|
|
|
Entry("with scheme", "scheme://user:password@localhost"),
|
|
|
|
Entry("no password", "localhost"),
|
|
|
|
Entry("not a URL", "invalid!://"),
|
|
|
|
)
|
2023-03-12 22:14:10 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
Describe("SetDefaults", func() {
|
|
|
|
It("should log configuration", func() {
|
2023-12-20 21:38:33 +01:00
|
|
|
cfg := QueryLog{}
|
2023-03-12 22:14:10 +01:00
|
|
|
Expect(cfg.Fields).Should(BeEmpty())
|
|
|
|
|
|
|
|
Expect(defaults.Set(&cfg)).Should(Succeed())
|
|
|
|
|
|
|
|
Expect(cfg.Fields).ShouldNot(BeEmpty())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|