mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-01 07:21:17 +00:00
add permission validation for scrobble retriever
This commit is contained in:
parent
3c77910bfb
commit
885eda0674
@ -53,10 +53,14 @@ func ParseManifest(data []byte) (*Manifest, error) {
|
||||
// This validates rules like "SubsonicAPI permission requires users permission".
|
||||
func (m *Manifest) Validate() error {
|
||||
// SubsonicAPI permission requires users permission
|
||||
if m.Permissions != nil && m.Permissions.Subsonicapi != nil {
|
||||
if m.Permissions.Users == nil {
|
||||
if m.Permissions != nil && m.Permissions.Users == nil {
|
||||
if m.Permissions.Subsonicapi != nil {
|
||||
return fmt.Errorf("'subsonicapi' permission requires 'users' permission to be declared")
|
||||
}
|
||||
|
||||
if m.Permissions.ScrobbleRetriever != nil {
|
||||
return fmt.Errorf("'scrobbleRetriever' permission requires 'users' permission to be declared")
|
||||
}
|
||||
}
|
||||
|
||||
// Matcher returns library content, so it requires the library permission (which
|
||||
|
||||
@ -222,6 +222,36 @@ var _ = Describe("Manifest", func() {
|
||||
Expect(err.Error()).To(ContainSubstring("library"))
|
||||
})
|
||||
|
||||
It("validates manifest with scrobbleRetriever and users permissions", func() {
|
||||
m := &Manifest{
|
||||
Name: "Test",
|
||||
Author: "Author",
|
||||
Version: "1.0.0",
|
||||
Permissions: &Permissions{
|
||||
ScrobbleRetriever: &ScrobbleRetrieverPermission{},
|
||||
Users: &UsersPermission{},
|
||||
},
|
||||
}
|
||||
|
||||
err := m.Validate()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
It("returns error when scrobbleRetriever without users permission", func() {
|
||||
m := &Manifest{
|
||||
Name: "Test",
|
||||
Author: "Author",
|
||||
Version: "1.0.0",
|
||||
Permissions: &Permissions{
|
||||
ScrobbleRetriever: &ScrobbleRetrieverPermission{},
|
||||
},
|
||||
}
|
||||
|
||||
err := m.Validate()
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("scrobbleRetriever"))
|
||||
})
|
||||
|
||||
It("validates manifest without subsonicapi", func() {
|
||||
m := &Manifest{
|
||||
Name: "Test",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user