Some checks failed
Pipeline: Test, Lint, Build / Get version info (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test JS code (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint i18n files (push) Has been cancelled
Pipeline: Test, Lint, Build / Check Docker configuration (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v5) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v6) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v7) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to GHCR (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to Docker Hub (push) Has been cancelled
Pipeline: Test, Lint, Build / Cleanup digest artifacts (push) Has been cancelled
Pipeline: Test, Lint, Build / Build Windows installers (push) Has been cancelled
Pipeline: Test, Lint, Build / Package/Release (push) Has been cancelled
Pipeline: Test, Lint, Build / Upload Linux PKG (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
POEditor import / update-translations (push) Has been cancelled
145 lines
4.7 KiB
Go
145 lines
4.7 KiB
Go
package plugins
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/navidrome/navidrome/plugins/schema"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("Plugin Manifest", func() {
|
|
var tempDir string
|
|
|
|
BeforeEach(func() {
|
|
tempDir = GinkgoT().TempDir()
|
|
})
|
|
|
|
It("should load and parse a valid manifest", func() {
|
|
manifestPath := filepath.Join(tempDir, "manifest.json")
|
|
manifestContent := []byte(`{
|
|
"name": "test-plugin",
|
|
"author": "Test Author",
|
|
"version": "1.0.0",
|
|
"description": "A test plugin",
|
|
"website": "https://test.navidrome.org/test-plugin",
|
|
"capabilities": ["MetadataAgent", "Scrobbler"],
|
|
"permissions": {
|
|
"http": {
|
|
"reason": "To fetch metadata",
|
|
"allowedUrls": {
|
|
"https://api.example.com/*": ["GET"]
|
|
}
|
|
}
|
|
}
|
|
}`)
|
|
|
|
err := os.WriteFile(manifestPath, manifestContent, 0600)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
manifest, err := LoadManifest(tempDir)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(manifest).NotTo(BeNil())
|
|
Expect(manifest.Name).To(Equal("test-plugin"))
|
|
Expect(manifest.Author).To(Equal("Test Author"))
|
|
Expect(manifest.Version).To(Equal("1.0.0"))
|
|
Expect(manifest.Description).To(Equal("A test plugin"))
|
|
Expect(manifest.Capabilities).To(HaveLen(2))
|
|
Expect(manifest.Capabilities[0]).To(Equal(schema.PluginManifestCapabilitiesElemMetadataAgent))
|
|
Expect(manifest.Capabilities[1]).To(Equal(schema.PluginManifestCapabilitiesElemScrobbler))
|
|
Expect(manifest.Permissions.Http).NotTo(BeNil())
|
|
Expect(manifest.Permissions.Http.Reason).To(Equal("To fetch metadata"))
|
|
})
|
|
|
|
It("should fail with proper error for non-existent manifest", func() {
|
|
_, err := LoadManifest(filepath.Join(tempDir, "non-existent"))
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("failed to read manifest file"))
|
|
})
|
|
|
|
It("should fail with JSON parse error for invalid JSON", func() {
|
|
// Create invalid JSON
|
|
invalidJSON := `{
|
|
"name": "test-plugin",
|
|
"author": "Test Author"
|
|
"version": "1.0.0"
|
|
"description": "A test plugin",
|
|
"capabilities": ["MetadataAgent"],
|
|
"permissions": {}
|
|
}`
|
|
|
|
pluginDir := filepath.Join(tempDir, "invalid-json")
|
|
Expect(os.MkdirAll(pluginDir, 0755)).To(Succeed())
|
|
Expect(os.WriteFile(filepath.Join(pluginDir, "manifest.json"), []byte(invalidJSON), 0600)).To(Succeed())
|
|
|
|
// Test validation fails
|
|
_, err := LoadManifest(pluginDir)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("invalid manifest"))
|
|
})
|
|
|
|
It("should validate manifest against schema with detailed error for missing required field", func() {
|
|
// Create manifest missing required name field
|
|
manifestContent := `{
|
|
"author": "Test Author",
|
|
"version": "1.0.0",
|
|
"description": "A test plugin",
|
|
"website": "https://test.navidrome.org/test-plugin",
|
|
"capabilities": ["MetadataAgent"],
|
|
"permissions": {}
|
|
}`
|
|
|
|
pluginDir := filepath.Join(tempDir, "test-plugin")
|
|
Expect(os.MkdirAll(pluginDir, 0755)).To(Succeed())
|
|
Expect(os.WriteFile(filepath.Join(pluginDir, "manifest.json"), []byte(manifestContent), 0600)).To(Succeed())
|
|
|
|
_, err := LoadManifest(pluginDir)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("field name in PluginManifest: required"))
|
|
})
|
|
|
|
It("should validate manifest with wrong capability type", func() {
|
|
// Create manifest with invalid capability
|
|
manifestContent := `{
|
|
"name": "test-plugin",
|
|
"author": "Test Author",
|
|
"version": "1.0.0",
|
|
"description": "A test plugin",
|
|
"website": "https://test.navidrome.org/test-plugin",
|
|
"capabilities": ["UnsupportedService"],
|
|
"permissions": {}
|
|
}`
|
|
|
|
pluginDir := filepath.Join(tempDir, "test-plugin")
|
|
Expect(os.MkdirAll(pluginDir, 0755)).To(Succeed())
|
|
Expect(os.WriteFile(filepath.Join(pluginDir, "manifest.json"), []byte(manifestContent), 0600)).To(Succeed())
|
|
|
|
_, err := LoadManifest(pluginDir)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("invalid value"))
|
|
Expect(err.Error()).To(ContainSubstring("UnsupportedService"))
|
|
})
|
|
|
|
It("should validate manifest with empty capabilities array", func() {
|
|
// Create manifest with empty capabilities array
|
|
manifestContent := `{
|
|
"name": "test-plugin",
|
|
"author": "Test Author",
|
|
"version": "1.0.0",
|
|
"description": "A test plugin",
|
|
"website": "https://test.navidrome.org/test-plugin",
|
|
"capabilities": [],
|
|
"permissions": {}
|
|
}`
|
|
|
|
pluginDir := filepath.Join(tempDir, "test-plugin")
|
|
Expect(os.MkdirAll(pluginDir, 0755)).To(Succeed())
|
|
Expect(os.WriteFile(filepath.Join(pluginDir, "manifest.json"), []byte(manifestContent), 0600)).To(Succeed())
|
|
|
|
_, err := LoadManifest(pluginDir)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("field capabilities length: must be >= 1"))
|
|
})
|
|
})
|