diff options
| author | Xe Iaso <me@xeiaso.net> | 2025-04-22 14:52:31 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2025-04-22 14:52:52 -0400 |
| commit | 211d346cbcbaf8fada694102bfb392c82c8938ea (patch) | |
| tree | 5824fc7d122e4f7411d08d0bec3aa7f7ddb822fd | |
| parent | e6af0697daea67eab0dcec1ad5929ffe7e9dbd50 (diff) | |
| download | anubis-211d346cbcbaf8fada694102bfb392c82c8938ea.tar.xz anubis-211d346cbcbaf8fada694102bfb392c82c8938ea.zip | |
fix(lib/policy): better test importing from JSON snippets
Signed-off-by: Xe Iaso <me@xeiaso.net>
| -rw-r--r-- | lib/policy/config/config.go | 2 | ||||
| -rw-r--r-- | lib/policy/config/testdata/bad/import_and_bot.json | 10 | ||||
| -rw-r--r-- | lib/policy/config/testdata/bad/import_and_bot.yaml | 6 | ||||
| -rw-r--r-- | lib/policy/config/testdata/good/import_filesystem.json | 2 | ||||
| -rw-r--r-- | lib/policy/config/testdata/hack-test.json | 9 | ||||
| -rw-r--r-- | lib/policy/testdata/hack-test.json | 9 |
6 files changed, 36 insertions, 2 deletions
diff --git a/lib/policy/config/config.go b/lib/policy/config/config.go index d9883c5..5352818 100644 --- a/lib/policy/config/config.go +++ b/lib/policy/config/config.go @@ -26,7 +26,7 @@ var ( ErrInvalidCIDR = errors.New("config.Bot: invalid CIDR") ErrInvalidImportStatement = errors.New("config.ImportStatement: invalid source file") ErrCantSetBotAndImportValuesAtOnce = errors.New("config.BotOrImport: can't set bot rules and import values at the same time") - ErrMustSetBotOrImportRules = errors.New("config.BotOrImport: rule definition is invalid, you must set either bot rules or an import statement") + ErrMustSetBotOrImportRules = errors.New("config.BotOrImport: rule definition is invalid, you must set either bot rules or an import statement, not both") ) type Rule string diff --git a/lib/policy/config/testdata/bad/import_and_bot.json b/lib/policy/config/testdata/bad/import_and_bot.json new file mode 100644 index 0000000..7fa4255 --- /dev/null +++ b/lib/policy/config/testdata/bad/import_and_bot.json @@ -0,0 +1,10 @@ +{ + "bots": [ + { + "import": "(data)/bots/ai-robots-txt.yaml", + "name": "generic-browser", + "user_agent_regex": "Mozilla|Opera\n", + "action": "CHALLENGE" + } + ] +}
\ No newline at end of file diff --git a/lib/policy/config/testdata/bad/import_and_bot.yaml b/lib/policy/config/testdata/bad/import_and_bot.yaml new file mode 100644 index 0000000..0080b10 --- /dev/null +++ b/lib/policy/config/testdata/bad/import_and_bot.yaml @@ -0,0 +1,6 @@ +bots: +- import: (data)/bots/ai-robots-txt.yaml + name: generic-browser + user_agent_regex: > + Mozilla|Opera + action: CHALLENGE
\ No newline at end of file diff --git a/lib/policy/config/testdata/good/import_filesystem.json b/lib/policy/config/testdata/good/import_filesystem.json index 31f3700..23480c9 100644 --- a/lib/policy/config/testdata/good/import_filesystem.json +++ b/lib/policy/config/testdata/good/import_filesystem.json @@ -1,7 +1,7 @@ { "bots": [ { - "import": "./testdata/hack-test.yaml" + "import": "./testdata/hack-test.json" } ] }
\ No newline at end of file diff --git a/lib/policy/config/testdata/hack-test.json b/lib/policy/config/testdata/hack-test.json new file mode 100644 index 0000000..652dcd8 --- /dev/null +++ b/lib/policy/config/testdata/hack-test.json @@ -0,0 +1,9 @@ +[ + { + "name": "ipv6-ula", + "action": "ALLOW", + "remote_addresses": [ + "fc00::/7" + ] + } +]
\ No newline at end of file diff --git a/lib/policy/testdata/hack-test.json b/lib/policy/testdata/hack-test.json new file mode 100644 index 0000000..652dcd8 --- /dev/null +++ b/lib/policy/testdata/hack-test.json @@ -0,0 +1,9 @@ +[ + { + "name": "ipv6-ula", + "action": "ALLOW", + "remote_addresses": [ + "fc00::/7" + ] + } +]
\ No newline at end of file |
