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
80 lines
2.6 KiB
Go
80 lines
2.6 KiB
Go
package plugins
|
|
|
|
import (
|
|
"github.com/navidrome/navidrome/plugins/schema"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("WebSocket Permissions", func() {
|
|
Describe("parseWebSocketPermissions", func() {
|
|
It("should parse valid WebSocket permissions", func() {
|
|
permData := &schema.PluginManifestPermissionsWebsocket{
|
|
Reason: "Need to connect to WebSocket API",
|
|
AllowLocalNetwork: false,
|
|
AllowedUrls: []string{"wss://api.example.com/ws", "wss://cdn.example.com/*"},
|
|
}
|
|
|
|
perms, err := parseWebSocketPermissions(permData)
|
|
Expect(err).To(BeNil())
|
|
Expect(perms).ToNot(BeNil())
|
|
Expect(perms.AllowLocalNetwork).To(BeFalse())
|
|
Expect(perms.AllowedUrls).To(Equal([]string{"wss://api.example.com/ws", "wss://cdn.example.com/*"}))
|
|
})
|
|
|
|
It("should fail if allowedUrls is empty", func() {
|
|
permData := &schema.PluginManifestPermissionsWebsocket{
|
|
Reason: "Need to connect to WebSocket API",
|
|
AllowLocalNetwork: false,
|
|
AllowedUrls: []string{},
|
|
}
|
|
|
|
_, err := parseWebSocketPermissions(permData)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("allowedUrls must contain at least one URL pattern"))
|
|
})
|
|
|
|
It("should handle wildcard patterns", func() {
|
|
permData := &schema.PluginManifestPermissionsWebsocket{
|
|
Reason: "Need to connect to any WebSocket",
|
|
AllowLocalNetwork: true,
|
|
AllowedUrls: []string{"wss://*"},
|
|
}
|
|
|
|
perms, err := parseWebSocketPermissions(permData)
|
|
Expect(err).To(BeNil())
|
|
Expect(perms.AllowLocalNetwork).To(BeTrue())
|
|
Expect(perms.AllowedUrls).To(Equal([]string{"wss://*"}))
|
|
})
|
|
|
|
Context("URL matching", func() {
|
|
var perms *webSocketPermissions
|
|
|
|
BeforeEach(func() {
|
|
permData := &schema.PluginManifestPermissionsWebsocket{
|
|
Reason: "Need to connect to external services",
|
|
AllowLocalNetwork: true,
|
|
AllowedUrls: []string{"wss://api.example.com/*", "ws://localhost:8080"},
|
|
}
|
|
var err error
|
|
perms, err = parseWebSocketPermissions(permData)
|
|
Expect(err).To(BeNil())
|
|
})
|
|
|
|
It("should allow connections to URLs matching patterns", func() {
|
|
err := perms.IsConnectionAllowed("wss://api.example.com/v1/stream")
|
|
Expect(err).To(BeNil())
|
|
|
|
err = perms.IsConnectionAllowed("ws://localhost:8080")
|
|
Expect(err).To(BeNil())
|
|
})
|
|
|
|
It("should deny connections to URLs not matching patterns", func() {
|
|
err := perms.IsConnectionAllowed("wss://malicious.com/stream")
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("does not match any allowed URL patterns"))
|
|
})
|
|
})
|
|
})
|
|
})
|