Files
lukaszraczylo 22775d446e feat(stealth): make evasion script coherent with generated fingerprint
- Convert assets/evasions.js to evasions.js.tmpl (Go text/template)
- Placeholders: WebGLVendor, WebGLRenderer, Platform, Languages
- Add navigator.platform spoof from fingerprint
- ScriptParams gains OS, Browser, Locale, Seed fields (fieldalignment ordered)
- ScriptResult gains Fingerprint field — returns the identity the script was rendered for
- StealthScript calls GenerateFingerprint and renders template; single call gives both script and coherent fingerprint
- languagesJS: locale to JS list (en-GB -> 'en-GB', 'en')
- Template parsed once at init via template.Must
- StealthScriptIn in tools.go gains OS, Browser, Locale, Seed pass-through
- Tests: added TestStealthScriptCoherence asserting rendered values match fingerprint
2026-06-07 14:29:13 +01:00

49 lines
1.4 KiB
Go

package stealth
import (
"strings"
"testing"
)
func TestStealthScript(t *testing.T) {
res := StealthScript(ScriptParams{Engine: "playwright"})
if res.Script == "" {
t.Fatal("empty script")
}
for _, want := range []string{"navigator.webdriver", "languages", "WebGL", "chrome"} {
if !strings.Contains(res.Script, want) {
t.Fatalf("script missing %q", want)
}
}
if res.Apply.How == "" || len(res.IncludedEvasions) == 0 {
t.Fatalf("missing apply metadata: %+v", res)
}
}
func TestStealthScriptCoherence(t *testing.T) {
p := ScriptParams{OS: "macos", Locale: "en-GB", Seed: 7}
res := StealthScript(p)
// Independently generate the same fingerprint.
fp := GenerateFingerprint(FingerprintParams{OS: "macos", Locale: "en-GB", Seed: 7})
// Script must contain the fingerprint's WebGL and platform values.
for _, want := range []string{fp.WebGLVendor, fp.WebGLRenderer, fp.Platform} {
if !strings.Contains(res.Script, want) {
t.Errorf("script missing %q", want)
}
}
// Script must contain navigator.platform spoof.
if !strings.Contains(res.Script, "navigator.platform") {
t.Error("script missing navigator.platform spoof")
}
// ScriptResult.Fingerprint must equal independently generated fingerprint.
if res.Fingerprint != fp {
t.Errorf("fingerprint mismatch:\n got %+v\n want %+v", res.Fingerprint, fp)
}
// Template must not produce empty script.
if res.Script == "" {
t.Fatal("empty rendered script")
}
}