Import Anubis v1.28.2
Replace the tree with upstream TecharoHQ/anubis v1.28.2 (a1384fbf42e3). Masyunis customizations are re-applied in the following commits.
This commit is contained in:
1 parent
eb3e46d8d0
commit
e07de898cd
573 files changed
+35846
-6807
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package lib
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/TecharoHQ/anubis/internal"
|
||||
"github.com/TecharoHQ/anubis/lib/challenge"
|
||||
)
|
||||
|
||||
type failingChallenge struct {
|
||||
challenge.Impl
|
||||
err error
|
||||
}
|
||||
|
||||
func (f failingChallenge) Validate(*http.Request, *slog.Logger, *challenge.ValidateInput) error {
|
||||
return f.err
|
||||
}
|
||||
|
||||
func TestPassChallengeRejectsEveryValidationError(t *testing.T) {
|
||||
original, _ := challenge.Get("fast")
|
||||
t.Cleanup(func() { challenge.Register("fast", original) })
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
err error
|
||||
}{
|
||||
{"plain", errors.New("validation unavailable")},
|
||||
{"wrapped without sentinel", challenge.NewError("validate", "internal WASM error", errors.New("validation unavailable"))},
|
||||
{"failed sentinel", challenge.NewError("validate", "invalid response", challenge.ErrFailed)},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
challenge.Register("fast", failingChallenge{Impl: original, err: tt.err})
|
||||
srv := spawnAnubis(t, Options{Next: http.NewServeMux(), Policy: loadPolicies(t, "./testdata/zero_difficulty.yaml", 0)})
|
||||
ts := httptest.NewServer(internal.RemoteXRealIP(true, "tcp", srv))
|
||||
t.Cleanup(ts.Close)
|
||||
cli := httpClient(t)
|
||||
chall := makeChallenge(t, ts, cli)
|
||||
resp := handleChallengeZeroDifficulty(t, ts, cli, chall)
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
if resp.StatusCode < 400 {
|
||||
t.Errorf("validation error accepted: status %d", resp.StatusCode)
|
||||
}
|
||||
if authCookie(srv, resp) != nil {
|
||||
t.Error("validation error minted clearance cookie")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user