Update to Anubis v1.28.2 (#1)

This upgrades the Masyunis fork from Anubis v1.25.0 to the latest stable release, **v1.28.2** (“Wuk Lamat Echo 2”), while keeping the fork’s custom styling and removals.

## Approach

The Gitea repo is a tree snapshot of v1.25.0, not a git-level fork of [TecharoHQ/anubis](https://github.com/TecharoHQ/anubis). The histories share no commits, so a merge or rebase onto the upstream tag is not usable.

The first commit on this branch replaces the tree with a snapshot of the **v1.28.2** tag (`git rm -r` plus `git checkout v1.28.2 -- .`; the import tree is identical to the tag). A short patch series on top restores the Masyunis customizations.

## Customizations kept

- Masyunya mascots (`web/static/img/{happy,pensive,reject}.webp`), hashes match current `master`.
- `web/static/img/ATTRIBUTIONS.txt` stays deleted.
- Challenge footer: drop the `made_with` (Canada / maple-leaf) line and the CELPHASE mascot credit; keep “Protected by Anubis from Techaro”. The generated `web/index_templ.go` matches `go generate ./web`.
- Short README (the old `anubisc` typo is fixed).
- Version stamped `v1.28.2/masyunis` via Makefile ldflags. `anubis.go` `init()` does not overwrite a link-time version; `go run` / `go test` still report `devel` on purpose.
- Upstream `.github`, `.devcontainer`, `.husky`, and `.vscode` stay deleted.
- `"uk"` is removed from `lib/localization/locales/manifest.json` **on purpose**, because of Alpine locale problems. `uk.json` and its test entry stay; the served manifest lists 27 languages.
- `package.json` `prepare` no longer runs `husky` (the hooks directory is gone). The rest of the script is unchanged. `husky` remains in devDependencies, as upstream left it.

## Deploy notes

- **Cookie rename (v1.27):** with the default `DYNAMIC_COOKIE_SUFFIX=true`, cookie names become e.g. `techaro.lol-anubis-auth-<hash>`. Existing clients get a **one-time re-challenge**. That is expected, not a loop.
- **Docker / ko / yeet builds** skip the Makefile ldflags, so the displayed version is `<git-version>/masyunis`. It is `v1.28.2/masyunis` only when built from a `v1.28.2` tag (or via `make build` / `make prebaked-build`).
- Go 1.27.3 is required (upstream bump in v1.28.2). Thoth (`THOTH_URL` / `THOTH_TOKEN`) was removed upstream; those settings now warn and do nothing. New WASM challenge methods stay disabled unless opted in.

## Verification

- `make build` succeeds. `./var/anubis --version` prints `Anubis v1.28.2/masyunis`.
- `SKIP_INTEGRATION=1 go test ./...` passes (unit tests; integration package is skipped).
- Local challenge/reject pages (en and ru) show Masyunya, version `v1.28.2/masyunis`, and no Canada / CELPHASE / mascot-credit text. Screenshots:

![Challenge page (en)](https://git.unvr.site/attachments/36112ff0-5155-495c-8bd2-59606ee3bd64)
![Reject page (en)](https://git.unvr.site/attachments/2cad0256-1b0e-4f71-8d06-d1a447fd5263)

- Upstream Playwright tests (`make test` without `SKIP_INTEGRATION`) fail on this box because the browser download fails. A clean v1.28.2 tree fails the same three Playwright tests here, so this is not a fork regression.
- `npm audit` reports **4** findings in upstream’s lockfile (2 moderate, 2 high: `brace-expansion`, `fast-uri`, `lodash.trim`, `source-map-js`). Left alone.

Please review and merge when ready. I will not merge this myself.

Reviewed-on: #1
Co-authored-by: Lead <3+lead_bot@noreply.git.unvr.site>
This commit was merged in pull request #1.
This commit is contained in:
sol_bot Bot authored and matiashik committed 2026-11-28 12:10:27 +00:00
1 parent eb3e46d8d0
commit caf4d72880
529 files changed
+33015 -6659

No files matched your search

+586
View File
@@ -0,0 +1,586 @@
package main
import (
"errors"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"slices"
"strings"
"testing"
"gopkg.in/yaml.v3"
)
func TestParsePrefixes(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
name string
input string
want []string
err error
}{
{
name: "ipv4 and ipv6",
input: `{"prefixes":[{"ipv4Prefix":"192.0.2.0/24"},{"ipv6Prefix":"2001:db8::/32"}]}`,
want: []string{"192.0.2.0/24", "2001:db8::/32"},
},
{
name: "ignores unrelated fields",
input: `{"creationTime":"2026-08-31T14:46:46.000000","notes":"hi","prefixes":[{"ipv4Prefix":"192.0.2.0/24"}]}`,
want: []string{"192.0.2.0/24"},
},
{
name: "no prefixes",
input: `{"prefixes":[]}`,
err: ErrNoPrefixes,
},
{
name: "empty prefix entry",
input: `{"prefixes":[{"ipv4Prefix":"192.0.2.0/24"},{}]}`,
},
{
name: "bare address is not a prefix",
input: `{"prefixes":[{"ipv4Prefix":"192.0.2.1"}]}`,
},
{
name: "garbage prefix",
input: `{"prefixes":[{"ipv4Prefix":"not-an-ip/24"}]}`,
},
{
name: "not json",
input: `<html>go away</html>`,
},
} {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := parsePrefixes(strings.NewReader(tt.input))
if tt.want == nil {
if err == nil {
t.Logf("got: %v", got)
t.Fatal("wanted an error but parsing succeeded")
}
if tt.err != nil && !errors.Is(err, tt.err) {
t.Logf("want: %v", tt.err)
t.Logf("got: %v", err)
t.Error("got wrong error")
}
return
}
if err != nil {
t.Fatalf("can't parse prefix list: %v", err)
}
if !slices.Equal(got, tt.want) {
t.Logf("want: %v", tt.want)
t.Logf("got: %v", got)
t.Error("got wrong prefixes")
}
})
}
}
func TestSetRemoteAddresses(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
name string
input string
rule string
want []string
wantOld []string
err error
}{
{
name: "block style rule",
input: `- name: googlebot
user_agent_regex: \+http\://www\.google\.com/bot\.html
action: ALLOW
remote_addresses:
- 192.0.2.0/24
`,
rule: "googlebot",
want: []string{"198.51.100.0/24"},
wantOld: []string{"192.0.2.0/24"},
},
{
name: "picks the right rule in a multi rule file",
input: `- name: first
action: ALLOW
remote_addresses: ["192.0.2.0/24"]
- name: second
action: ALLOW
remote_addresses: ["203.0.113.0/24"]
`,
rule: "second",
want: []string{"198.51.100.0/24"},
wantOld: []string{"203.0.113.0/24"},
},
{
name: "rule is missing",
input: `- name: googlebot
action: ALLOW
remote_addresses: ["192.0.2.0/24"]
`,
rule: "bingbot",
err: ErrRuleNotFound,
},
{
name: "rule has no remote_addresses",
input: `- name: yandexbot
action: ALLOW
`,
rule: "yandexbot",
err: ErrNoRemoteAddresses,
},
} {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var root yaml.Node
if err := yaml.Unmarshal([]byte(tt.input), &root); err != nil {
t.Fatalf("can't parse test fixture: %v", err)
}
old, err := setRemoteAddresses(&root, tt.rule, tt.want)
if tt.err != nil {
if !errors.Is(err, tt.err) {
t.Logf("want: %v", tt.err)
t.Logf("got: %v", err)
t.Error("got wrong error")
}
return
}
if err != nil {
t.Fatalf("can't set remote addresses: %v", err)
}
if !slices.Equal(old, tt.wantOld) {
t.Logf("want: %v", tt.wantOld)
t.Logf("got: %v", old)
t.Error("got wrong previous addresses")
}
data, err := marshal(&root)
if err != nil {
t.Fatalf("can't serialize result: %v", err)
}
var rules []struct {
Name string `yaml:"name"`
RemoteAddr []string `yaml:"remote_addresses"`
}
if err := yaml.Unmarshal(data, &rules); err != nil {
t.Fatalf("can't reparse result: %v", err)
}
idx := slices.IndexFunc(rules, func(r struct {
Name string `yaml:"name"`
RemoteAddr []string `yaml:"remote_addresses"`
}) bool {
return r.Name == tt.rule
})
if idx == -1 {
t.Fatalf("rule %s vanished from the result:\n%s", tt.rule, data)
}
if !slices.Equal(rules[idx].RemoteAddr, tt.want) {
t.Logf("want: %v", tt.want)
t.Logf("got: %v", rules[idx].RemoteAddr)
t.Error("got wrong addresses in output")
}
})
}
}
func TestSetRemoteAddressesKeepsComments(t *testing.T) {
t.Parallel()
const input = `# Indexing for search and Siri
# https://support.apple.com/en-us/119829
- name: applebot
user_agent_regex: Applebot
action: ALLOW
# https://search.developer.apple.com/applebot.json
remote_addresses: ["17.241.208.160/27"]
# trailing note
`
var root yaml.Node
if err := yaml.Unmarshal([]byte(input), &root); err != nil {
t.Fatalf("can't parse test fixture: %v", err)
}
if _, err := setRemoteAddresses(&root, "applebot", []string{"192.0.2.0/24"}); err != nil {
t.Fatalf("can't set remote addresses: %v", err)
}
data, err := marshal(&root)
if err != nil {
t.Fatalf("can't serialize result: %v", err)
}
for _, want := range []string{
"# Indexing for search and Siri",
"# https://support.apple.com/en-us/119829",
"# https://search.developer.apple.com/applebot.json",
"# trailing note",
"user_agent_regex: Applebot",
} {
if !strings.Contains(string(data), want) {
t.Logf("want to find: %q", want)
t.Logf("got:\n%s", data)
t.Error("output lost part of the original file")
}
}
}
func TestSetRemoteAddressesKeepsStyle(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
name string
input string
want string
}{
{
name: "flow style quotes every prefix",
input: "- name: applebot\n remote_addresses: [\"192.0.2.0/24\"]\n",
want: `remote_addresses: ["198.51.100.0/24", "2001:db8::/32"]`,
},
{
name: "block style leaves prefixes bare",
input: "- name: applebot\n remote_addresses:\n - 192.0.2.0/24\n",
want: "remote_addresses:\n - 198.51.100.0/24\n - 2001:db8::/32",
},
} {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var root yaml.Node
if err := yaml.Unmarshal([]byte(tt.input), &root); err != nil {
t.Fatalf("can't parse test fixture: %v", err)
}
if _, err := setRemoteAddresses(&root, "applebot", []string{"198.51.100.0/24", "2001:db8::/32"}); err != nil {
t.Fatalf("can't set remote addresses: %v", err)
}
data, err := marshal(&root)
if err != nil {
t.Fatalf("can't serialize result: %v", err)
}
if !strings.Contains(string(data), tt.want) {
t.Logf("want to find:\n%s", tt.want)
t.Logf("got:\n%s", data)
t.Error("wrote the prefixes in the wrong style")
}
})
}
}
func TestSelectSources(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
name string
input []string
want []string
err error
}{
{
name: "no arguments selects everything",
input: nil,
want: allSourceNames(),
},
{
name: "by name",
input: []string{"googlebot", "bingbot"},
want: []string{"googlebot", "bingbot"},
},
{
name: "unknown crawler",
input: []string{"googlebot", "clippy"},
err: ErrNoSuchCrawler,
},
} {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := selectSources(tt.input)
if tt.err != nil {
if !errors.Is(err, tt.err) {
t.Logf("want: %v", tt.err)
t.Logf("got: %v", err)
t.Error("got wrong error")
}
return
}
if err != nil {
t.Fatalf("can't select sources: %v", err)
}
var names []string
for _, src := range got {
names = append(names, src.Name())
}
if !slices.Equal(names, tt.want) {
t.Logf("want: %v", tt.want)
t.Logf("got: %v", names)
t.Error("selected the wrong crawlers")
}
})
}
}
func TestSourcesMatchDataFiles(t *testing.T) {
t.Parallel()
const dir = "../../../data/crawlers"
for _, src := range sources {
t.Run(src.Name(), func(t *testing.T) {
t.Parallel()
data, err := os.ReadFile(filepath.Join(dir, src.File))
if err != nil {
t.Fatalf("can't read policy file: %v", err)
}
var rules []struct {
Name string `yaml:"name"`
RemoteAddr []string `yaml:"remote_addresses"`
}
if err := yaml.Unmarshal(data, &rules); err != nil {
t.Fatalf("can't parse policy file: %v", err)
}
for _, rule := range rules {
if rule.Name != src.Rule {
continue
}
if len(rule.RemoteAddr) == 0 {
t.Errorf("rule %s has no remote_addresses to update", src.Rule)
}
return
}
t.Errorf("%s declares no rule named %q", src.File, src.Rule)
})
}
}
func TestUpdate(t *testing.T) {
t.Parallel()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if got := r.Header.Get("User-Agent"); got != "test-agent" {
t.Errorf("wanted User-Agent test-agent, got: %s", got)
}
w.Header().Set("Content-Type", "application/json")
writePrefixes(t, w)
}))
t.Cleanup(srv.Close)
dir := t.TempDir()
fname := filepath.Join(dir, "googlebot.yaml")
const input = `- name: googlebot
action: ALLOW
# source of truth
remote_addresses:
- 192.0.2.0/24
`
if err := os.WriteFile(fname, []byte(input), 0o644); err != nil {
t.Fatalf("can't write test fixture: %v", err)
}
src := Source{File: "googlebot.yaml", Rule: "googlebot", URL: srv.URL}
t.Run("dry run leaves the file alone", func(t *testing.T) {
u := &updater{cli: srv.Client(), dataDir: dir, dryRun: true, userAgent: "test-agent"}
if err := u.update(src); err != nil {
t.Fatalf("can't update: %v", err)
}
got, err := os.ReadFile(fname)
if err != nil {
t.Fatalf("can't read file back: %v", err)
}
if string(got) != input {
t.Logf("want:\n%s", input)
t.Logf("got:\n%s", got)
t.Error("dry run wrote to the file")
}
})
t.Run("writes the new prefixes", func(t *testing.T) {
u := &updater{cli: srv.Client(), dataDir: dir, userAgent: "test-agent"}
if err := u.update(src); err != nil {
t.Fatalf("can't update: %v", err)
}
got, err := os.ReadFile(fname)
if err != nil {
t.Fatalf("can't read file back: %v", err)
}
for _, want := range []string{"198.51.100.0/24", "2001:db8::/32", "# source of truth"} {
if !strings.Contains(string(got), want) {
t.Logf("want to find: %q", want)
t.Logf("got:\n%s", got)
t.Error("output is missing something")
}
}
if strings.Contains(string(got), "192.0.2.0/24") {
t.Logf("got:\n%s", got)
t.Error("stale prefix survived the update")
}
})
}
func TestUpdateRejectsBadFeed(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
name string
status int
body string
wantErr error
}{
{name: "server error", status: http.StatusInternalServerError, body: "nope", wantErr: ErrUnexpectedStatus},
{name: "empty feed", status: http.StatusOK, body: `{"prefixes":[]}`, wantErr: ErrNoPrefixes},
} {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(tt.status)
if _, err := w.Write([]byte(tt.body)); err != nil {
t.Errorf("can't write response: %v", err)
}
}))
t.Cleanup(srv.Close)
dir := t.TempDir()
fname := filepath.Join(dir, "googlebot.yaml")
const input = "- name: googlebot\n action: ALLOW\n remote_addresses:\n - 192.0.2.0/24\n"
if err := os.WriteFile(fname, []byte(input), 0o644); err != nil {
t.Fatalf("can't write test fixture: %v", err)
}
u := &updater{cli: srv.Client(), dataDir: dir, userAgent: "test-agent"}
err := u.update(Source{File: "googlebot.yaml", Rule: "googlebot", URL: srv.URL})
if !errors.Is(err, tt.wantErr) {
t.Logf("want: %v", tt.wantErr)
t.Logf("got: %v", err)
t.Error("got wrong error")
}
got, err := os.ReadFile(fname)
if err != nil {
t.Fatalf("can't read file back: %v", err)
}
if string(got) != input {
t.Logf("got:\n%s", got)
t.Error("a failed fetch must not touch the policy file")
}
})
}
}
func TestDiff(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
name string
old, cur []string
wantAdded []string
wantRemoved []string
}{
{
name: "no change",
old: []string{"192.0.2.0/24"},
cur: []string{"192.0.2.0/24"},
},
{
name: "reordering is not a change",
old: []string{"192.0.2.0/24", "198.51.100.0/24"},
cur: []string{"198.51.100.0/24", "192.0.2.0/24"},
wantAdded: nil,
},
{
name: "added and removed",
old: []string{"192.0.2.0/24", "203.0.113.0/24"},
cur: []string{"192.0.2.0/24", "198.51.100.0/24"},
wantAdded: []string{"198.51.100.0/24"},
wantRemoved: []string{"203.0.113.0/24"},
},
{
name: "first run",
cur: []string{"192.0.2.0/24"},
wantAdded: []string{"192.0.2.0/24"},
},
} {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
added, removed := diff(tt.old, tt.cur)
if !slices.Equal(added, tt.wantAdded) {
t.Logf("want: %v", tt.wantAdded)
t.Logf("got: %v", added)
t.Error("got wrong added prefixes")
}
if !slices.Equal(removed, tt.wantRemoved) {
t.Logf("want: %v", tt.wantRemoved)
t.Logf("got: %v", removed)
t.Error("got wrong removed prefixes")
}
})
}
}
func allSourceNames() []string {
var names []string
for _, src := range sources {
names = append(names, src.Name())
}
return names
}
func writePrefixes(t *testing.T, w http.ResponseWriter) {
t.Helper()
const body = `{"prefixes":[{"ipv4Prefix":"198.51.100.0/24"},{"ipv6Prefix":"2001:db8::/32"}]}`
if _, err := w.Write([]byte(body)); err != nil {
t.Errorf("can't write response: %v", err)
}
}