Captcha is now the host-stamped X-Bn-Verified-Captcha trusted header (pluginsdk v0.2.2), so no plugin has a legitimate core import left: isForbiddenPluginImport flags ALL first-party prefixes unconditionally, and a block/core require in a plugin go.mod fails as no-block-core-require (always vestigial — imports are already forbidden). Fleet-verified: no plugin imports or requires core. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
152 lines
5.1 KiB
Go
152 lines
5.1 KiB
Go
package main
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestCheckStandalonePluginImportsFlagsBlockNinjaCMSImports(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "plugin.mod"), "[plugin]\nname = \"example\"\nversion = \"1.0.0\"\n", 0644)
|
|
writeTestFile(t, filepath.Join(root, "main.go"), `package example
|
|
|
|
import (
|
|
"git.dev.alexdunmow.com/block/pluginsdk/plugin"
|
|
"git.dev.alexdunmow.com/block/cms/internal/helpers"
|
|
)
|
|
|
|
func Example() {
|
|
_ = plugin.PluginRegistration{}
|
|
_ = helpers.Slugify("x")
|
|
}
|
|
`, 0644)
|
|
|
|
violations := checkStandalonePluginImports(root)
|
|
if len(violations) != 1 {
|
|
t.Fatalf("checkStandalonePluginImports() returned %d violations, want 1: %#v", len(violations), violations)
|
|
}
|
|
if violations[0].importPath != "git.dev.alexdunmow.com/block/cms/internal/helpers" {
|
|
t.Fatalf("importPath = %q, want forbidden BlockNinja import", violations[0].importPath)
|
|
}
|
|
}
|
|
|
|
func TestCheckStandalonePluginImportsFlagsCoreImports(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "plugin.mod"), "[plugin]\nname = \"example\"\nversion = \"1.0.0\"\n", 0644)
|
|
writeTestFile(t, filepath.Join(root, "main.go"), `package example
|
|
|
|
import "git.dev.alexdunmow.com/block/core/plugin"
|
|
|
|
func Example() {
|
|
_ = plugin.PluginRegistration{}
|
|
}
|
|
`, 0644)
|
|
|
|
violations := checkStandalonePluginImports(root)
|
|
if len(violations) != 1 {
|
|
t.Fatalf("checkStandalonePluginImports() returned %d violations, want 1: %#v", len(violations), violations)
|
|
}
|
|
if violations[0].importPath != "git.dev.alexdunmow.com/block/core/plugin" {
|
|
t.Fatalf("importPath = %q, want forbidden core import", violations[0].importPath)
|
|
}
|
|
}
|
|
|
|
func TestCheckStandalonePluginImportsAllowsSDKImports(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "plugin.mod"), "[plugin]\nname = \"example\"\nversion = \"1.0.0\"\n", 0644)
|
|
writeTestFile(t, filepath.Join(root, "main.go"), `package example
|
|
|
|
import (
|
|
"git.dev.alexdunmow.com/block/pluginsdk/auth"
|
|
"git.dev.alexdunmow.com/block/pluginsdk/plugin"
|
|
"git.dev.alexdunmow.com/block/pluginsdk/render"
|
|
)
|
|
|
|
func Example() {
|
|
_ = plugin.PluginRegistration{}
|
|
_ = auth.CaptchaVerified
|
|
_ = render.BlockNoteToHTML
|
|
}
|
|
`, 0644)
|
|
|
|
violations := checkStandalonePluginImports(root)
|
|
if len(violations) != 0 {
|
|
t.Fatalf("checkStandalonePluginImports() returned %d violations, want 0: %#v", len(violations), violations)
|
|
}
|
|
}
|
|
|
|
// Captcha moved to the host-stamped X-Bn-Verified-Captcha trusted header
|
|
// (pluginsdk/auth), so the former core/captcha carve-out is gone: NO block/core
|
|
// package is plugin-importable anymore.
|
|
func TestCheckStandalonePluginImportsFlagsFormerlyKeptCoreImports(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "plugin.mod"), "[plugin]\nname = \"example\"\nversion = \"1.0.0\"\n", 0644)
|
|
writeTestFile(t, filepath.Join(root, "main.go"), `package example
|
|
|
|
import "git.dev.alexdunmow.com/block/core/captcha"
|
|
|
|
func Example() {
|
|
_ = captcha.New
|
|
}
|
|
`, 0644)
|
|
|
|
violations := checkStandalonePluginImports(root)
|
|
if len(violations) != 1 {
|
|
t.Fatalf("checkStandalonePluginImports() returned %d violations, want 1: %#v", len(violations), violations)
|
|
}
|
|
if violations[0].importPath != "git.dev.alexdunmow.com/block/core/captcha" {
|
|
t.Fatalf("importPath = %q, want forbidden core/captcha import", violations[0].importPath)
|
|
}
|
|
}
|
|
|
|
func TestCheckStandalonePluginImportsFlagsOrchestratorImports(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "plugin.mod"), "[plugin]\nname = \"example\"\nversion = \"1.0.0\"\n", 0644)
|
|
writeTestFile(t, filepath.Join(root, "main.go"), `package example
|
|
|
|
import "git.dev.alexdunmow.com/block/orchestrator/backend/internal/services"
|
|
|
|
func Example() {
|
|
_ = services.InstanceService{}
|
|
}
|
|
`, 0644)
|
|
|
|
violations := checkStandalonePluginImports(root)
|
|
if len(violations) != 1 {
|
|
t.Fatalf("checkStandalonePluginImports() returned %d violations, want 1: %#v", len(violations), violations)
|
|
}
|
|
if violations[0].importPath != "git.dev.alexdunmow.com/block/orchestrator/backend/internal/services" {
|
|
t.Fatalf("importPath = %q, want forbidden orchestrator import", violations[0].importPath)
|
|
}
|
|
}
|
|
|
|
func TestCheckStandalonePluginImportsFlagsBlockNinjaCMSImportsInTemplFiles(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeTestFile(t, filepath.Join(root, "plugin.mod"), "[plugin]\nname = \"example\"\nversion = \"1.0.0\"\n", 0644)
|
|
writeTestFile(t, filepath.Join(root, "page.templ"), `package example
|
|
|
|
import (
|
|
"git.dev.alexdunmow.com/block/core/templates/bn"
|
|
"git.dev.alexdunmow.com/block/cms/internal/templates"
|
|
)
|
|
|
|
templ Page() {
|
|
<div></div>
|
|
}
|
|
`, 0644)
|
|
|
|
violations := checkStandalonePluginImports(root)
|
|
if len(violations) != 2 {
|
|
t.Fatalf("checkStandalonePluginImports() returned %d violations, want 2: %#v", len(violations), violations)
|
|
}
|
|
if violations[0].importPath != "git.dev.alexdunmow.com/block/core/templates/bn" {
|
|
t.Fatalf("importPath[0] = %q, want forbidden core templ import", violations[0].importPath)
|
|
}
|
|
if violations[1].importPath != "git.dev.alexdunmow.com/block/cms/internal/templates" {
|
|
t.Fatalf("importPath[1] = %q, want forbidden BlockNinja templ import", violations[1].importPath)
|
|
}
|
|
if violations[1].line != 5 {
|
|
t.Fatalf("line = %d, want 5", violations[1].line)
|
|
}
|
|
}
|