NUKE
Some checks failed
Docker image builds / build (push) Failing after 4m22s

This commit is contained in:
Soph :3 2026-02-07 14:27:38 +02:00
parent d2205b11a7
commit 02b9aebbe5
341 changed files with 1571 additions and 32574 deletions

View file

@ -1,11 +1,11 @@
//go:build !windows
// Integration tests for Anubis, using Playwright.
// Integration tests for Nuke, using Playwright.
//
// These tests require an already running Anubis and Playwright server.
// These tests require an already running Nuke and Playwright server.
//
// Anubis must be configured to redirect to the server started by the test suite.
// The bind address and the Anubis server can be specified using the flags `-bind` and `-anubis` respectively.
// Nuke must be configured to redirect to the server started by the test suite.
// The bind address and the Nuke server can be specified using the flags `-bind` and `-nuke` respectively.
//
// Playwright must be started in server mode using `npx playwright@1.50.1 run-server --port 3000`.
// The version must match the minor used by the playwright-go package.
@ -28,8 +28,7 @@ import (
"testing"
"time"
"github.com/TecharoHQ/anubis"
libanubis "github.com/TecharoHQ/anubis/lib"
libnuke "git.sad.ovh/sophie/nuke/lib"
"github.com/playwright-community/playwright-go"
)
@ -88,7 +87,7 @@ var (
name: "unknownAgent",
action: actionAllow,
realIP: placeholderIP,
userAgent: "AnubisTest/0",
userAgent: "NukeTest/0",
},
}
)
@ -222,7 +221,7 @@ func TestPlaywrightBrowser(t *testing.T) {
startPlaywright(t)
pw := setupPlaywright(t)
anubisURL := spawnAnubis(t)
nukeURL := spawnNuke(t)
browsers := []playwright.BrowserType{pw.Chromium, pw.Firefox, pw.WebKit}
@ -255,7 +254,7 @@ func TestPlaywrightBrowser(t *testing.T) {
defer page.Close()
timeout := 2.0
page.Goto(anubisURL, playwright.PageGotoOptions{
page.Goto(nukeURL, playwright.PageGotoOptions{
Timeout: &timeout,
})
})
@ -271,7 +270,7 @@ func TestPlaywrightBrowser(t *testing.T) {
var performedAction action
var err error
for i := 0; i < 5; i++ {
performedAction, err = executeTestCase(t, tc, typ, anubisURL)
performedAction, err = executeTestCase(t, tc, typ, nukeURL)
if performedAction == tc.action {
break
}
@ -305,11 +304,11 @@ func TestPlaywrightWithBasePrefix(t *testing.T) {
pw := setupPlaywright(t)
basePrefix := "/myapp"
anubisURL := spawnAnubisWithOptions(t, basePrefix)
nukeURL := spawnNukeWithOptions(t, basePrefix)
// Reset BasePrefix after test
t.Cleanup(func() {
anubis.BasePrefix = ""
nuke.BasePrefix = ""
})
browsers := []playwright.BrowserType{pw.Chromium}
@ -343,7 +342,7 @@ func TestPlaywrightWithBasePrefix(t *testing.T) {
defer page.Close()
// Test accessing the base URL with prefix
_, err = page.Goto(anubisURL+basePrefix, playwright.PageGotoOptions{
_, err = page.Goto(nukeURL+basePrefix, playwright.PageGotoOptions{
Timeout: pwTimeout(testCases[0], time.Now().Add(5*time.Second)),
})
if err != nil {
@ -369,8 +368,8 @@ func TestPlaywrightWithBasePrefix(t *testing.T) {
// Complete the challenge
// Wait for the challenge to be solved
anubisTest := page.Locator("#anubis-test")
err = anubisTest.WaitFor(playwright.LocatorWaitForOptions{
nukeTest := page.Locator("#nuke-test")
err = nukeTest.WaitFor(playwright.LocatorWaitForOptions{
Timeout: pwTimeout(testCases[0], time.Now().Add(30*time.Second)),
})
if err != nil {
@ -378,7 +377,7 @@ func TestPlaywrightWithBasePrefix(t *testing.T) {
}
// Verify the challenge was solved
content, err := anubisTest.TextContent(playwright.LocatorTextContentOptions{})
content, err := nukeTest.TextContent(playwright.LocatorTextContentOptions{})
if err != nil {
pwFail(t, page, "could not get text content: %v", err)
}
@ -402,7 +401,7 @@ func TestPlaywrightWithBasePrefix(t *testing.T) {
var found bool
for _, cookie := range cookies {
if cookie.Name == anubis.CookieName {
if cookie.Name == nuke.CookieName {
found = true
if cookie.Path != basePrefix+"/" {
t.Errorf("cookie path is wrong, wanted %s, got: %s", basePrefix+"/", cookie.Path)
@ -412,7 +411,7 @@ func TestPlaywrightWithBasePrefix(t *testing.T) {
}
if !found {
t.Errorf("Cookie %q not found", anubis.CookieName)
t.Errorf("Cookie %q not found", nuke.CookieName)
}
})
}
@ -428,7 +427,7 @@ func buildBrowserConnect(name string) string {
return u.String()
}
func executeTestCase(t *testing.T, tc testCase, typ playwright.BrowserType, anubisURL string) (action, error) {
func executeTestCase(t *testing.T, tc testCase, typ playwright.BrowserType, nukeURL string) (action, error) {
deadline, _ := t.Deadline()
browser, err := typ.Connect(buildBrowserConnect(typ.Name()), playwright.BrowserTypeConnectOptions{
@ -460,7 +459,7 @@ func executeTestCase(t *testing.T, tc testCase, typ playwright.BrowserType, anub
// Attempt challenge.
start := time.Now()
_, err = page.Goto(anubisURL, playwright.PageGotoOptions{
_, err = page.Goto(nukeURL, playwright.PageGotoOptions{
Timeout: pwTimeout(tc, deadline),
})
if err != nil {
@ -480,7 +479,7 @@ func executeTestCase(t *testing.T, tc testCase, typ playwright.BrowserType, anub
// Ensure protected resource was provided.
res, err := page.Locator("#anubis-test").TextContent(playwright.LocatorTextContentOptions{
res, err := page.Locator("#nuke-test").TextContent(playwright.LocatorTextContentOptions{
Timeout: pwTimeout(tc, deadline),
})
end := time.Now()
@ -552,7 +551,7 @@ func saveScreenshot(t *testing.T, page playwright.Page) {
return
}
f, err := os.CreateTemp("", "anubis-test-fail-*.png")
f, err := os.CreateTemp("", "nuke-test-fail-*.png")
if err != nil {
t.Logf("could not create temporary file: %v", err)
return
@ -583,19 +582,19 @@ func setupPlaywright(t *testing.T) *playwright.Playwright {
return pw
}
func spawnAnubis(t *testing.T) string {
return spawnAnubisWithOptions(t, "")
func spawnNuke(t *testing.T) string {
return spawnNukeWithOptions(t, "")
}
func spawnAnubisWithOptions(t *testing.T, basePrefix string) string {
func spawnNukeWithOptions(t *testing.T, basePrefix string) string {
t.Helper()
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "text/html")
fmt.Fprintf(w, "<html><body><span id=anubis-test>%d</span></body></html>", time.Now().Unix())
fmt.Fprintf(w, "<html><body><span id=nuke-test>%d</span></body></html>", time.Now().Unix())
})
policy, err := libanubis.LoadPoliciesOrDefault(t.Context(), "", anubis.DefaultDifficulty, "info")
policy, err := libnuke.LoadPoliciesOrDefault(t.Context(), "", nuke.DefaultDifficulty, "info")
if err != nil {
t.Fatal(err)
}
@ -609,7 +608,7 @@ func spawnAnubisWithOptions(t *testing.T, basePrefix string) string {
host := "localhost"
port := strconv.Itoa(addr.Port)
s, err := libanubis.New(libanubis.Options{
s, err := libnuke.New(libnuke.Options{
Next: h,
Policy: policy,
ServeRobotsTXT: true,
@ -617,7 +616,7 @@ func spawnAnubisWithOptions(t *testing.T, basePrefix string) string {
BasePrefix: basePrefix,
})
if err != nil {
t.Fatalf("can't construct libanubis.Server: %v", err)
t.Fatalf("can't construct libnuke.Server: %v", err)
}
ts := &httptest.Server{