AdGuardHome/internal/home/upgrade_test.go

1568 lines
31 KiB
Go
Raw Normal View History

package home
import (
"testing"
"time"
Pull request: 4871 imp filtering Merge in DNS/adguard-home from 4871-imp-filtering to master Closes #4871. Squashed commit of the following: commit 618e7c558447703c114332708c94ef1b34362cf9 Merge: 41ff8ab7 11e4f091 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Sep 22 19:27:08 2022 +0300 Merge branch 'master' into 4871-imp-filtering commit 41ff8ab755a87170e7334dedcae00f01dcca238a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Sep 22 19:26:11 2022 +0300 filtering: imp code, log commit e4ae1d1788406ffd7ef0fcc6df896a22b0c2db37 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Sep 22 14:11:07 2022 +0300 filtering: move handlers into single func commit f7a340b4c10980f512ae935a156f02b0133a1627 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Sep 21 19:21:09 2022 +0300 all: imp code commit e064bf4d3de0283e4bda2aaf5b9822bb8a08f4a6 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 20 20:12:16 2022 +0300 all: imp name commit e7eda3905762f0821e1be1ac3cf77e0ecbedeff4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 20 17:51:23 2022 +0300 all: finally get rid of filtering commit 188550d873e625cc2951583bb3a2eaad036745f5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 20 17:36:03 2022 +0300 filtering: merge refresh commit e54ed9c7952b17e66b790c835269b28fbc26f9ca Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 20 17:16:23 2022 +0300 filtering: merge filters commit 32da31b754a319487d5f9d5e81e607d349b90180 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 20 14:48:13 2022 +0300 filtering: imp docs commit 43b0cafa7a27bb9b620c2ba50ccdddcf32cfcecc Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 20 14:38:04 2022 +0300 all: imp code commit 253a2ea6c92815d364546e34d631e406dd604644 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Sep 19 20:43:15 2022 +0300 filtering: rm important flag commit 1b87f08f946389d410f13412c7e486290d5e752d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Sep 19 17:05:40 2022 +0300 all: move filtering to the package commit daa13499f1dd4fe475c4b75769e34f1eb0915bdf Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Sep 19 15:13:55 2022 +0300 all: finish merging commit d6db75eb2e1f23528e9200ea51507eb793eefa3c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Sep 16 18:18:14 2022 +0300 all: continue merging commit 45b4c484deb7198a469aa18d719bb9dbe81e5d22 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Sep 14 15:44:22 2022 +0300 all: merge filtering types
2022-09-23 13:23:35 +03:00
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/golibs/testutil"
"github.com/AdguardTeam/golibs/timeutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TODO(a.garipov): Cover all migrations, use a testdata/ dir.
func TestUpgradeSchema1to2(t *testing.T) {
diskConf := testDiskConf(1)
2019-03-01 11:27:15 +03:00
err := upgradeSchema1to2(diskConf)
require.NoError(t, err)
require.Equal(t, diskConf["schema_version"], 2)
_, ok := diskConf["coredns"]
require.False(t, ok)
newDNSConf, ok := diskConf["dns"]
require.True(t, ok)
oldDNSConf := testDNSConf(1)
assert.Equal(t, oldDNSConf, newDNSConf)
2019-03-01 11:27:15 +03:00
oldExcludedEntries := []string{"coredns", "schema_version"}
newExcludedEntries := []string{"dns", "schema_version"}
oldDiskConf := testDiskConf(1)
assertEqualExcept(t, oldDiskConf, diskConf, oldExcludedEntries, newExcludedEntries)
}
func TestUpgradeSchema2to3(t *testing.T) {
diskConf := testDiskConf(2)
err := upgradeSchema2to3(diskConf)
require.NoError(t, err)
require.Equal(t, diskConf["schema_version"], 3)
dnsMap, ok := diskConf["dns"]
require.True(t, ok)
newDNSConf, ok := dnsMap.(yobj)
require.True(t, ok)
bootstrapDNS := newDNSConf["bootstrap_dns"]
switch v := bootstrapDNS.(type) {
case []string:
require.Len(t, v, 1)
require.Equal(t, "8.8.8.8:53", v[0])
default:
t.Fatalf("wrong type for bootstrap dns: %T", v)
}
2019-03-01 11:27:15 +03:00
excludedEntries := []string{"bootstrap_dns"}
oldDNSConf := testDNSConf(2)
assertEqualExcept(t, oldDNSConf, newDNSConf, excludedEntries, excludedEntries)
2019-03-01 11:27:15 +03:00
excludedEntries = []string{"dns", "schema_version"}
oldDiskConf := testDiskConf(2)
assertEqualExcept(t, oldDiskConf, diskConf, excludedEntries, excludedEntries)
2019-03-01 11:27:15 +03:00
}
Pull request: home: imp code Merge in DNS/adguard-home from home-imp-code to master Squashed commit of the following: commit 459297e189c55393bf0340dd51ec9608d3475e55 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed May 10 11:42:34 2023 +0300 home: imp code commit ab38e1e80fed7b24fe57d4afdc57b70608f65d73 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed May 10 11:01:23 2023 +0300 all: lint script commit 7df68b128bf32172ef2e3bf7116f4f72a97baa2b Merge: bcb482714 db52f7a3a Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed May 10 10:59:40 2023 +0300 Merge remote-tracking branch 'origin/master' into home-imp-code commit bcb482714780da882e69c261be08511ea4f36f3b Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu May 4 13:48:27 2023 +0300 all: lint script commit 1c017f27715202ec1f40881f069a96f11f9822e8 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu May 4 13:45:25 2023 +0300 all: lint script commit ee3d427a7d6ee7e377e67c5eb99eebc7fb1e6acc Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu May 4 13:44:53 2023 +0300 home: imp code commit bc50430469123415216e60e178bd8e30fc229300 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu May 4 13:12:10 2023 +0300 home: imp code commit fc07e416aeab2612e68cf0e3f933aaed95931115 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu May 4 11:42:32 2023 +0300 aghos: service precheck commit a68480fd9c4cd6f3c89210bee6917c53074f7a82 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu May 4 11:07:05 2023 +0300 home: imp code commit 61b743a340ac1564c48212452c7a9acd1808d352 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed May 3 17:17:21 2023 +0300 all: lint script commit c6fe620510c4af5b65456e90cb3424831334e004 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed May 3 17:16:37 2023 +0300 home: imp code commit 4b2fb47ea9c932054ccc72b1fd1d11793c93e39c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed May 3 16:55:44 2023 +0300 home: imp code commit 63df3e2ab58482920a074cfd5f4188e49a0f8448 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed May 3 16:25:38 2023 +0300 home: imp code commit c7f1502f976482c2891e0c64426218b549585e83 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed May 3 15:54:30 2023 +0300 home: imp code commit c64cdaf1c82495bb70d9cdcaf7be9eeee9a7c773 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed May 3 14:35:04 2023 +0300 home: imp code commit a50436e040b3a064ef51d5f936b879fe8de72d41 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed May 3 14:24:02 2023 +0300 home: imp code commit 2b66464f472df732ea27cbbe5ac5c673a13bc14b Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed May 3 14:11:53 2023 +0300 home: imp code commit 713ce2963c210887faa0a06e41e01e4ebbf96894 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed May 3 14:10:54 2023 +0300 home: imp code
2023-05-10 16:30:03 +03:00
func TestUpgradeSchema5to6(t *testing.T) {
const newSchemaVer = 6
testCases := []struct {
in yobj
want yobj
wantErr string
name string
}{{
in: yobj{
"clients": []yobj{},
},
want: yobj{
"clients": []yobj{},
"schema_version": newSchemaVer,
},
wantErr: "",
name: "no_clients",
}, {
in: yobj{
"clients": []yobj{{"ip": "127.0.0.1"}},
},
want: yobj{
"clients": []yobj{{
"ids": []string{"127.0.0.1"},
"ip": "127.0.0.1",
}},
"schema_version": newSchemaVer,
},
wantErr: "",
name: "client_ip",
}, {
in: yobj{
"clients": []yobj{{"mac": "mac"}},
},
want: yobj{
"clients": []yobj{{
"ids": []string{"mac"},
"mac": "mac",
}},
"schema_version": newSchemaVer,
},
wantErr: "",
name: "client_mac",
}, {
in: yobj{
"clients": []yobj{{"ip": "127.0.0.1", "mac": "mac"}},
},
want: yobj{
"clients": []yobj{{
"ids": []string{"127.0.0.1", "mac"},
"ip": "127.0.0.1",
"mac": "mac",
}},
"schema_version": newSchemaVer,
},
wantErr: "",
name: "client_ip_mac",
}, {
in: yobj{
"clients": []yobj{{"ip": 1, "mac": "mac"}},
},
want: yobj{
"clients": []yobj{{"ip": 1, "mac": "mac"}},
"schema_version": newSchemaVer,
},
wantErr: "client.ip is not a string: 1",
name: "inv_client_ip",
}, {
in: yobj{
"clients": []yobj{{"ip": "127.0.0.1", "mac": 1}},
},
want: yobj{
"clients": []yobj{{"ip": "127.0.0.1", "mac": 1}},
"schema_version": newSchemaVer,
},
wantErr: "client.mac is not a string: 1",
name: "inv_client_mac",
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema5to6(tc.in)
testutil.AssertErrorMsg(t, tc.wantErr, err)
assert.Equal(t, tc.want, tc.in)
})
}
}
func TestUpgradeSchema7to8(t *testing.T) {
const host = "1.2.3.4"
oldConf := yobj{
"dns": yobj{
"bind_host": host,
},
"schema_version": 7,
}
err := upgradeSchema7to8(oldConf)
require.NoError(t, err)
require.Equal(t, oldConf["schema_version"], 8)
dnsVal, ok := oldConf["dns"]
require.True(t, ok)
newDNSConf, ok := dnsVal.(yobj)
require.True(t, ok)
newBindHosts, ok := newDNSConf["bind_hosts"].(yarr)
require.True(t, ok)
require.Len(t, newBindHosts, 1)
assert.Equal(t, host, newBindHosts[0])
2019-03-01 11:27:15 +03:00
}
func TestUpgradeSchema8to9(t *testing.T) {
const tld = "foo"
t.Run("with_autohost_tld", func(t *testing.T) {
oldConf := yobj{
"dns": yobj{
"autohost_tld": tld,
},
"schema_version": 8,
}
err := upgradeSchema8to9(oldConf)
require.NoError(t, err)
require.Equal(t, oldConf["schema_version"], 9)
dnsVal, ok := oldConf["dns"]
require.True(t, ok)
newDNSConf, ok := dnsVal.(yobj)
require.True(t, ok)
localDomainName, ok := newDNSConf["local_domain_name"].(string)
require.True(t, ok)
assert.Equal(t, tld, localDomainName)
})
t.Run("without_autohost_tld", func(t *testing.T) {
oldConf := yobj{
"dns": yobj{},
"schema_version": 8,
}
err := upgradeSchema8to9(oldConf)
require.NoError(t, err)
require.Equal(t, oldConf["schema_version"], 9)
dnsVal, ok := oldConf["dns"]
require.True(t, ok)
newDNSConf, ok := dnsVal.(yobj)
require.True(t, ok)
// Should be nil in order to be set to the default value by the
// following config rewrite.
_, ok = newDNSConf["local_domain_name"]
require.False(t, ok)
})
}
// assertEqualExcept removes entries from configs and compares them.
func assertEqualExcept(t *testing.T, oldConf, newConf yobj, oldKeys, newKeys []string) {
t.Helper()
2019-03-01 11:27:15 +03:00
for _, k := range oldKeys {
delete(oldConf, k)
}
for _, k := range newKeys {
delete(newConf, k)
2019-03-01 11:27:15 +03:00
}
assert.Equal(t, oldConf, newConf)
}
func testDiskConf(schemaVersion int) (diskConf yobj) {
Pull request: 4871 imp filtering Merge in DNS/adguard-home from 4871-imp-filtering to master Closes #4871. Squashed commit of the following: commit 618e7c558447703c114332708c94ef1b34362cf9 Merge: 41ff8ab7 11e4f091 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Sep 22 19:27:08 2022 +0300 Merge branch 'master' into 4871-imp-filtering commit 41ff8ab755a87170e7334dedcae00f01dcca238a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Sep 22 19:26:11 2022 +0300 filtering: imp code, log commit e4ae1d1788406ffd7ef0fcc6df896a22b0c2db37 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Sep 22 14:11:07 2022 +0300 filtering: move handlers into single func commit f7a340b4c10980f512ae935a156f02b0133a1627 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Sep 21 19:21:09 2022 +0300 all: imp code commit e064bf4d3de0283e4bda2aaf5b9822bb8a08f4a6 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 20 20:12:16 2022 +0300 all: imp name commit e7eda3905762f0821e1be1ac3cf77e0ecbedeff4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 20 17:51:23 2022 +0300 all: finally get rid of filtering commit 188550d873e625cc2951583bb3a2eaad036745f5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 20 17:36:03 2022 +0300 filtering: merge refresh commit e54ed9c7952b17e66b790c835269b28fbc26f9ca Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 20 17:16:23 2022 +0300 filtering: merge filters commit 32da31b754a319487d5f9d5e81e607d349b90180 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 20 14:48:13 2022 +0300 filtering: imp docs commit 43b0cafa7a27bb9b620c2ba50ccdddcf32cfcecc Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 20 14:38:04 2022 +0300 all: imp code commit 253a2ea6c92815d364546e34d631e406dd604644 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Sep 19 20:43:15 2022 +0300 filtering: rm important flag commit 1b87f08f946389d410f13412c7e486290d5e752d Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Sep 19 17:05:40 2022 +0300 all: move filtering to the package commit daa13499f1dd4fe475c4b75769e34f1eb0915bdf Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Sep 19 15:13:55 2022 +0300 all: finish merging commit d6db75eb2e1f23528e9200ea51507eb793eefa3c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Sep 16 18:18:14 2022 +0300 all: continue merging commit 45b4c484deb7198a469aa18d719bb9dbe81e5d22 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Sep 14 15:44:22 2022 +0300 all: merge filtering types
2022-09-23 13:23:35 +03:00
filters := []filtering.FilterYAML{{
URL: "https://filters.adtidy.org/android/filters/111_optimized.txt",
Name: "Latvian filter",
RulesCount: 100,
}, {
URL: "https://easylist.to/easylistgermany/easylistgermany.txt",
Name: "Germany filter",
RulesCount: 200,
}}
diskConf = yobj{
"language": "en",
"filters": filters,
"user_rules": []string{},
"schema_version": schemaVersion,
"bind_host": "0.0.0.0",
"bind_port": 80,
"auth_name": "name",
"auth_pass": "pass",
}
dnsConf := testDNSConf(schemaVersion)
if schemaVersion > 1 {
diskConf["dns"] = dnsConf
} else {
diskConf["coredns"] = dnsConf
}
return diskConf
}
// testDNSConf creates a DNS config for test the way gopkg.in/yaml.v3 would
// unmarshal it. In YAML, keys aren't guaranteed to always only be strings.
func testDNSConf(schemaVersion int) (dnsConf yobj) {
dnsConf = yobj{
"port": 53,
"blocked_response_ttl": 10,
"querylog_enabled": true,
"ratelimit": 20,
"bootstrap_dns": "8.8.8.8:53",
"parental_sensitivity": 13,
"ratelimit_whitelist": []string{},
"upstream_dns": []string{"tls://1.1.1.1", "tls://1.0.0.1", "8.8.8.8"},
"filtering_enabled": true,
"refuse_any": true,
"parental_enabled": true,
"bind_host": "0.0.0.0",
"protection_enabled": true,
"safesearch_enabled": true,
"safebrowsing_enabled": true,
}
if schemaVersion > 2 {
dnsConf["bootstrap_dns"] = []string{"8.8.8.8:53"}
}
return dnsConf
}
func TestAddQUICPort(t *testing.T) {
testCases := []struct {
name string
ups string
want string
}{{
name: "simple_ip",
ups: "8.8.8.8",
want: "8.8.8.8",
}, {
name: "url_ipv4",
ups: "quic://8.8.8.8",
want: "quic://8.8.8.8:784",
}, {
name: "url_ipv4_with_port",
ups: "quic://8.8.8.8:25565",
want: "quic://8.8.8.8:25565",
}, {
name: "url_ipv6",
ups: "quic://[::1]",
want: "quic://[::1]:784",
}, {
name: "url_ipv6_invalid",
ups: "quic://::1",
want: "quic://::1",
}, {
name: "url_ipv6_with_port",
ups: "quic://[::1]:25565",
want: "quic://[::1]:25565",
}, {
name: "url_hostname",
ups: "quic://example.com",
want: "quic://example.com:784",
}, {
name: "url_hostname_with_port",
ups: "quic://example.com:25565",
want: "quic://example.com:25565",
}, {
name: "url_hostname_with_endpoint",
ups: "quic://example.com/some-endpoint",
want: "quic://example.com:784/some-endpoint",
}, {
name: "url_hostname_with_port_endpoint",
ups: "quic://example.com:25565/some-endpoint",
want: "quic://example.com:25565/some-endpoint",
}, {
name: "non-quic_proto",
ups: "tls://example.com",
want: "tls://example.com",
}, {
name: "comment",
ups: "# comment",
want: "# comment",
}, {
name: "blank",
ups: "",
want: "",
}, {
name: "with_domain_ip",
ups: "[/example.domain/]8.8.8.8",
want: "[/example.domain/]8.8.8.8",
}, {
name: "with_domain_url",
ups: "[/example.domain/]quic://example.com",
want: "[/example.domain/]quic://example.com:784",
}, {
name: "invalid_domain",
ups: "[/exmaple.domain]quic://example.com",
want: "[/exmaple.domain]quic://example.com",
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
withPort := addQUICPort(tc.ups, 784)
assert.Equal(t, tc.want, withPort)
})
}
}
func TestUpgradeSchema9to10(t *testing.T) {
const ultimateAns = 42
testCases := []struct {
ups any
want any
wantErr string
name string
}{{
ups: yarr{"quic://8.8.8.8"},
want: yarr{"quic://8.8.8.8:784"},
wantErr: "",
name: "success",
}, {
ups: ultimateAns,
want: nil,
wantErr: "unexpected type of dns.upstream_dns: int",
name: "bad_yarr_type",
}, {
ups: yarr{ultimateAns},
want: nil,
wantErr: "unexpected type of upstream field: int",
name: "bad_upstream_type",
}}
for _, tc := range testCases {
conf := yobj{
"dns": yobj{
"upstream_dns": tc.ups,
},
"schema_version": 9,
}
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema9to10(conf)
if tc.wantErr != "" {
testutil.AssertErrorMsg(t, tc.wantErr, err)
return
}
require.NoError(t, err)
require.Equal(t, conf["schema_version"], 10)
dnsVal, ok := conf["dns"]
require.True(t, ok)
newDNSConf, ok := dnsVal.(yobj)
require.True(t, ok)
fixedUps, ok := newDNSConf["upstream_dns"].(yarr)
require.True(t, ok)
assert.Equal(t, tc.want, fixedUps)
})
}
t.Run("no_dns", func(t *testing.T) {
err := upgradeSchema9to10(yobj{})
assert.NoError(t, err)
})
t.Run("bad_dns", func(t *testing.T) {
err := upgradeSchema9to10(yobj{
"dns": ultimateAns,
})
testutil.AssertErrorMsg(t, "unexpected type of dns: int", err)
})
}
func TestUpgradeSchema10to11(t *testing.T) {
check := func(t *testing.T, conf yobj) {
rlimit, _ := conf["rlimit_nofile"].(int)
err := upgradeSchema10to11(conf)
require.NoError(t, err)
require.Equal(t, conf["schema_version"], 11)
_, ok := conf["rlimit_nofile"]
assert.False(t, ok)
osVal, ok := conf["os"]
require.True(t, ok)
newOSConf, ok := osVal.(yobj)
require.True(t, ok)
_, ok = newOSConf["group"]
assert.True(t, ok)
_, ok = newOSConf["user"]
assert.True(t, ok)
rlimitVal, ok := newOSConf["rlimit_nofile"].(int)
require.True(t, ok)
assert.Equal(t, rlimit, rlimitVal)
}
const rlimit = 42
t.Run("with_rlimit", func(t *testing.T) {
conf := yobj{
"rlimit_nofile": rlimit,
"schema_version": 10,
}
check(t, conf)
})
t.Run("without_rlimit", func(t *testing.T) {
conf := yobj{
"schema_version": 10,
}
check(t, conf)
})
}
func TestUpgradeSchema11to12(t *testing.T) {
testCases := []struct {
ivl any
want any
wantErr string
name string
}{{
ivl: 1,
want: timeutil.Duration{Duration: timeutil.Day},
wantErr: "",
name: "success",
}, {
ivl: 0.25,
want: 0,
wantErr: "unexpected type of querylog_interval: float64",
name: "fail",
}}
for _, tc := range testCases {
conf := yobj{
"dns": yobj{
"querylog_interval": tc.ivl,
},
"schema_version": 11,
}
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema11to12(conf)
if tc.wantErr != "" {
require.Error(t, err)
assert.Equal(t, tc.wantErr, err.Error())
return
}
require.NoError(t, err)
require.Equal(t, conf["schema_version"], 12)
dnsVal, ok := conf["dns"]
require.True(t, ok)
var newDNSConf yobj
newDNSConf, ok = dnsVal.(yobj)
require.True(t, ok)
var newIvl timeutil.Duration
newIvl, ok = newDNSConf["querylog_interval"].(timeutil.Duration)
require.True(t, ok)
assert.Equal(t, tc.want, newIvl)
})
}
t.Run("no_dns", func(t *testing.T) {
err := upgradeSchema11to12(yobj{})
assert.NoError(t, err)
})
t.Run("bad_dns", func(t *testing.T) {
err := upgradeSchema11to12(yobj{
"dns": 0,
})
testutil.AssertErrorMsg(t, "unexpected type of dns: int", err)
})
t.Run("no_field", func(t *testing.T) {
conf := yobj{
"dns": yobj{},
}
err := upgradeSchema11to12(conf)
require.NoError(t, err)
dns, ok := conf["dns"]
require.True(t, ok)
var dnsVal yobj
dnsVal, ok = dns.(yobj)
require.True(t, ok)
var ivl any
ivl, ok = dnsVal["querylog_interval"]
require.True(t, ok)
var ivlVal timeutil.Duration
ivlVal, ok = ivl.(timeutil.Duration)
require.True(t, ok)
assert.Equal(t, 90*24*time.Hour, ivlVal.Duration)
})
}
func TestUpgradeSchema12to13(t *testing.T) {
const newSchemaVer = 13
testCases := []struct {
in yobj
want yobj
name string
}{{
in: yobj{},
want: yobj{"schema_version": newSchemaVer},
name: "no_dns",
}, {
in: yobj{"dns": yobj{}},
want: yobj{
"dns": yobj{},
"schema_version": newSchemaVer,
},
name: "no_dhcp",
}, {
in: yobj{
"dns": yobj{
"local_domain_name": "lan",
},
"dhcp": yobj{},
"schema_version": newSchemaVer - 1,
},
want: yobj{
"dns": yobj{},
"dhcp": yobj{
"local_domain_name": "lan",
},
"schema_version": newSchemaVer,
},
name: "good",
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema12to13(tc.in)
require.NoError(t, err)
assert.Equal(t, tc.want, tc.in)
})
}
}
func TestUpgradeSchema13to14(t *testing.T) {
const newSchemaVer = 14
testClient := &clientObject{
Name: "agh-client",
IDs: []string{"id1"},
UseGlobalSettings: true,
}
testCases := []struct {
in yobj
want yobj
name string
}{{
in: yobj{},
want: yobj{
"schema_version": newSchemaVer,
// The clients field will be added anyway.
"clients": yobj{
"persistent": yarr{},
"runtime_sources": &clientSourcesConfig{
WHOIS: true,
ARP: true,
RDNS: false,
DHCP: true,
HostsFile: true,
},
},
},
name: "no_clients",
}, {
in: yobj{
"clients": []*clientObject{testClient},
},
want: yobj{
"schema_version": newSchemaVer,
"clients": yobj{
"persistent": []*clientObject{testClient},
"runtime_sources": &clientSourcesConfig{
WHOIS: true,
ARP: true,
RDNS: false,
DHCP: true,
HostsFile: true,
},
},
},
name: "no_dns",
}, {
in: yobj{
"clients": []*clientObject{testClient},
"dns": yobj{
"resolve_clients": true,
},
},
want: yobj{
"schema_version": newSchemaVer,
"clients": yobj{
"persistent": []*clientObject{testClient},
"runtime_sources": &clientSourcesConfig{
WHOIS: true,
ARP: true,
RDNS: true,
DHCP: true,
HostsFile: true,
},
},
"dns": yobj{},
},
name: "good",
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema13to14(tc.in)
require.NoError(t, err)
assert.Equal(t, tc.want, tc.in)
})
}
}
Pull request 1727: 4299-querylog-ignore Merge in DNS/adguard-home from 4299-querylog-ignore to master Squashed commit of the following: commit 06f32fef860d63dc2af9aad8d4251918c5babd00 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 7 17:14:26 2023 +0300 add debug msg commit 48fc9cf90bcb5baec4b9a7949b5be00055ad0955 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 7 16:30:06 2023 +0300 add line break commit a96fe712b6e5c6a190a92b2f83ed031a85658e58 Merge: d1035219 b8d55eaf Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 7 16:12:32 2023 +0300 Merge branch 'master' into 4299-querylog-ignore commit d1035219e15e5b5639b2fc39e0b17cfc05904722 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 7 16:11:03 2023 +0300 fix docs commit caea5dcdf3e2ca8fe2d54cb1463226bb791470f8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 7 15:30:16 2023 +0300 fix issue link commit f6e3d122404e1363dd6dd7fa0221e8ce321354e9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 7 14:34:11 2023 +0300 all: add issues links commit 52f77188f1c3a93494585ca8a3ea16e373a8b5c6 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 7 13:11:58 2023 +0300 all: add log message commit a40a0c87937abb778e4e632a5403543371b6d2e0 Merge: 87fd71ba b31bab59 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 7 12:16:08 2023 +0300 Merge branch 'master' into 4299-querylog-ignore commit 87fd71ba01588f798ba944a75e6585ebdc4aa1f7 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 7 12:13:44 2023 +0300 all: add todo commit c0c2ea08d36f25003c709eb2c190a147c47c2e0c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 6 13:27:24 2023 +0300 all: add changelog commit 8d227b684794e306e314d8cb848fe354d4578607 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Feb 3 16:06:43 2023 +0300 all: querylog ignore
2023-02-07 17:50:39 +03:00
func TestUpgradeSchema14to15(t *testing.T) {
const newSchemaVer = 15
defaultWantObj := yobj{
"querylog": map[string]any{
"enabled": true,
"file_enabled": true,
"interval": "2160h",
"size_memory": 1000,
"ignored": []any{},
},
"dns": map[string]any{},
"schema_version": newSchemaVer,
}
testCases := []struct {
in yobj
want yobj
name string
}{{
in: yobj{
"dns": map[string]any{
"querylog_enabled": true,
"querylog_file_enabled": true,
"querylog_interval": "2160h",
"querylog_size_memory": 1000,
},
},
want: defaultWantObj,
name: "basic",
}, {
in: yobj{
"dns": map[string]any{},
},
want: defaultWantObj,
name: "default_values",
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema14to15(tc.in)
require.NoError(t, err)
assert.Equal(t, tc.want, tc.in)
})
}
}
Pull request 1731: 4299-stats-ignore Merge in DNS/adguard-home from 4299-stats-ignore to master Updates #1717. Updates #4299. Squashed commit of the following: commit 1d1212d088c944e995deae2fd599eccb0a075033 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 13 17:53:36 2023 +0300 fix changelog commit 5f56852c21d794bd87c13192d3857757be10f9b2 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 13 17:39:02 2023 +0300 add todo; fix data race commit 89b8b16ddf5a43ebf68174cbaf9e8a53365f8cbe Merge: e0a6bb49 ec19a85e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Feb 10 17:21:38 2023 +0300 Merge branch 'master' into 4299-stats-ignore commit e0a6bb490b651d1cf31589a7f17095fff4cb4dbb Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Feb 10 17:21:06 2023 +0300 interval under mutex commit c569c7bc237f11b23fe47c98a20a1c5cb36751cb Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Feb 10 16:19:35 2023 +0300 fix mutex commit 9374cf0c54dccc2fbfc38765b52c64e1c479137c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Feb 10 16:03:17 2023 +0300 fix typo commit 1f4fd1e7ab1b3c2f8e9c3d32ef7e4958f99abb47 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Feb 10 15:55:44 2023 +0300 add mutex commit 2148048ce9ad228381cbb51a806c9b9cc21458fd Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Feb 10 12:27:36 2023 +0300 add key check commit a19350977c463f888aea70d0dace26dff0173a65 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Feb 9 18:34:36 2023 +0300 fix changelog commit 23c3b6da162dfd513884b460c265ba4cafeb9727 Merge: 8fccc0b8 b89105e3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Feb 9 13:28:59 2023 +0300 Merge branch 'master' into 4299-stats-ignore commit 8fccc0b8ec670a37e5209d795f35c43dd64afeb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Feb 9 13:27:42 2023 +0300 add changelog commit 0416c71742795b2fb8adb0173dcd6a99d9d9c676 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Feb 8 14:31:55 2023 +0300 all: stats ignore
2023-02-13 18:15:33 +03:00
func TestUpgradeSchema15to16(t *testing.T) {
const newSchemaVer = 16
defaultWantObj := yobj{
"statistics": map[string]any{
"enabled": true,
"interval": 1,
"ignored": []any{},
},
"dns": map[string]any{},
"schema_version": newSchemaVer,
}
testCases := []struct {
in yobj
want yobj
name string
}{{
in: yobj{
"dns": map[string]any{
"statistics_interval": 1,
},
},
want: defaultWantObj,
name: "basic",
}, {
in: yobj{
"dns": map[string]any{},
},
want: defaultWantObj,
name: "default_values",
}, {
in: yobj{
"dns": map[string]any{
"statistics_interval": 0,
},
},
want: yobj{
"statistics": map[string]any{
"enabled": false,
"interval": 1,
Pull request 1731: 4299-stats-ignore Merge in DNS/adguard-home from 4299-stats-ignore to master Updates #1717. Updates #4299. Squashed commit of the following: commit 1d1212d088c944e995deae2fd599eccb0a075033 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 13 17:53:36 2023 +0300 fix changelog commit 5f56852c21d794bd87c13192d3857757be10f9b2 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 13 17:39:02 2023 +0300 add todo; fix data race commit 89b8b16ddf5a43ebf68174cbaf9e8a53365f8cbe Merge: e0a6bb49 ec19a85e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Feb 10 17:21:38 2023 +0300 Merge branch 'master' into 4299-stats-ignore commit e0a6bb490b651d1cf31589a7f17095fff4cb4dbb Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Feb 10 17:21:06 2023 +0300 interval under mutex commit c569c7bc237f11b23fe47c98a20a1c5cb36751cb Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Feb 10 16:19:35 2023 +0300 fix mutex commit 9374cf0c54dccc2fbfc38765b52c64e1c479137c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Feb 10 16:03:17 2023 +0300 fix typo commit 1f4fd1e7ab1b3c2f8e9c3d32ef7e4958f99abb47 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Feb 10 15:55:44 2023 +0300 add mutex commit 2148048ce9ad228381cbb51a806c9b9cc21458fd Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Feb 10 12:27:36 2023 +0300 add key check commit a19350977c463f888aea70d0dace26dff0173a65 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Feb 9 18:34:36 2023 +0300 fix changelog commit 23c3b6da162dfd513884b460c265ba4cafeb9727 Merge: 8fccc0b8 b89105e3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Feb 9 13:28:59 2023 +0300 Merge branch 'master' into 4299-stats-ignore commit 8fccc0b8ec670a37e5209d795f35c43dd64afeb3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Feb 9 13:27:42 2023 +0300 add changelog commit 0416c71742795b2fb8adb0173dcd6a99d9d9c676 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Feb 8 14:31:55 2023 +0300 all: stats ignore
2023-02-13 18:15:33 +03:00
"ignored": []any{},
},
"dns": map[string]any{},
"schema_version": newSchemaVer,
},
name: "stats_disabled",
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema15to16(tc.in)
require.NoError(t, err)
assert.Equal(t, tc.want, tc.in)
})
}
}
Pull request 1744: 1472-edns-custom-ip Merge in DNS/adguard-home from 1472-edns-custom-ip to master Updates #1472. Squashed commit of the following: commit 07460c3adf7747fd9ec1b4a3d04fb459dec44280 Merge: 65455430 ae653f16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 15:38:46 2023 +0300 Merge branch 'master' into 1472-edns-custom-ip commit 65455430993e4a62c49e1f45def909b0a135af3b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 15:37:17 2023 +0300 dnsforward: add todo commit e1978ad4b6051f29185ef32973d20bc70f2a6634 Merge: 6cd98f42 bb226434 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 11:32:23 2023 +0300 Merge branch 'master' into 1472-edns-custom-ip commit 6cd98f4235b1b52d443c1950f2516af3cc4fb258 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 11:31:16 2023 +0300 all: fix chlog; fix field alignment commit defdec623919c23ab446324828d08839469669e1 Merge: 1130ebd5 a772212d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 28 12:17:23 2023 +0300 Merge branch 'master' into 1472-edns-custom-ip commit 1130ebd509bf4f7ec25fbb53717576e273dbfff2 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 28 12:13:30 2023 +0300 all: add use_custom field commit ec0cdc7af0f96f761ed85516bbcae2567fd6f7d2 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 13:59:13 2023 +0300 all: fix chlog; imp code commit f8450cfcd6054f32d6ea0a5e26c551fe153a0b21 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 11:28:16 2023 +0300 dnsforward: fix fmt commit 54a344e5bb17aae7ca213ed66b85f06ef6585316 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 11:11:52 2023 +0300 all: fix chlog; add test case commit 47b5476f6621c6ea31aa496d4113445a8e8bceb4 Merge: 8724f374 304f2ba2 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Feb 22 16:33:07 2023 +0300 Merge branch 'master' into 1472-edns-custom-ip commit 8724f3745ccc29849a4001f79b055c7ebeb19106 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Feb 22 16:31:40 2023 +0300 all: fix comments commit d2b1528ba333e7669795a3fb80355ff7d90cf4f5 Merge: 7898c23a 76a513cd Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Feb 22 11:53:25 2023 +0300 Merge branch 'master' into 1472-edns-custom-ip commit 7898c23ab991bc516bcc2f41e47bed15582fd962 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Feb 22 11:52:37 2023 +0300 all: upd chlog commit 8763261dcb4187a93104955e7cb440965e2b6739 Merge: d28394b3 ff9b24ad Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 21 17:12:03 2023 +0300 Merge branch 'master' into 1472-edns-custom-ip commit d28394b3c980b10f28c6c38ce35f368edb11d314 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 21 17:11:29 2023 +0300 home: fix default value commit 1a5da3f267706baa83eebe1923ea1b0b4e79fd6c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 21 13:37:04 2023 +0300 all: add custom ip for edns
2023-03-01 16:16:16 +03:00
func TestUpgradeSchema16to17(t *testing.T) {
const newSchemaVer = 17
defaultWantObj := yobj{
"dns": map[string]any{
"edns_client_subnet": map[string]any{
"enabled": false,
"use_custom": false,
"custom_ip": "",
},
},
"schema_version": newSchemaVer,
}
testCases := []struct {
in yobj
want yobj
name string
}{{
in: yobj{
"dns": map[string]any{
"edns_client_subnet": false,
},
},
want: defaultWantObj,
name: "basic",
}, {
in: yobj{
"dns": map[string]any{},
},
want: defaultWantObj,
name: "default_values",
}, {
in: yobj{
"dns": map[string]any{
"edns_client_subnet": true,
},
},
want: yobj{
"dns": map[string]any{
"edns_client_subnet": map[string]any{
"enabled": true,
"use_custom": false,
"custom_ip": "",
},
},
"schema_version": newSchemaVer,
},
name: "is_true",
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema16to17(tc.in)
require.NoError(t, err)
assert.Equal(t, tc.want, tc.in)
})
}
}
Pull request: 1163 safesearch vol.2 Merge in DNS/adguard-home from 1163-safesearch-1-2-1 to master Squashed commit of the following: commit d3a5ebef35210019842145074e898129b42f1f2c Merge: b85264ae c6706445 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Mar 15 09:17:53 2023 +0700 Merge remote-tracking branch 'origin/master' into 1163-safesearch-1-2-1 # Conflicts: # CHANGELOG.md commit b85264aefc5f191ac6cb194b519f03ba15829a4e Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Mar 14 00:16:07 2023 +0700 home: imp code commit ac2ed7a5ce8db40628e7d4d1c8634641e5f38b0b Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Mar 13 23:02:06 2023 +0700 all: changelog commit f0fccafcb01f50c7051df53bbe9b02cab75aa71e Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Mar 13 22:42:36 2023 +0700 all: changelog commit 37df29bf6372939644fb28e3d70365496e0cb4f6 Merge: b227b277 595484e0 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Mar 13 22:38:57 2023 +0700 Merge remote-tracking branch 'origin/master' into 1163-safesearch-1-2-1 commit b227b2775b4866d69241ad87acf99700715552cb Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Mar 13 16:56:01 2023 +0700 all: imp docs commit 6fd39fc3565c3f4bc7a7113d17733c20dfe24d8d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Mar 13 16:55:03 2023 +0700 home: imp code commit 3bb3bb7c7dcf97b2a5602a7d2b6770c08b4d863d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Mar 13 12:16:53 2023 +0700 home: imp docs commit 5f573a56a9fd9942ad677fa0fae6b24228dab653 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Mar 13 11:56:47 2023 +0700 home: imp code commit 23eeb5552cf2510596b2311cc3eda53ac678ffcc Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Mar 10 10:57:33 2023 +0700 home: imp code commit 643de2fca1b5917c61fe83e1e472222404f3cd21 Merge: dada6e63 a2053526 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Mar 9 21:03:08 2023 +0700 Merge remote-tracking branch 'origin/master' into 1163-safesearch-1-2-1 commit dada6e63ca5324d30775e2da1727da891743f654 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Mar 9 17:09:03 2023 +0700 all: imp docs commit 81a180d99dd9a995440d5f4e2ebca34678e7d0c7 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Mar 9 15:12:43 2023 +0700 all: imp code commit fa84877bc777004d246d71d0a9ae0bd9ee568a91 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Mar 9 10:53:05 2023 +0700 all: imp code commit 6d7e02e745d72921a693d4f09eec7ce21c2aefd4 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Mar 9 10:40:02 2023 +0700 all: imp docs commit 0a4332997070fb8d2fb3a34d32b92f57a325ff06 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Mar 7 22:00:52 2023 +0700 safesearch: fix merge commit 145c2222ba4cf7f8909b816d83829d2217c94243 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Mar 2 11:41:48 2023 +0700 safesearch: fix merge commit 14c6a8005fe15b5d5a39f91b17c96d8670975811 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Mar 1 12:50:09 2023 +0700 all: docs commit 2a85c8831866bf1c34c423a289461fc1e32667b5 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Mar 1 12:47:00 2023 +0700 all: use safesearch package
2023-03-15 14:31:07 +03:00
func TestUpgradeSchema17to18(t *testing.T) {
const newSchemaVer = 18
defaultWantObj := yobj{
"dns": yobj{
"safe_search": yobj{
"enabled": true,
"bing": true,
"duckduckgo": true,
"google": true,
"pixabay": true,
"yandex": true,
"youtube": true,
},
},
"schema_version": newSchemaVer,
}
testCases := []struct {
in yobj
want yobj
name string
}{{
in: yobj{"dns": yobj{}},
want: defaultWantObj,
name: "default_values",
}, {
in: yobj{"dns": yobj{"safesearch_enabled": true}},
want: defaultWantObj,
name: "enabled",
}, {
in: yobj{"dns": yobj{"safesearch_enabled": false}},
want: yobj{
"dns": yobj{
"safe_search": map[string]any{
"enabled": false,
"bing": true,
"duckduckgo": true,
"google": true,
"pixabay": true,
"yandex": true,
"youtube": true,
},
},
"schema_version": newSchemaVer,
},
name: "disabled",
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema17to18(tc.in)
require.NoError(t, err)
assert.Equal(t, tc.want, tc.in)
})
}
}
func TestUpgradeSchema18to19(t *testing.T) {
const newSchemaVer = 19
defaultWantObj := yobj{
"clients": yobj{
"persistent": []yobj{{
"name": "localhost",
"safe_search": yobj{
"enabled": true,
"bing": true,
"duckduckgo": true,
"google": true,
"pixabay": true,
"yandex": true,
"youtube": true,
},
}},
},
"schema_version": newSchemaVer,
}
testCases := []struct {
in yobj
want yobj
name string
}{{
in: yobj{
"clients": yobj{},
},
want: yobj{
"clients": yobj{},
"schema_version": newSchemaVer,
},
name: "no_clients",
}, {
in: yobj{
"clients": yobj{
"persistent": []yobj{{"name": "localhost"}},
},
},
want: defaultWantObj,
name: "default_values",
}, {
in: yobj{
"clients": yobj{
"persistent": []yobj{{"name": "localhost", "safesearch_enabled": true}},
},
},
want: defaultWantObj,
name: "enabled",
}, {
in: yobj{
"clients": yobj{
"persistent": []yobj{{"name": "localhost", "safesearch_enabled": false}},
},
},
want: yobj{
"clients": yobj{"persistent": []yobj{{
"name": "localhost",
"safe_search": yobj{
"enabled": false,
"bing": true,
"duckduckgo": true,
"google": true,
"pixabay": true,
"yandex": true,
"youtube": true,
},
}}},
"schema_version": newSchemaVer,
},
name: "disabled",
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema18to19(tc.in)
require.NoError(t, err)
assert.Equal(t, tc.want, tc.in)
})
}
}
Pull request 1736: 4299-querylog-stats-api Merge in DNS/adguard-home from 4299-querylog-stats-api to master Updates #1717. Updates #4299. Squashed commit of the following: commit 5b706b7997a536bc4fd2c532fb89ca5ab3536848 Merge: 48b62b0f 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 13:53:09 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 48b62b0f1882f1ad120c6cdd90cd7dd8cb8a7738 Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com> Date: Wed Mar 22 12:25:04 2023 +0200 client: fix styles, add titles and descrs commit 97e31cff70d05b51bd0e5ea2d20e8e7a251a7e41 Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com> Date: Tue Mar 21 18:38:12 2023 +0200 client: add ignored domains for querylog commit 24d75c4376382205ae6b8f731b1cd23d517772c9 Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com> Date: Tue Mar 21 18:21:13 2023 +0200 client: add ignore domains for stats commit eefc3891d01f90af79fdac9ba8eea06d4d54a0bc Merge: 978675ea 1daabb97 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Mar 21 10:53:35 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 978675ea2c07bf248b4c8f26ebdf78cf59a12ef5 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Mar 21 10:53:11 2023 +0300 openapi: fix chlog commit 2ed33007aade115d38b0ca582206cc10678b084c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 17:49:07 2023 +0300 home: fix tests commit 6af11520c164553ee9fce8f214ea169672188d7e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 17:40:16 2023 +0300 home: fix typo commit 56acdfde5b1ee8d16b232c1293b91affbe319ad1 Merge: 319da34d 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 17:32:58 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 319da34de41ec84310b23bba2ad79c8a3a4c14ff Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 3 17:34:38 2023 +0300 querylog: fix docs commit d5a8f24d5b336e7bdbbca18069f6ede8c96bcc2c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 3 11:42:00 2023 +0300 stats: fix docs commit e0cbfc1c4078180a05835ce7587e9f45484adc81 Merge: 4743c810 012e5beb Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 18:45:17 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 4743c81038052b9e0ca29ae5f1565021d36ca1ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 18:14:16 2023 +0300 all: imp code; fix time conversion commit 34310cffd7e331d098c535590245387051674fa8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 12:34:11 2023 +0300 chlog: restore order commit cadd864a66655242948f1cb16e6d4945c0235d7e Merge: 2f3e25be bb226434 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 12:26:06 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 2f3e25bee56d2c6ddcf4aa2fc6a1dc51ed9b06e1 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 12:25:14 2023 +0300 all: fix fmt commit d54022baa6c8a3d0d3c308a9b6b1a6a9dc6ac7b6 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 28 16:16:40 2023 +0300 all: imp code; fix chlog commit df22de91f59a51194c55e7bcbe5bc3fcc60cb8e3 Merge: e1ea4797 a772212d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 17:24:09 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit e1ea4797af974c36f06683ffc6eaaae917921a43 Merge: d7db0a5a bb80a7c2 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 17:23:20 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit d7db0a5af1e1f49f6174c1c42e6d9306f2381d16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 17:12:20 2023 +0300 all: imp docs ... and 15 more commits
2023-03-23 13:46:57 +03:00
func TestUpgradeSchema19to20(t *testing.T) {
testCases := []struct {
ivl any
want any
wantErr string
name string
}{{
ivl: 1,
want: timeutil.Duration{Duration: timeutil.Day},
wantErr: "",
name: "success",
}, {
ivl: 0,
want: timeutil.Duration{Duration: timeutil.Day},
wantErr: "",
name: "success",
Pull request 1736: 4299-querylog-stats-api Merge in DNS/adguard-home from 4299-querylog-stats-api to master Updates #1717. Updates #4299. Squashed commit of the following: commit 5b706b7997a536bc4fd2c532fb89ca5ab3536848 Merge: 48b62b0f 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 13:53:09 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 48b62b0f1882f1ad120c6cdd90cd7dd8cb8a7738 Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com> Date: Wed Mar 22 12:25:04 2023 +0200 client: fix styles, add titles and descrs commit 97e31cff70d05b51bd0e5ea2d20e8e7a251a7e41 Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com> Date: Tue Mar 21 18:38:12 2023 +0200 client: add ignored domains for querylog commit 24d75c4376382205ae6b8f731b1cd23d517772c9 Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com> Date: Tue Mar 21 18:21:13 2023 +0200 client: add ignore domains for stats commit eefc3891d01f90af79fdac9ba8eea06d4d54a0bc Merge: 978675ea 1daabb97 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Mar 21 10:53:35 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 978675ea2c07bf248b4c8f26ebdf78cf59a12ef5 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Mar 21 10:53:11 2023 +0300 openapi: fix chlog commit 2ed33007aade115d38b0ca582206cc10678b084c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 17:49:07 2023 +0300 home: fix tests commit 6af11520c164553ee9fce8f214ea169672188d7e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 17:40:16 2023 +0300 home: fix typo commit 56acdfde5b1ee8d16b232c1293b91affbe319ad1 Merge: 319da34d 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 17:32:58 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 319da34de41ec84310b23bba2ad79c8a3a4c14ff Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 3 17:34:38 2023 +0300 querylog: fix docs commit d5a8f24d5b336e7bdbbca18069f6ede8c96bcc2c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 3 11:42:00 2023 +0300 stats: fix docs commit e0cbfc1c4078180a05835ce7587e9f45484adc81 Merge: 4743c810 012e5beb Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 18:45:17 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 4743c81038052b9e0ca29ae5f1565021d36ca1ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 18:14:16 2023 +0300 all: imp code; fix time conversion commit 34310cffd7e331d098c535590245387051674fa8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 12:34:11 2023 +0300 chlog: restore order commit cadd864a66655242948f1cb16e6d4945c0235d7e Merge: 2f3e25be bb226434 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 12:26:06 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 2f3e25bee56d2c6ddcf4aa2fc6a1dc51ed9b06e1 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 12:25:14 2023 +0300 all: fix fmt commit d54022baa6c8a3d0d3c308a9b6b1a6a9dc6ac7b6 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 28 16:16:40 2023 +0300 all: imp code; fix chlog commit df22de91f59a51194c55e7bcbe5bc3fcc60cb8e3 Merge: e1ea4797 a772212d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 17:24:09 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit e1ea4797af974c36f06683ffc6eaaae917921a43 Merge: d7db0a5a bb80a7c2 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 17:23:20 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit d7db0a5af1e1f49f6174c1c42e6d9306f2381d16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 17:12:20 2023 +0300 all: imp docs ... and 15 more commits
2023-03-23 13:46:57 +03:00
}, {
ivl: 0.25,
want: 0,
wantErr: "unexpected type of interval: float64",
name: "fail",
}}
for _, tc := range testCases {
conf := yobj{
"statistics": yobj{
"interval": tc.ivl,
},
"schema_version": 19,
}
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema19to20(conf)
if tc.wantErr != "" {
require.Error(t, err)
assert.Equal(t, tc.wantErr, err.Error())
return
}
require.NoError(t, err)
require.Equal(t, conf["schema_version"], 20)
statsVal, ok := conf["statistics"]
require.True(t, ok)
var stats yobj
stats, ok = statsVal.(yobj)
require.True(t, ok)
var newIvl timeutil.Duration
newIvl, ok = stats["interval"].(timeutil.Duration)
require.True(t, ok)
assert.Equal(t, tc.want, newIvl)
})
}
t.Run("no_stats", func(t *testing.T) {
err := upgradeSchema19to20(yobj{})
assert.NoError(t, err)
})
t.Run("bad_stats", func(t *testing.T) {
err := upgradeSchema19to20(yobj{
"statistics": 0,
})
testutil.AssertErrorMsg(t, "unexpected type of stats: int", err)
})
t.Run("no_field", func(t *testing.T) {
conf := yobj{
"statistics": yobj{},
}
err := upgradeSchema19to20(conf)
require.NoError(t, err)
statsVal, ok := conf["statistics"]
require.True(t, ok)
var stats yobj
stats, ok = statsVal.(yobj)
require.True(t, ok)
var ivl any
ivl, ok = stats["interval"]
require.True(t, ok)
var ivlVal timeutil.Duration
ivlVal, ok = ivl.(timeutil.Duration)
require.True(t, ok)
assert.Equal(t, 24*time.Hour, ivlVal.Duration)
})
}
Pull request 1854: 951-blocked-services-schedule Merge in DNS/adguard-home from 951-blocked-services-schedule to master Squashed commit of the following: commit 0f0770292f8aa9dc0dddc05edefacf6655f329b8 Merge: 2705fbcfb 7309a5335 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jun 14 15:00:56 2023 +0300 Merge branch 'master' into 951-blocked-services-schedule commit 2705fbcfba57392bcc0fa9b6e1f1dfdce9796963 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jun 14 14:56:01 2023 +0300 schedule: imp field alignment commit ff8fa040558e97192a5a2c91c1d5722c67d88b3d Merge: f99936f36 9fda7bfd3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 13 11:49:15 2023 +0300 Merge branch 'master' into 951-blocked-services-schedule commit f99936f36be3453b50d772ce10bfdc1ad14879c5 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Jun 9 19:14:06 2023 +0300 schedule: add tests commit 8436c2c5675d5cc22a3554ded2ce4a49eeeefc91 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jun 8 20:10:03 2023 +0300 schedule: imp code commit 850a3d93e659e0584bd449cf5af3f13b36be9e62 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jun 8 18:57:23 2023 +0300 schedule: imp tests commit d54c42b782a4a806d2f35abbea1826ba6394a64c Merge: 21dfa51ea 156c199bb Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jun 8 18:12:03 2023 +0300 Merge branch 'master' into 951-blocked-services-schedule commit 21dfa51ea7441c655ac39f2cbceeaa598d364bff Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jun 8 18:02:47 2023 +0300 all: add todo commit d0d4532c8911fb6365f6af66ceb72a70b158b77d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jun 7 18:54:44 2023 +0300 all: upd chlog commit dc1d55fa23c0ec8e7f7b7cd25d3d0cbf3e51e236 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jun 7 17:34:28 2023 +0300 all: add tests commit 601775307c2b23fa9d6cf2aa271793e8fd5f1797 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jun 7 13:20:00 2023 +0300 all: add schedule pkg commit e0bcad0193a559a89f5f5052f5a985fa730d23be Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Jun 2 13:03:04 2023 +0300 filtering: add test case commit da7a7c20c84151ff83414cb5d576a91740a1be7e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed May 31 15:31:48 2023 +0300 filtering: imp code commit 9845a11cdae25eafe39a50f8cdc408fefe1fd746 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon May 29 17:46:24 2023 +0300 filtering: add type check commit f4bcea8ad90d584ceff236ccce4f246e391e0e33 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon May 29 17:37:25 2023 +0300 all: imp code commit 9de3a0f37eb65d0db2431c27dd4d69136c1485a7 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon May 29 15:20:33 2023 +0300 filtering: imp err msg commit 1befab59cf2a12a3bc8296066ce1115dff5a8843 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon May 29 14:31:14 2023 +0300 filtering: imp tests commit 09506f924f363f1563009cec0c44ad40d08b8ddd Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri May 26 18:44:12 2023 +0300 filtering: add tests commit 36c42f523fcfe7fa6dca5f6f13e6c79f491c1ad5 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri May 26 17:57:01 2023 +0300 all: fix typos commit 69399cd3ea17691ff0848baf43ff09b18b82114c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu May 25 18:50:51 2023 +0300 all: upd chlog ... and 2 more commits
2023-06-14 15:08:57 +03:00
func TestUpgradeSchema20to21(t *testing.T) {
const newSchemaVer = 21
testCases := []struct {
in yobj
want yobj
name string
}{{
name: "nothing",
in: yobj{},
want: yobj{
"schema_version": newSchemaVer,
},
}, {
name: "no_clients",
in: yobj{
"dns": yobj{
"blocked_services": yarr{"ok"},
},
},
want: yobj{
"dns": yobj{
"blocked_services": yobj{
"ids": yarr{"ok"},
"schedule": yobj{
"time_zone": "Local",
},
},
},
"schema_version": newSchemaVer,
},
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema20to21(tc.in)
require.NoError(t, err)
assert.Equal(t, tc.want, tc.in)
})
}
}
Pull request 1883: 951-blocked-services-client-schedule Updates #951. Squashed commit of the following: commit 94e4766932940a99c5265489bccb46d0ed6cec25 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 27 17:21:41 2023 +0300 chlog: upd docs commit b4022c33860c258bf29650413f0c972b849a1758 Merge: cfa24ff01 e7e638443 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 27 16:33:20 2023 +0300 Merge branch 'master' into 951-blocked-services-client-schedule commit cfa24ff0190b2bc12736700eeff815525fbaf5fe Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 27 15:04:10 2023 +0300 chlog: imp docs commit dad27590d5eefde82758d58fc06a20c139492db8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Jun 26 17:38:08 2023 +0300 home: imp err msg commit 7d9ba98c4477000fc2e0f06c3462fe9cd0c65293 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Jun 26 16:58:00 2023 +0300 all: add tests commit 8e952fc4e3b3d433b29efe47c88d6b7806e99ff8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Jun 23 16:36:10 2023 +0300 schedule: add todo commit 723573a98d5b930334a5fa125eb12593f4a2430d Merge: 2151ab2a6 e54fc9b1e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Jun 23 11:40:03 2023 +0300 Merge branch 'master' into 951-blocked-services-client-schedule commit 2151ab2a627b9833ba6cce9621f72b29d326da75 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Jun 23 11:37:49 2023 +0300 all: add tests commit 81ab341db3e4053f09b181d8111c0da197bdac05 Merge: aa7ae41a8 66345e855 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jun 22 17:59:01 2023 +0300 Merge branch 'master' into 951-blocked-services-client-schedule commit aa7ae41a868045fe24e390b25f15551fd8821529 Merge: 304389a48 06d465b0d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jun 21 17:10:11 2023 +0300 Merge branch 'master' into 951-blocked-services-client-schedule commit 304389a487f728e8ced293ea811a4e0026a37f0d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jun 21 17:05:31 2023 +0300 home: imp err msg commit 29cfc7ae2a0bbd5ec3205eae3f6f810519787f26 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 20 20:42:59 2023 +0300 all: imp err handling commit 8543868eef6442fd30131d9567b66222999101e9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 20 18:21:50 2023 +0300 all: upd chlog commit c5b614d45e5cf25c30c52343f48139fb34c77539 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jun 20 14:37:47 2023 +0300 all: add blocked services schedule
2023-06-27 18:03:07 +03:00
func TestUpgradeSchema21to22(t *testing.T) {
const newSchemaVer = 22
testCases := []struct {
in yobj
want yobj
name string
}{{
in: yobj{
"clients": yobj{},
},
want: yobj{
"clients": yobj{},
"schema_version": newSchemaVer,
},
name: "nothing",
}, {
in: yobj{
"clients": yobj{
"persistent": []any{yobj{"name": "localhost", "blocked_services": yarr{}}},
},
},
want: yobj{
"clients": yobj{
"persistent": []any{yobj{
"name": "localhost",
"blocked_services": yobj{
"ids": yarr{},
"schedule": yobj{
"time_zone": "Local",
},
},
}},
},
"schema_version": newSchemaVer,
},
name: "no_services",
}, {
in: yobj{
"clients": yobj{
"persistent": []any{yobj{"name": "localhost", "blocked_services": yarr{"ok"}}},
},
},
want: yobj{
"clients": yobj{
"persistent": []any{yobj{
"name": "localhost",
"blocked_services": yobj{
"ids": yarr{"ok"},
"schedule": yobj{
"time_zone": "Local",
},
},
}},
},
"schema_version": newSchemaVer,
},
name: "services",
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema21to22(tc.in)
require.NoError(t, err)
assert.Equal(t, tc.want, tc.in)
})
}
}
Pull request: home: http conf Updates #2860. Squashed commit of the following: commit 0d55a99d5c0b9f1d8c9497775dd69929e5091eaa Merge: 73a203ac8 d4a4bda64 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 29 16:25:36 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 73a203ac8acf083fa289015e1f301d05bf320ea7 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 29 16:21:48 2023 +0400 home: imp docs commit a4819ace94bfe4427f70f1b8341c9babc9234740 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 29 11:45:30 2023 +0400 snap: imp script commit b0913c7ac5c6c46d6a73790fd57d8c5f9d7ace75 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 28 17:34:03 2023 +0400 all: docs commit 14820d6d56f958081d9f236277fd34f356bdab33 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 28 13:21:43 2023 +0400 home: imp tests commit 9db800d3ce39c36da7959e37b4a46736f4217e5c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 28 13:17:34 2023 +0400 all: docs commit 9174a0ae710da51d85b4e1b1af79eda6a61dd3a2 Merge: ca8c4ae95 d88181343 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 28 10:19:01 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf # Conflicts: # CHANGELOG.md # internal/home/upgrade.go # internal/home/upgrade_test.go commit ca8c4ae954ece25d78ef2f873bb3ba71fa4b8fa9 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 28 10:07:15 2023 +0400 snap: imp script commit d84473f8e07b2c6e65023613eb4032fd01951521 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 28 09:59:57 2023 +0400 snap: imp script commit 8a0808e42ddbff7d9d3345d758f91b14bb4453be Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 27 15:03:53 2023 +0400 home: http conf commit e8fbb89cc5748f9d8fa4be9e702756bd8b869de9 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 27 14:59:37 2023 +0400 home: imp code commit 46541aabc421118562d564675dfd7e594d2056aa Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 27 12:36:14 2023 +0400 snap: bind port commit cecda5fcfd8c473db42f235b4f586b2193086997 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 27 12:12:39 2023 +0400 docker: bind port commit 8d8945b70366c6b018616a32421c77eb281a6ea1 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 27 11:06:32 2023 +0400 home: imp code commit ae5e8c1c4333d7b752c08605d80e41f55ee50e59 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jun 27 11:02:09 2023 +0400 home: imp code commit c9ee460f37e32941b84ea5fa94d21b186d6dd82b Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Jun 26 17:11:10 2023 +0400 home: imp code commit 44c72445112ef38d6ec9c25b197c119edd6c959f Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Jun 26 11:52:19 2023 +0400 all: docs commit e3bf5faeb748f347b1202a496788739ff9219ed0 Merge: 38cc0f639 e7e638443 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Jun 26 11:39:12 2023 +0400 Merge remote-tracking branch 'origin/master' into http-yaml-conf commit 38cc0f6399040f1fa39d9da31ad6db65a6bdd4cc Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Jun 26 11:38:17 2023 +0400 snap: bind port commit 3b9cb9e8cc89a67e55cecc7a2040c150f8675b4c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Jun 26 11:25:03 2023 +0400 docker: bind port ... and 4 more commits
2023-06-29 15:29:52 +03:00
func TestUpgradeSchema22to23(t *testing.T) {
const newSchemaVer = 23
testCases := []struct {
in yobj
want yobj
name string
}{{
name: "empty",
in: yobj{},
want: yobj{
"schema_version": newSchemaVer,
},
}, {
name: "ok",
in: yobj{
"bind_host": "1.2.3.4",
"bind_port": 8081,
"web_session_ttl": 720,
},
want: yobj{
"http": yobj{
"address": "1.2.3.4:8081",
"session_ttl": "720h",
},
"schema_version": newSchemaVer,
},
}, {
name: "v6_address",
in: yobj{
"bind_host": "2001:db8::1",
"bind_port": 8081,
"web_session_ttl": 720,
},
want: yobj{
"http": yobj{
"address": "[2001:db8::1]:8081",
"session_ttl": "720h",
},
"schema_version": newSchemaVer,
},
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema22to23(tc.in)
require.NoError(t, err)
assert.Equal(t, tc.want, tc.in)
})
}
}
Pull request: log-yaml-conf Updates #4897. Squashed commit of the following: commit 8a961157c9930bf4859ce2209e5016ce94987e12 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jul 5 10:13:24 2023 +0400 home: imp code commit 509c07eed06311d773bc3e34b3ca28d9f14186fe Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jul 4 17:33:31 2023 +0400 all: fix commit f032e28f98552f238721491c998fca2d7d4b9802 Merge: ee0113435 c46516475 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jul 4 17:31:29 2023 +0400 Merge remote-tracking branch 'origin/master' into log-yaml-conf # Conflicts: # CHANGELOG.md commit ee011343512e82d4e21cb402759d0284523ba02a Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jul 4 12:31:42 2023 +0400 all: changelog commit 07f4c4a244b1b6200d3056cde5ebced6254084a7 Merge: 2042c0753 97af062f7 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jul 4 12:25:21 2023 +0400 Merge remote-tracking branch 'origin/master' into log-yaml-conf commit 2042c0753ec29de6045c3f1de6d075cb93d6ec27 Merge: a1d3a5130 8004b135b Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Jul 3 16:25:26 2023 +0400 Merge remote-tracking branch 'origin/master' into log-yaml-conf commit a1d3a51307e80f9e509bd6f3bee1a7b17bf1ffe6 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Jun 30 11:11:32 2023 +0400 home: imp code commit 2392a3b02620b8c38e88afb4d75988be85fe1338 Merge: 4224fbed7 39f5c50ac Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 29 16:46:47 2023 +0400 home: imp code commit 4224fbed7113e94bee44d0ab0272e8302a8086f3 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 29 16:39:35 2023 +0400 home: imp code commit 5ce708cc50bed83e64f062e599fc8b6143d0d44d Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 29 12:48:42 2023 +0400 all: docs commit 4b6d898a888818410f59b843c3ca1a685aafec82 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 29 12:20:54 2023 +0400 home: imp code commit 431b44eda71f488c747c3efa4da0a6c222b1cf06 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jun 29 12:03:17 2023 +0400 home: imp tests commit 53a5c31060018c37953beb27d80c46f92bbe14af Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 28 17:40:49 2023 +0400 home: imp docs commit bfa57d9f21e3326baafd3a52e91d54396d8e03fa Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 28 15:49:40 2023 +0400 home: log conf commit 49e06dca9dc2ceb2647b7e36dac145ccf78a6c3f Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 28 15:41:02 2023 +0400 home: log conf commit 9be432dea7cec8ae0c0d3ee1f73c58c76376d07e Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jun 28 10:45:01 2023 +0400 home: log conf
2023-07-06 10:09:04 +03:00
func TestUpgradeSchema23to24(t *testing.T) {
const newSchemaVer = 24
testCases := []struct {
in yobj
want yobj
name string
wantErrMsg string
}{{
name: "empty",
in: yobj{},
want: yobj{
"schema_version": newSchemaVer,
},
wantErrMsg: "",
}, {
name: "ok",
in: yobj{
"log_file": "/test/path.log",
"log_max_backups": 1,
"log_max_size": 2,
"log_max_age": 3,
"log_compress": true,
"log_localtime": true,
"verbose": true,
},
want: yobj{
"log": yobj{
"file": "/test/path.log",
"max_backups": 1,
"max_size": 2,
"max_age": 3,
"compress": true,
"local_time": true,
"verbose": true,
},
"schema_version": newSchemaVer,
},
wantErrMsg: "",
}, {
name: "invalid",
in: yobj{
"log_file": "/test/path.log",
"log_max_backups": 1,
"log_max_size": 2,
"log_max_age": 3,
"log_compress": "",
"log_localtime": true,
"verbose": true,
},
want: yobj{
"log_file": "/test/path.log",
"log_max_backups": 1,
"log_max_size": 2,
"log_max_age": 3,
"log_compress": "",
"log_localtime": true,
"verbose": true,
"schema_version": newSchemaVer,
},
wantErrMsg: "unexpected type of log_compress: string",
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema23to24(tc.in)
testutil.AssertErrorMsg(t, tc.wantErrMsg, err)
assert.Equal(t, tc.want, tc.in)
})
}
}
func TestUpgradeSchema24to25(t *testing.T) {
const newSchemaVer = 25
testCases := []struct {
in yobj
want yobj
name string
wantErrMsg string
}{{
name: "empty",
in: yobj{},
want: yobj{
"schema_version": newSchemaVer,
},
wantErrMsg: "",
}, {
name: "ok",
in: yobj{
"http": yobj{
"address": "0.0.0.0:3000",
"session_ttl": "720h",
},
"debug_pprof": true,
},
want: yobj{
"http": yobj{
"address": "0.0.0.0:3000",
"session_ttl": "720h",
"pprof": yobj{
"enabled": true,
"port": 6060,
},
},
"schema_version": newSchemaVer,
},
wantErrMsg: "",
}, {
name: "ok_disabled",
in: yobj{
"http": yobj{
"address": "0.0.0.0:3000",
"session_ttl": "720h",
},
"debug_pprof": false,
},
want: yobj{
"http": yobj{
"address": "0.0.0.0:3000",
"session_ttl": "720h",
"pprof": yobj{
"enabled": false,
"port": 6060,
},
},
"schema_version": newSchemaVer,
},
wantErrMsg: "",
}, {
name: "invalid",
in: yobj{
"http": yobj{
"address": "0.0.0.0:3000",
"session_ttl": "720h",
},
"debug_pprof": 1,
},
want: yobj{
"http": yobj{
"address": "0.0.0.0:3000",
"session_ttl": "720h",
},
"debug_pprof": 1,
"schema_version": newSchemaVer,
},
wantErrMsg: "unexpected type of debug_pprof: int",
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema24to25(tc.in)
testutil.AssertErrorMsg(t, tc.wantErrMsg, err)
assert.Equal(t, tc.want, tc.in)
})
}
}
Pull request 1979: AG-25263 filtering config Squashed commit of the following: commit a5607f811ab4642a0e34d3042240e3a9aafc3d84 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 30 15:44:26 2023 +0300 home: upgrade yaml commit 0593e4da17613b8770c4567fdd5fbfde31631e6f Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 30 15:01:14 2023 +0300 home: upgrade yaml commit 59ec4ba0bbe59fb2e95290f4f8101891ce4ff959 Merge: 6555941f5 a325c9b6b Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 30 14:57:41 2023 +0300 Merge remote-tracking branch 'origin/master' into AG-25263-filtering-config # Conflicts: # internal/dnsforward/http.go # internal/dnsforward/http_test.go # internal/dnsforward/process.go # internal/dnsforward/process_internal_test.go commit 6555941f57e99aa8bc2473b8be9e4f096ce665e0 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 30 14:38:01 2023 +0300 docs: changelog commit c66d14cecbb1f08869a90c46e58d08ec03e29de5 Merge: a50ff1622 aac36a2d2 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 30 12:58:41 2023 +0300 Merge remote-tracking branch 'origin/master' into AG-25263-filtering-config commit a50ff162291f7953912c1bb195bd7b5d802d0ab3 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 30 11:22:12 2023 +0300 home: imp code commit ef40d073e00d6acb164c0d680ed9971c4e75fbb7 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Aug 29 16:19:14 2023 +0300 home: imp code commit 5fa09a95e901a72dc5d2a90ba47c96842152587b Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Aug 29 14:47:48 2023 +0300 home: imp code commit 52bb295120f468faf94c953d0e795d1d58696ef1 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Aug 29 13:33:01 2023 +0300 home: imp code commit 24cfccf071385d660aeba4ced744ebbacc819686 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Aug 29 12:24:20 2023 +0300 filtering: imp code commit 758242b69ee5f351b25407340f989ec6b90d3607 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Aug 29 10:32:51 2023 +0300 home: imp code commit 906deaa3bf86af5038fb05a54c34cc9511500ac9 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Aug 28 14:46:01 2023 +0300 dnsforward: imp code commit 978bb508349cd0b6a1a0bd3df5b879b6a4dd9e29 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Aug 28 14:40:31 2023 +0300 home: imp code commit d5b8dd5c930b0ccbe612f320a9908f2849370fd4 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Aug 28 12:34:32 2023 +0300 filtering: imp code commit d3e5726df6bc93112329ec81bc83932ccf64b8de Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Aug 28 11:57:33 2023 +0300 home: upgrade yaml commit 75d701553595786d5695540c001e6d46153351a9 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Aug 28 11:46:55 2023 +0300 home: upgrade yaml commit cd8cb623b0e6eb00fd05fb62b7445ca4315b94e0 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Aug 28 11:29:16 2023 +0300 docs: changelog commit 31c098d6f8d68a4afa30246c8d067a1ef4586de9 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Aug 28 11:08:48 2023 +0300 docs: changelog commit 24c88dd5d42b0168a13ea11b3f760eae1e804558 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Sun Aug 27 19:12:55 2023 +0300 home: imp code commit 94f2d386c9c1b6be5df06525078c90a3d068641f Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Sun Aug 27 16:15:05 2023 +0300 home: upgrade yaml ... and 10 more commits
2023-08-30 18:26:02 +03:00
func TestUpgradeSchema25to26(t *testing.T) {
const newSchemaVer = 26
testCases := []struct {
in yobj
want yobj
name string
}{{
name: "empty",
in: yobj{},
want: yobj{
"schema_version": newSchemaVer,
},
}, {
name: "ok",
in: yobj{
"dns": yobj{
"filtering_enabled": true,
"filters_update_interval": 24,
"parental_enabled": false,
"safebrowsing_enabled": false,
"safebrowsing_cache_size": 1048576,
"safesearch_cache_size": 1048576,
"parental_cache_size": 1048576,
"safe_search": yobj{
"enabled": false,
"bing": true,
"duckduckgo": true,
"google": true,
"pixabay": true,
"yandex": true,
"youtube": true,
},
"rewrites": yarr{},
"blocked_services": yobj{
"schedule": yobj{
"time_zone": "Local",
},
"ids": yarr{},
},
"protection_enabled": true,
"blocking_mode": "custom_ip",
"blocking_ipv4": "1.2.3.4",
"blocking_ipv6": "1:2:3::4",
"blocked_response_ttl": 10,
"protection_disabled_until": nil,
"parental_block_host": "p.dns.adguard.com",
"safebrowsing_block_host": "s.dns.adguard.com",
},
},
want: yobj{
"dns": yobj{},
"filtering": yobj{
"filtering_enabled": true,
"filters_update_interval": 24,
"parental_enabled": false,
"safebrowsing_enabled": false,
"safebrowsing_cache_size": 1048576,
"safesearch_cache_size": 1048576,
"parental_cache_size": 1048576,
"safe_search": yobj{
"enabled": false,
"bing": true,
"duckduckgo": true,
"google": true,
"pixabay": true,
"yandex": true,
"youtube": true,
},
"rewrites": yarr{},
"blocked_services": yobj{
"schedule": yobj{
"time_zone": "Local",
},
"ids": yarr{},
},
"protection_enabled": true,
"blocking_mode": "custom_ip",
"blocking_ipv4": "1.2.3.4",
"blocking_ipv6": "1:2:3::4",
"blocked_response_ttl": 10,
"protection_disabled_until": nil,
"parental_block_host": "p.dns.adguard.com",
"safebrowsing_block_host": "s.dns.adguard.com",
},
"schema_version": newSchemaVer,
},
}}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := upgradeSchema25to26(tc.in)
require.NoError(t, err)
assert.Equal(t, tc.want, tc.in)
})
}
}