diff --git a/api/api_endpoints_test.go b/api/api_endpoints_test.go index f49d8bf5..52bb310a 100644 --- a/api/api_endpoints_test.go +++ b/api/api_endpoints_test.go @@ -7,7 +7,7 @@ import ( . "github.com/0xERR0R/blocky/helpertest" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/go-chi/chi/v5" diff --git a/api/api_suite_test.go b/api/api_suite_test.go index e9ea295c..c3e3b2d0 100644 --- a/api/api_suite_test.go +++ b/api/api_suite_test.go @@ -4,7 +4,7 @@ import ( "testing" . "github.com/0xERR0R/blocky/log" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/cache/expirationcache/expiration_cache_suite_test.go b/cache/expirationcache/expiration_cache_suite_test.go index 515a3de7..a390046b 100644 --- a/cache/expirationcache/expiration_cache_suite_test.go +++ b/cache/expirationcache/expiration_cache_suite_test.go @@ -5,7 +5,7 @@ import ( . "github.com/0xERR0R/blocky/log" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/cache/expirationcache/expiration_cache_test.go b/cache/expirationcache/expiration_cache_test.go index 9ce20030..37071ae4 100644 --- a/cache/expirationcache/expiration_cache_test.go +++ b/cache/expirationcache/expiration_cache_test.go @@ -3,7 +3,7 @@ package expirationcache import ( "time" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/cache/stringcache/string_cache_suite_test.go b/cache/stringcache/string_cache_suite_test.go index 80c7b4ad..bc8de415 100644 --- a/cache/stringcache/string_cache_suite_test.go +++ b/cache/stringcache/string_cache_suite_test.go @@ -5,7 +5,7 @@ import ( . "github.com/0xERR0R/blocky/log" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/cache/stringcache/string_caches_test.go b/cache/stringcache/string_caches_test.go index ec6ac3cd..a4d25c67 100644 --- a/cache/stringcache/string_caches_test.go +++ b/cache/stringcache/string_caches_test.go @@ -1,7 +1,7 @@ package stringcache import ( - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/cmd/blocking_test.go b/cmd/blocking_test.go index ee655b6d..04ccaf24 100644 --- a/cmd/blocking_test.go +++ b/cmd/blocking_test.go @@ -9,7 +9,7 @@ import ( "github.com/0xERR0R/blocky/api" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/cmd/cmd_suite_test.go b/cmd/cmd_suite_test.go index af7bb3a8..a1be82d8 100644 --- a/cmd/cmd_suite_test.go +++ b/cmd/cmd_suite_test.go @@ -4,7 +4,7 @@ import ( "testing" . "github.com/0xERR0R/blocky/log" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/sirupsen/logrus/hooks/test" diff --git a/cmd/lists_test.go b/cmd/lists_test.go index e6afa9aa..57ee94a7 100644 --- a/cmd/lists_test.go +++ b/cmd/lists_test.go @@ -4,7 +4,7 @@ import ( "net/http" "net/http/httptest" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) @@ -40,7 +40,9 @@ var _ = Describe("Lists command", func() { } }) It("should end with error", func() { - _ = newRefreshCommand().Execute() + c := newRefreshCommand() + c.SetArgs(make([]string, 0)) + _ = c.Execute() Expect(fatal).Should(BeTrue()) Expect(loggerHook.LastEntry().Message).Should(ContainSubstring("NOK: 500 Internal Server Error")) }) @@ -48,7 +50,9 @@ var _ = Describe("Lists command", func() { When("Url is wrong", func() { It("should end with error", func() { apiPort = 0 - _ = newRefreshCommand().Execute() + c := newRefreshCommand() + c.SetArgs(make([]string, 0)) + _ = c.Execute() Expect(fatal).Should(BeTrue()) Expect(loggerHook.LastEntry().Message).Should(ContainSubstring("connection refused")) }) diff --git a/cmd/query_test.go b/cmd/query_test.go index 777f2428..5abaa453 100644 --- a/cmd/query_test.go +++ b/cmd/query_test.go @@ -7,7 +7,7 @@ import ( "github.com/0xERR0R/blocky/api" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/cmd/root_test.go b/cmd/root_test.go index f87035df..aac0ff21 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -3,7 +3,7 @@ package cmd import ( "github.com/0xERR0R/blocky/log" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/cmd/serve_test.go b/cmd/serve_test.go index 3c66661a..6683f3ef 100644 --- a/cmd/serve_test.go +++ b/cmd/serve_test.go @@ -5,7 +5,7 @@ import ( "github.com/0xERR0R/blocky/config" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" ) var _ = Describe("Serve command", func() { diff --git a/cmd/version_test.go b/cmd/version_test.go index f10f5c84..496cf730 100644 --- a/cmd/version_test.go +++ b/cmd/version_test.go @@ -1,7 +1,7 @@ package cmd import ( - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) @@ -9,6 +9,7 @@ var _ = Describe("Version command", func() { When("Version command is called", func() { It("should execute without error", func() { c := NewVersionCommand() + c.SetArgs(make([]string, 0)) err := c.Execute() Expect(err).Should(Succeed()) }) diff --git a/config/config_suite_test.go b/config/config_suite_test.go index 7476b6da..6727f122 100644 --- a/config/config_suite_test.go +++ b/config/config_suite_test.go @@ -4,7 +4,7 @@ import ( "testing" . "github.com/0xERR0R/blocky/log" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/config/config_test.go b/config/config_test.go index 697482c5..24a815e9 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -9,8 +9,7 @@ import ( "github.com/0xERR0R/blocky/helpertest" . "github.com/0xERR0R/blocky/log" - . "github.com/onsi/ginkgo" - . "github.com/onsi/ginkgo/extensions/table" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/go.mod b/go.mod index 05096cec..6bf51047 100644 --- a/go.mod +++ b/go.mod @@ -5,18 +5,17 @@ go 1.17 require ( github.com/alicebob/miniredis/v2 v2.18.0 github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef - github.com/avast/retry-go/v4 v4.0.3 github.com/creasty/defaults v1.5.2 - github.com/go-chi/chi/v5 v5.0.7 github.com/go-chi/cors v1.2.0 github.com/go-redis/redis/v8 v8.11.4 github.com/google/uuid v1.3.0 github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b github.com/hashicorp/go-multierror v1.1.1 - github.com/hashicorp/golang-lru v0.5.4 + github.com/mattn/go-colorable v0.1.12 // indirect + github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect github.com/miekg/dns v1.1.46 github.com/mroth/weightedrand v0.4.1 - github.com/onsi/ginkgo v1.16.5 + github.com/onsi/ginkgo v1.16.5 // indirect github.com/onsi/gomega v1.18.1 github.com/prometheus/client_golang v1.12.1 github.com/sirupsen/logrus v1.8.1 @@ -25,10 +24,17 @@ require ( github.com/x-cray/logrus-prefixed-formatter v0.5.2 golang.org/x/net v0.0.0-20211209124913-491a49abca63 gopkg.in/yaml.v2 v2.4.0 - gorm.io/driver/mysql v1.2.3 - gorm.io/driver/postgres v1.2.3 + gorm.io/driver/mysql v1.3.2 gorm.io/driver/sqlite v1.2.6 - gorm.io/gorm v1.22.5 + gorm.io/gorm v1.23.1 +) + +require ( + github.com/avast/retry-go/v4 v4.0.3 + github.com/go-chi/chi/v5 v5.0.7 + github.com/hashicorp/golang-lru v0.5.4 + github.com/onsi/ginkgo/v2 v2.1.3 + gorm.io/driver/postgres v1.3.1 ) require ( @@ -37,7 +43,6 @@ require ( github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect - github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect @@ -48,17 +53,14 @@ require ( github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgproto3/v2 v2.2.0 // indirect github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect - github.com/jackc/pgtype v1.9.0 // indirect - github.com/jackc/pgx/v4 v4.14.0 // indirect + github.com/jackc/pgtype v1.9.1 // indirect + github.com/jackc/pgx/v4 v4.14.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.4 // indirect github.com/kr/text v0.2.0 // indirect - github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-sqlite3 v1.14.9 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect - github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect - github.com/nxadm/tail v1.4.8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect @@ -75,6 +77,5 @@ require ( golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/protobuf v1.27.1 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 9d2548e1..999605be 100644 --- a/go.sum +++ b/go.sum @@ -315,14 +315,14 @@ github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01C github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc= github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw= github.com/jackc/pgtype v1.8.1-0.20210724151600-32e20a603178/go.mod h1:C516IlIV9NKqfsMCXTdChteoXmwgUceqaLfjg2e3NlM= -github.com/jackc/pgtype v1.9.0 h1:/SH1RxEtltvJgsDqp3TbiTFApD3mey3iygpuEGeuBXk= -github.com/jackc/pgtype v1.9.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= +github.com/jackc/pgtype v1.9.1 h1:MJc2s0MFS8C3ok1wQTdQxWuXQcB6+HwAm5x1CzW7mf0= +github.com/jackc/pgtype v1.9.1/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y= github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM= github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc= github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs= -github.com/jackc/pgx/v4 v4.14.0 h1:TgdrmgnM7VY72EuSQzBbBd4JA1RLqJolrw9nQVZABVc= -github.com/jackc/pgx/v4 v4.14.0/go.mod h1:jT3ibf/A0ZVCp89rtCIN0zCJxcE74ypROmHEZYsG/j8= +github.com/jackc/pgx/v4 v4.14.1 h1:71oo1KAGI6mXhLiTMn6iDFcp3e7+zon/capWjl2OEFU= +github.com/jackc/pgx/v4 v4.14.1/go.mod h1:RgDuE4Z34o7XE92RpLsvFiOEfrAUT0Xt2KxvX73W06M= github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= @@ -330,7 +330,6 @@ github.com/jackc/puddle v1.2.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dv github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/jinzhu/now v1.1.3/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas= github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= @@ -420,8 +419,9 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108 github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.0.0 h1:CcuG/HvWNkkaqCUpJifQY8z7qEMBJya6aLPx6ftGyjQ= github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= +github.com/onsi/ginkgo/v2 v2.1.3 h1:e/3Cwtogj0HA+25nMP1jCMDIf8RtRYbGwGGuBIFztkc= +github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= @@ -1021,16 +1021,15 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/mysql v1.2.3 h1:cZqzlOfg5Kf1VIdLC1D9hT6Cy9BgxhExLj/2tIgUe7Y= -gorm.io/driver/mysql v1.2.3/go.mod h1:qsiz+XcAyMrS6QY+X3M9R6b/lKM1imKmcuK9kac5LTo= -gorm.io/driver/postgres v1.2.3 h1:f4t0TmNMy9gh3TU2PX+EppoA6YsgFnyq8Ojtddb42To= -gorm.io/driver/postgres v1.2.3/go.mod h1:pJV6RgYQPG47aM1f0QeOzFH9HxQc8JcmAgjRCgS0wjs= +gorm.io/driver/mysql v1.3.2 h1:QJryWiqQ91EvZ0jZL48NOpdlPdMjdip1hQ8bTgo4H7I= +gorm.io/driver/mysql v1.3.2/go.mod h1:ChK6AHbHgDCFZyJp0F+BmVGb06PSIoh9uVYKAlRbb2U= +gorm.io/driver/postgres v1.3.1 h1:Pyv+gg1Gq1IgsLYytj/S2k7ebII3CzEdpqQkPOdH24g= +gorm.io/driver/postgres v1.3.1/go.mod h1:WwvWOuR9unCLpGWCL6Y3JOeBWvbKi6JLhayiVclSZZU= gorm.io/driver/sqlite v1.2.6 h1:SStaH/b+280M7C8vXeZLz/zo9cLQmIGwwj3cSj7p6l4= gorm.io/driver/sqlite v1.2.6/go.mod h1:gyoX0vHiiwi0g49tv+x2E7l8ksauLK0U/gShcdUsjWY= gorm.io/gorm v1.22.3/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0= -gorm.io/gorm v1.22.4/go.mod h1:1aeVC+pe9ZmvKZban/gW4QPra7PRoTEssyc922qCAkk= -gorm.io/gorm v1.22.5 h1:lYREBgc02Be/5lSCTuysZZDb6ffL2qrat6fg9CFbvXU= -gorm.io/gorm v1.22.5/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= +gorm.io/gorm v1.23.1 h1:aj5IlhDzEPsoIyOPtTRVI+SyaN1u6k613sbt4pwbxG0= +gorm.io/gorm v1.23.1/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/lists/list_cache_test.go b/lists/list_cache_test.go index ef42b1e3..828bf6f0 100644 --- a/lists/list_cache_test.go +++ b/lists/list_cache_test.go @@ -10,7 +10,7 @@ import ( . "github.com/0xERR0R/blocky/evt" . "github.com/0xERR0R/blocky/helpertest" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/lists/list_suite_test.go b/lists/list_suite_test.go index 04cdbe26..9cb277b3 100644 --- a/lists/list_suite_test.go +++ b/lists/list_suite_test.go @@ -5,7 +5,7 @@ import ( . "github.com/0xERR0R/blocky/log" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/querylog/database_writer.go b/querylog/database_writer.go index c60ecbc4..eb5951b1 100644 --- a/querylog/database_writer.go +++ b/querylog/database_writer.go @@ -94,7 +94,7 @@ func (d *DatabaseWriter) periodicFlush() { } } -func (d *DatabaseWriter) Write(entry *Entry) { +func (d *DatabaseWriter) Write(entry *LogEntry) { domain := util.ExtractDomain(entry.Request.Req.Question[0]) eTLD, _ := publicsuffix.EffectiveTLDPlusOne(domain) diff --git a/querylog/database_writer_test.go b/querylog/database_writer_test.go index 18301abc..9feaffc9 100644 --- a/querylog/database_writer_test.go +++ b/querylog/database_writer_test.go @@ -11,7 +11,7 @@ import ( . "github.com/onsi/gomega" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" ) var _ = Describe("DatabaseWriter", func() { @@ -34,7 +34,7 @@ var _ = Describe("DatabaseWriter", func() { Reason: "Resolved", RType: model.ResponseTypeRESOLVED, } - writer.Write(&Entry{ + writer.Write(&LogEntry{ Request: request, Response: response, Start: time.Now(), @@ -69,7 +69,7 @@ var _ = Describe("DatabaseWriter", func() { } // one entry with now as timestamp - writer.Write(&Entry{ + writer.Write(&LogEntry{ Request: request, Response: response, Start: time.Now(), @@ -77,7 +77,7 @@ var _ = Describe("DatabaseWriter", func() { }) // one entry before 2 days -> should be deleted - writer.Write(&Entry{ + writer.Write(&LogEntry{ Request: request, Response: response, Start: time.Now().AddDate(0, 0, -2), diff --git a/querylog/file_writer.go b/querylog/file_writer.go index 7dcaf52a..ea1776b1 100644 --- a/querylog/file_writer.go +++ b/querylog/file_writer.go @@ -39,7 +39,7 @@ func NewCSVWriter(target string, perClient bool, logRetentionDays uint64) (*File }, nil } -func (d *FileWriter) Write(entry *Entry) { +func (d *FileWriter) Write(entry *LogEntry) { var clientPrefix string dateString := entry.Start.Format("2006-01-02") @@ -101,7 +101,7 @@ func (d *FileWriter) CleanUp() { } } -func createQueryLogRow(logEntry *Entry) []string { +func createQueryLogRow(logEntry *LogEntry) []string { request := logEntry.Request response := logEntry.Response diff --git a/querylog/file_writer_test.go b/querylog/file_writer_test.go index 0f2a68f3..ceead7fc 100644 --- a/querylog/file_writer_test.go +++ b/querylog/file_writer_test.go @@ -16,7 +16,7 @@ import ( "github.com/0xERR0R/blocky/model" "github.com/0xERR0R/blocky/util" "github.com/miekg/dns" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) @@ -48,7 +48,7 @@ var _ = Describe("FileWriter", func() { Expect(err).Should(Succeed()) By("entry for client 1", func() { - writer.Write(&Entry{ + writer.Write(&LogEntry{ Request: &model.Request{ ClientNames: []string{"client1"}, Req: util.NewMsgWithQuestion("google.de.", dns.TypeA), @@ -65,7 +65,7 @@ var _ = Describe("FileWriter", func() { }) By("entry for client 2", func() { - writer.Write(&Entry{ + writer.Write(&LogEntry{ Request: &model.Request{ ClientNames: []string{"client2"}, Req: util.NewMsgWithQuestion("google.de.", dns.TypeA), @@ -95,7 +95,7 @@ var _ = Describe("FileWriter", func() { Expect(err).Should(Succeed()) By("entry for client 1", func() { - writer.Write(&Entry{ + writer.Write(&LogEntry{ Request: &model.Request{ ClientNames: []string{"client1"}, Req: util.NewMsgWithQuestion("google.de.", dns.TypeA), @@ -112,7 +112,7 @@ var _ = Describe("FileWriter", func() { }) By("entry for client 2", func() { - writer.Write(&Entry{ + writer.Write(&LogEntry{ Request: &model.Request{ ClientNames: []string{"client2"}, Req: util.NewMsgWithQuestion("google.de.", dns.TypeA), @@ -146,7 +146,7 @@ var _ = Describe("FileWriter", func() { Expect(err).Should(Succeed()) By("entry today", func() { - writer.Write(&Entry{ + writer.Write(&LogEntry{ Request: &model.Request{ ClientNames: []string{"client1"}, Req: util.NewMsgWithQuestion("google.de.", dns.TypeA), @@ -162,7 +162,7 @@ var _ = Describe("FileWriter", func() { }) }) By("entry 2 days ago", func() { - writer.Write(&Entry{ + writer.Write(&LogEntry{ Request: &model.Request{ ClientNames: []string{"client1"}, Req: util.NewMsgWithQuestion("google.de.", dns.TypeA), diff --git a/querylog/logger_writer.go b/querylog/logger_writer.go index d702e063..307c024c 100644 --- a/querylog/logger_writer.go +++ b/querylog/logger_writer.go @@ -19,7 +19,7 @@ func NewLoggerWriter() *LoggerWriter { return &LoggerWriter{logger: log.PrefixedLog(loggerPrefixLoggerWriter)} } -func (d *LoggerWriter) Write(entry *Entry) { +func (d *LoggerWriter) Write(entry *LogEntry) { d.logger.WithFields( logrus.Fields{ "client_ip": entry.Request.ClientIP, diff --git a/querylog/logger_writer_test.go b/querylog/logger_writer_test.go index 0bf884fb..c00ff3e8 100644 --- a/querylog/logger_writer_test.go +++ b/querylog/logger_writer_test.go @@ -11,7 +11,7 @@ import ( . "github.com/onsi/gomega" "github.com/sirupsen/logrus" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" ) var _ = Describe("LoggerWriter", func() { @@ -34,7 +34,7 @@ var _ = Describe("LoggerWriter", func() { Reason: "Resolved", RType: model.ResponseTypeRESOLVED, } - writer.Write(&Entry{ + writer.Write(&LogEntry{ Request: request, Response: response, Start: time.Now(), diff --git a/querylog/none_writer.go b/querylog/none_writer.go index 6a634465..1c5945a1 100644 --- a/querylog/none_writer.go +++ b/querylog/none_writer.go @@ -7,7 +7,7 @@ func NewNoneWriter() *NoneWriter { return &NoneWriter{} } -func (d *NoneWriter) Write(entry *Entry) { +func (d *NoneWriter) Write(entry *LogEntry) { // Nothing to do } diff --git a/querylog/none_writer_test.go b/querylog/none_writer_test.go index aed0b2fd..3192b58b 100644 --- a/querylog/none_writer_test.go +++ b/querylog/none_writer_test.go @@ -1,7 +1,7 @@ package querylog import ( - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" ) var _ = Describe("NoneWriter", func() { diff --git a/querylog/querylog_suite_test.go b/querylog/querylog_suite_test.go index 6b0bfde9..91048583 100644 --- a/querylog/querylog_suite_test.go +++ b/querylog/querylog_suite_test.go @@ -5,7 +5,7 @@ import ( . "github.com/0xERR0R/blocky/log" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/querylog/writer.go b/querylog/writer.go index 0834f7b7..30dd8c01 100644 --- a/querylog/writer.go +++ b/querylog/writer.go @@ -6,7 +6,7 @@ import ( "github.com/0xERR0R/blocky/model" ) -type Entry struct { +type LogEntry struct { Request *model.Request Response *model.Response Start time.Time @@ -14,6 +14,6 @@ type Entry struct { } type Writer interface { - Write(entry *Entry) + Write(entry *LogEntry) CleanUp() } diff --git a/redis/redis_suite_test.go b/redis/redis_suite_test.go index ae927997..e5afad36 100644 --- a/redis/redis_suite_test.go +++ b/redis/redis_suite_test.go @@ -4,7 +4,7 @@ import ( "testing" . "github.com/0xERR0R/blocky/log" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/redis/redis_test.go b/redis/redis_test.go index e810ee39..6d3708cf 100644 --- a/redis/redis_test.go +++ b/redis/redis_test.go @@ -9,39 +9,40 @@ import ( "github.com/creasty/defaults" "github.com/google/uuid" "github.com/miekg/dns" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) +var ( + redisServer *miniredis.Miniredis + redisClient *Client + redisConfig *config.RedisConfig + err error +) + +var _ = BeforeSuite(func() { + redisServer, err = miniredis.Run() + + Expect(err).Should(Succeed()) + + var rcfg config.RedisConfig + err = defaults.Set(&rcfg) + + Expect(err).Should(Succeed()) + + rcfg.Address = redisServer.Addr() + redisConfig = &rcfg + redisClient, err = New(redisConfig) + + Expect(err).Should(Succeed()) + Expect(redisClient).ShouldNot(BeNil()) +}) + +var _ = AfterSuite(func() { + redisServer.Close() +}) + var _ = Describe("Redis client", func() { - - var ( - redisServer *miniredis.Miniredis - redisClient *Client - redisConfig *config.RedisConfig - err error - ) - - BeforeSuite(func() { - redisServer, err = miniredis.Run() - - Expect(err).Should(Succeed()) - - var rcfg config.RedisConfig - err = defaults.Set(&rcfg) - - Expect(err).Should(Succeed()) - - rcfg.Address = redisServer.Addr() - redisConfig = &rcfg - redisClient, err = New(redisConfig) - - Expect(err).Should(Succeed()) - Expect(redisClient).ShouldNot(BeNil()) - }) - AfterSuite(func() { - redisServer.Close() - }) When("created", func() { It("with no address", func() { var rcfg config.RedisConfig diff --git a/resolver/blocking_resolver_test.go b/resolver/blocking_resolver_test.go index 20709cd0..8f3eb0c6 100644 --- a/resolver/blocking_resolver_test.go +++ b/resolver/blocking_resolver_test.go @@ -16,11 +16,29 @@ import ( "time" "github.com/miekg/dns" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/stretchr/testify/mock" ) +var group1File, group2File, defaultGroupFile *os.File + +var _ = BeforeSuite(func() { + group1File = TempFile("DOMAIN1.com") + group2File = TempFile("blocked2.com") + defaultGroupFile = TempFile( + `blocked3.com +123.145.123.145 +2001:db8:85a3:08d3::370:7344 +badcnamedomain.com`) +}) + +var _ = AfterSuite(func() { + _ = group1File.Close() + _ = group2File.Close() + _ = defaultGroupFile.Close() +}) + var _ = Describe("BlockingResolver", func() { var ( sut *BlockingResolver @@ -31,27 +49,9 @@ var _ = Describe("BlockingResolver", func() { err error resp *Response - group1File, group2File, defaultGroupFile *os.File - expectedReturnCode int ) - BeforeSuite(func() { - group1File = TempFile("DOMAIN1.com") - group2File = TempFile("blocked2.com") - defaultGroupFile = TempFile( - `blocked3.com -123.145.123.145 -2001:db8:85a3:08d3::370:7344 -badcnamedomain.com`) - }) - - AfterSuite(func() { - _ = group1File.Close() - _ = group2File.Close() - _ = defaultGroupFile.Close() - }) - BeforeEach(func() { expectedReturnCode = dns.RcodeSuccess diff --git a/resolver/caching_resolver_test.go b/resolver/caching_resolver_test.go index 53acc240..5d530e2b 100644 --- a/resolver/caching_resolver_test.go +++ b/resolver/caching_resolver_test.go @@ -14,7 +14,7 @@ import ( "github.com/creasty/defaults" "github.com/miekg/dns" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/stretchr/testify/mock" ) @@ -454,7 +454,7 @@ var _ = Describe("CachingResolver", func() { MaxCachingTime: config.Duration(time.Minute * -1), } }) - It("should return 'disabled''", func() { + It("should return 'disabled'", func() { c := sut.Configuration() Expect(c).Should(HaveLen(1)) Expect(c).Should(Equal([]string{"deactivated"})) diff --git a/resolver/client_names_resolver_test.go b/resolver/client_names_resolver_test.go index 6cab9865..5ae542f9 100644 --- a/resolver/client_names_resolver_test.go +++ b/resolver/client_names_resolver_test.go @@ -11,7 +11,7 @@ import ( . "github.com/0xERR0R/blocky/model" "github.com/miekg/dns" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/stretchr/testify/mock" ) diff --git a/resolver/conditionall_upstream_resolver_test.go b/resolver/conditionall_upstream_resolver_test.go index 93fb8de3..1e8b6458 100644 --- a/resolver/conditionall_upstream_resolver_test.go +++ b/resolver/conditionall_upstream_resolver_test.go @@ -8,7 +8,7 @@ import ( "github.com/0xERR0R/blocky/util" "github.com/miekg/dns" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/sirupsen/logrus" "github.com/stretchr/testify/mock" @@ -134,7 +134,7 @@ var _ = Describe("ConditionalUpstreamResolver", func() { BeforeEach(func() { sut = NewConditionalUpstreamResolver(config.ConditionalUpstreamConfig{}) }) - It("should return 'disabled''", func() { + It("should return 'disabled'", func() { c := sut.Configuration() Expect(c).Should(HaveLen(1)) Expect(c).Should(Equal([]string{"deactivated"})) diff --git a/resolver/custom_dns_resolver_test.go b/resolver/custom_dns_resolver_test.go index db87fbf1..4cfd9e00 100644 --- a/resolver/custom_dns_resolver_test.go +++ b/resolver/custom_dns_resolver_test.go @@ -8,7 +8,7 @@ import ( . "github.com/0xERR0R/blocky/helpertest" . "github.com/0xERR0R/blocky/model" "github.com/miekg/dns" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/stretchr/testify/mock" ) @@ -148,7 +148,7 @@ var _ = Describe("CustomDNSResolver", func() { BeforeEach(func() { sut = NewCustomDNSResolver(config.CustomDNSConfig{}) }) - It("should return 'disabled''", func() { + It("should return 'disabled'", func() { c := sut.Configuration() Expect(c).Should(HaveLen(1)) Expect(c).Should(Equal([]string{"deactivated"})) diff --git a/resolver/hosts_file_resolver_test.go b/resolver/hosts_file_resolver_test.go index 7b2dc168..39aae29f 100644 --- a/resolver/hosts_file_resolver_test.go +++ b/resolver/hosts_file_resolver_test.go @@ -9,7 +9,7 @@ import ( . "github.com/0xERR0R/blocky/helpertest" . "github.com/0xERR0R/blocky/model" "github.com/miekg/dns" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/stretchr/testify/mock" ) diff --git a/resolver/ipv6_disabling_resolver_test.go b/resolver/ipv6_disabling_resolver_test.go index 386766d7..af4d2a4c 100644 --- a/resolver/ipv6_disabling_resolver_test.go +++ b/resolver/ipv6_disabling_resolver_test.go @@ -6,7 +6,7 @@ import ( . "github.com/0xERR0R/blocky/model" "github.com/miekg/dns" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/stretchr/testify/mock" ) diff --git a/resolver/metrics_resolver_test.go b/resolver/metrics_resolver_test.go index 51bc7229..03040b59 100644 --- a/resolver/metrics_resolver_test.go +++ b/resolver/metrics_resolver_test.go @@ -8,7 +8,7 @@ import ( . "github.com/0xERR0R/blocky/model" "github.com/miekg/dns" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/testutil" diff --git a/resolver/parallel_best_resolver_test.go b/resolver/parallel_best_resolver_test.go index 3f9270f7..22d8e2c0 100644 --- a/resolver/parallel_best_resolver_test.go +++ b/resolver/parallel_best_resolver_test.go @@ -10,7 +10,7 @@ import ( . "github.com/0xERR0R/blocky/model" "github.com/0xERR0R/blocky/util" "github.com/miekg/dns" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/resolver/query_logging_resolver.go b/resolver/query_logging_resolver.go index 9ee43c02..23410896 100644 --- a/resolver/query_logging_resolver.go +++ b/resolver/query_logging_resolver.go @@ -21,7 +21,7 @@ type QueryLoggingResolver struct { NextResolver target string logRetentionDays uint64 - logChan chan *querylog.Entry + logChan chan *querylog.LogEntry writer querylog.Writer logType config.QueryLogType } @@ -64,7 +64,7 @@ func NewQueryLoggingResolver(cfg config.QueryLogConfig) ChainedResolver { logType = config.QueryLogTypeConsole } - logChan := make(chan *querylog.Entry, logChanCap) + logChan := make(chan *querylog.LogEntry, logChanCap) resolver := QueryLoggingResolver{ target: cfg.Target, @@ -110,7 +110,7 @@ func (r *QueryLoggingResolver) Resolve(request *model.Request) (*model.Response, if err == nil { select { - case r.logChan <- &querylog.Entry{ + case r.logChan <- &querylog.LogEntry{ Request: request, Response: resp, Start: start, diff --git a/resolver/query_logging_resolver_test.go b/resolver/query_logging_resolver_test.go index 30dc6e82..7de92ae7 100644 --- a/resolver/query_logging_resolver_test.go +++ b/resolver/query_logging_resolver_test.go @@ -18,16 +18,16 @@ import ( "github.com/0xERR0R/blocky/util" "github.com/miekg/dns" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/stretchr/testify/mock" ) type SlowMockWriter struct { - entries []*querylog.Entry + entries []*querylog.LogEntry } -func (m *SlowMockWriter) Write(entry *querylog.Entry) { +func (m *SlowMockWriter) Write(entry *querylog.LogEntry) { m.entries = append(m.entries, entry) time.Sleep(time.Millisecond) diff --git a/resolver/resolver_suite_test.go b/resolver/resolver_suite_test.go index d72c4415..7179c980 100644 --- a/resolver/resolver_suite_test.go +++ b/resolver/resolver_suite_test.go @@ -5,7 +5,7 @@ import ( . "github.com/0xERR0R/blocky/log" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/resolver/resolver_test.go b/resolver/resolver_test.go index 349214c1..12395a81 100644 --- a/resolver/resolver_test.go +++ b/resolver/resolver_test.go @@ -3,7 +3,7 @@ package resolver import ( "github.com/0xERR0R/blocky/config" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/resolver/upstream_resolver_test.go b/resolver/upstream_resolver_test.go index 38dbc9e5..f3625a41 100644 --- a/resolver/upstream_resolver_test.go +++ b/resolver/upstream_resolver_test.go @@ -11,7 +11,7 @@ import ( . "github.com/0xERR0R/blocky/model" "github.com/0xERR0R/blocky/util" "github.com/miekg/dns" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/sirupsen/logrus" ) diff --git a/server/server_suite_test.go b/server/server_suite_test.go index 5ee29202..e0bdc9d6 100644 --- a/server/server_suite_test.go +++ b/server/server_suite_test.go @@ -4,7 +4,7 @@ import ( "testing" . "github.com/0xERR0R/blocky/log" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/server/server_test.go b/server/server_test.go index 4b332ba7..1aa40d0e 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -19,116 +19,116 @@ import ( "github.com/0xERR0R/blocky/util" "github.com/creasty/defaults" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/miekg/dns" ) -var _ = Describe("Running DNS server", func() { - var ( - upstreamGoogle, upstreamFritzbox, upstreamClient config.Upstream - mockClientName string - sut *Server - err error - resp *dns.Msg - ) +var ( + upstreamGoogle, upstreamFritzbox, upstreamClient config.Upstream + mockClientName string + sut *Server + err error + resp *dns.Msg +) - BeforeSuite(func() { - upstreamGoogle = resolver.TestUDPUpstream(func(request *dns.Msg) *dns.Msg { - if request.Question[0].Name == "error." { - return nil - } - response, err := util.NewMsgWithAnswer(util.ExtractDomain(request.Question[0]), 123, dns.TypeA, "123.124.122.122") - - Expect(err).Should(Succeed()) - return response - }) - upstreamFritzbox = resolver.TestUDPUpstream(func(request *dns.Msg) *dns.Msg { - response, err := util.NewMsgWithAnswer(util.ExtractDomain(request.Question[0]), 3600, dns.TypeA, "192.168.178.2") - - Expect(err).Should(Succeed()) - return response - }) - - upstreamClient = resolver.TestUDPUpstream(func(request *dns.Msg) *dns.Msg { - response, err := util.NewMsgWithAnswer(util.ExtractDomain(request.Question[0]), 3600, dns.TypePTR, mockClientName) - - Expect(err).Should(Succeed()) - return response - }) - - // create server - sut, err = NewServer(&config.Config{ - CustomDNS: config.CustomDNSConfig{ - CustomTTL: config.Duration(time.Duration(3600) * time.Second), - Mapping: config.CustomDNSMapping{ - HostIPs: map[string][]net.IP{ - "custom.lan": {net.ParseIP("192.168.178.55")}, - "lan.home": {net.ParseIP("192.168.178.56")}, - }, - }, - }, - Conditional: config.ConditionalUpstreamConfig{ - Mapping: config.ConditionalUpstreamMapping{ - Upstreams: map[string][]config.Upstream{ - "net.cn": {upstreamClient}, - "fritz.box": {upstreamFritzbox}, - }, - }, - }, - Blocking: config.BlockingConfig{ - BlackLists: map[string][]string{ - "ads": { - "../testdata/doubleclick.net.txt", - "../testdata/www.bild.de.txt", - "../testdata/heise.de.txt"}, - "youtube": {"../testdata/youtube.com.txt"}}, - WhiteLists: map[string][]string{ - "ads": {"../testdata/heise.de.txt"}, - "whitelist": {"../testdata/heise.de.txt"}, - }, - ClientGroupsBlock: map[string][]string{ - "default": {"ads"}, - "clWhitelistOnly": {"whitelist"}, - "clAdsAndYoutube": {"ads", "youtube"}, - "clYoutubeOnly": {"youtube"}, - }, - BlockType: "zeroIp", - BlockTTL: config.Duration(6 * time.Hour), - }, - Upstream: config.UpstreamConfig{ - ExternalResolvers: map[string][]config.Upstream{"default": {upstreamGoogle}}, - }, - ClientLookup: config.ClientLookupConfig{ - Upstream: upstreamClient, - }, - - DNSPorts: config.ListenConfig{"55555"}, - TLSPorts: config.ListenConfig{"8853"}, - CertFile: "../testdata/cert.pem", - KeyFile: "../testdata/key.pem", - HTTPPorts: config.ListenConfig{"4000"}, - HTTPSPorts: config.ListenConfig{"4443"}, - Prometheus: config.PrometheusConfig{ - Enable: true, - Path: "/metrics", - }, - }) +var _ = BeforeSuite(func() { + upstreamGoogle = resolver.TestUDPUpstream(func(request *dns.Msg) *dns.Msg { + if request.Question[0].Name == "error." { + return nil + } + response, err := util.NewMsgWithAnswer(util.ExtractDomain(request.Question[0]), 123, dns.TypeA, "123.124.122.122") Expect(err).Should(Succeed()) + return response + }) + upstreamFritzbox = resolver.TestUDPUpstream(func(request *dns.Msg) *dns.Msg { + response, err := util.NewMsgWithAnswer(util.ExtractDomain(request.Question[0]), 3600, dns.TypeA, "192.168.178.2") - // start server - go func() { - sut.Start() - }() - time.Sleep(100 * time.Millisecond) + Expect(err).Should(Succeed()) + return response }) - AfterSuite(func() { - sut.Stop() + upstreamClient = resolver.TestUDPUpstream(func(request *dns.Msg) *dns.Msg { + response, err := util.NewMsgWithAnswer(util.ExtractDomain(request.Question[0]), 3600, dns.TypePTR, mockClientName) + + Expect(err).Should(Succeed()) + return response }) + // create server + sut, err = NewServer(&config.Config{ + CustomDNS: config.CustomDNSConfig{ + CustomTTL: config.Duration(time.Duration(3600) * time.Second), + Mapping: config.CustomDNSMapping{ + HostIPs: map[string][]net.IP{ + "custom.lan": {net.ParseIP("192.168.178.55")}, + "lan.home": {net.ParseIP("192.168.178.56")}, + }, + }, + }, + Conditional: config.ConditionalUpstreamConfig{ + Mapping: config.ConditionalUpstreamMapping{ + Upstreams: map[string][]config.Upstream{ + "net.cn": {upstreamClient}, + "fritz.box": {upstreamFritzbox}, + }, + }, + }, + Blocking: config.BlockingConfig{ + BlackLists: map[string][]string{ + "ads": { + "../testdata/doubleclick.net.txt", + "../testdata/www.bild.de.txt", + "../testdata/heise.de.txt"}, + "youtube": {"../testdata/youtube.com.txt"}}, + WhiteLists: map[string][]string{ + "ads": {"../testdata/heise.de.txt"}, + "whitelist": {"../testdata/heise.de.txt"}, + }, + ClientGroupsBlock: map[string][]string{ + "default": {"ads"}, + "clWhitelistOnly": {"whitelist"}, + "clAdsAndYoutube": {"ads", "youtube"}, + "clYoutubeOnly": {"youtube"}, + }, + BlockType: "zeroIp", + BlockTTL: config.Duration(6 * time.Hour), + }, + Upstream: config.UpstreamConfig{ + ExternalResolvers: map[string][]config.Upstream{"default": {upstreamGoogle}}, + }, + ClientLookup: config.ClientLookupConfig{ + Upstream: upstreamClient, + }, + + DNSPorts: config.ListenConfig{"55555"}, + TLSPorts: config.ListenConfig{"8853"}, + CertFile: "../testdata/cert.pem", + KeyFile: "../testdata/key.pem", + HTTPPorts: config.ListenConfig{"4000"}, + HTTPSPorts: config.ListenConfig{"4443"}, + Prometheus: config.PrometheusConfig{ + Enable: true, + Path: "/metrics", + }, + }) + + Expect(err).Should(Succeed()) + + // start server + go func() { + sut.Start() + }() + time.Sleep(100 * time.Millisecond) +}) + +var _ = AfterSuite(func() { + sut.Stop() +}) + +var _ = Describe("Running DNS server", func() { Describe("performing DNS request with running server", func() { BeforeEach(func() { diff --git a/util/bootstrap_test.go b/util/bootstrap_test.go index 8aa99ca9..81021d88 100644 --- a/util/bootstrap_test.go +++ b/util/bootstrap_test.go @@ -3,7 +3,7 @@ package util import ( "github.com/0xERR0R/blocky/config" "github.com/0xERR0R/blocky/helpertest" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "golang.org/x/net/context" ) diff --git a/util/common_test.go b/util/common_test.go index eb05a85f..1356a0a9 100644 --- a/util/common_test.go +++ b/util/common_test.go @@ -11,7 +11,7 @@ import ( "github.com/sirupsen/logrus/hooks/test" . "github.com/0xERR0R/blocky/log" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) diff --git a/util/util_suite_test.go b/util/util_suite_test.go index e47dc46f..5a3f2dcf 100644 --- a/util/util_suite_test.go +++ b/util/util_suite_test.go @@ -4,7 +4,7 @@ import ( "testing" . "github.com/0xERR0R/blocky/log" - . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" )