package plugin_test import ( "crypto/ed25519" "encoding/json" "os" "path/filepath" "strings" "testing" "github.com/Nwflower/reims-go/internal/plugin" ) func TestScanDirectoryCleanL1Theme(t *testing.T) { dir := t.TempDir() man, _ := json.Marshal(plugin.Manifest{ Schema: 1, ID: "test.theme.clean", Version: "1.0.0", Name: plugin.LocalizedText{ZhCN: "纯净主题", EnUS: "Clean Theme"}, Description: plugin.LocalizedText{ZhCN: "无脚本纯样式主题", EnUS: "Pure CSS theme"}, Publisher: "tester", License: "MIT", Contributes: plugin.Contributes{ Themes: []plugin.ThemeContribution{{ ID: "test.theme.clean", Name: plugin.LocalizedText{EnUS: "Clean"}, Stylesheet: "theme.css", }}, }, }) _ = os.WriteFile(filepath.Join(dir, "plugin.json"), man, 0o644) _ = os.WriteFile(filepath.Join(dir, "theme.css"), []byte(`.rg-p-sidebar { background: var(--surface-sidebar); }`), 0o644) _ = os.WriteFile(filepath.Join(dir, "icon.svg"), []byte(``), 0o644) rep := plugin.ScanDirectory(dir, "0.2.8", plugin.ScanOptions{}) if !rep.Passed || rep.HardBlocked { t.Fatalf("expected clean L1 theme to pass, got hard findings: %+v", rep.HardFindings) } if rep.Tier != plugin.TierL1 { t.Fatalf("tier = %s, want L1", rep.Tier) } if rep.NativeExecNotice.HasAny() { t.Fatalf("L1 theme should not carry native exec notice") } if rep.NeedsApproval { t.Fatalf("clean L1 theme should not require approval") } } func TestScanBlocksSmuggledBinariesInL1(t *testing.T) { dir := t.TempDir() man, _ := json.Marshal(plugin.Manifest{ Schema: 1, ID: "test.theme.smuggle", Version: "1.0.0", Name: plugin.LocalizedText{EnUS: "Smuggle"}, }) _ = os.WriteFile(filepath.Join(dir, "plugin.json"), man, 0o644) _ = os.WriteFile(filepath.Join(dir, "helper.ps1"), []byte(`Write-Host "hi"`), 0o644) _ = os.WriteFile(filepath.Join(dir, "payload.exe"), []byte("MZfake"), 0o644) rep := plugin.ScanDirectory(dir, "0.2.8", plugin.ScanOptions{}) if !rep.HardBlocked || rep.Passed { t.Fatalf("expected L1 package with .ps1/.exe to be hard-blocked") } if len(rep.Executables) != 2 { t.Fatalf("expected 2 executables recorded, got %d", len(rep.Executables)) } foundBin := 0 for _, f := range rep.HardFindings { if f.Check == "forbidden-binary" { foundBin++ } } if foundBin != 2 { t.Fatalf("expected 2 forbidden-binary hard findings, got %d (%+v)", foundBin, rep.HardFindings) } // InstallArchive must also hard-reject the zipped package. zipPath := makePluginZip(t, map[string][]byte{ "plugin.json": man, "helper.ps1": []byte(`Write-Host "hi"`), }, nil, false) layout := plugin.NewPluginsLayout(t.TempDir()) if _, err := plugin.InstallArchive(layout, zipPath, plugin.PackageInstallOptions{ HostVersion: "0.2.8", AllowUnsigned: true, }); err == nil || !strings.Contains(err.Error(), "static security gate") { t.Fatalf("expected InstallArchive hard gate rejection, got: %v", err) } } func TestScanBlocksSVGActiveContent(t *testing.T) { dir := t.TempDir() man, _ := json.Marshal(plugin.Manifest{ Schema: 1, ID: "test.theme.badsvg", Version: "1.0.0", Name: plugin.LocalizedText{EnUS: "Bad SVG"}, }) _ = os.WriteFile(filepath.Join(dir, "plugin.json"), man, 0o644) _ = os.WriteFile(filepath.Join(dir, "evil.svg"), []byte(``), 0o644) rep := plugin.ScanDirectory(dir, "0.2.8", plugin.ScanOptions{}) if !rep.HardBlocked { t.Fatal("expected SVG with