2020-07-13 15:37:43 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-11-21 17:08:41 +00:00
|
|
|
|
2022-09-28 07:01:17 +00:00
|
|
|
"github.com/photoprism/photoprism/internal/customize"
|
|
|
|
|
2020-11-21 17:08:41 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-09-28 07:01:17 +00:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/acl"
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
2020-07-13 15:37:43 +00:00
|
|
|
)
|
|
|
|
|
2022-09-28 07:01:17 +00:00
|
|
|
func TestConfig_ClientConfig(t *testing.T) {
|
|
|
|
t.Run("TestConfig", func(t *testing.T) {
|
|
|
|
c := TestConfig()
|
|
|
|
result := c.ClientPublic()
|
|
|
|
assert.IsType(t, ClientConfig{}, result)
|
|
|
|
assert.Equal(t, true, result.Public)
|
|
|
|
})
|
|
|
|
t.Run("TestErrorConfig", func(t *testing.T) {
|
|
|
|
c := NewTestErrorConfig()
|
|
|
|
result2 := c.ClientPublic()
|
|
|
|
assert.IsType(t, ClientConfig{}, result2)
|
|
|
|
assert.Equal(t, false, result2.Public)
|
|
|
|
})
|
|
|
|
t.Run("Values", func(t *testing.T) {
|
|
|
|
c := TestConfig()
|
|
|
|
|
|
|
|
cfg := c.ClientRole(acl.RoleAdmin)
|
|
|
|
|
|
|
|
assert.IsType(t, ClientConfig{}, cfg)
|
|
|
|
|
|
|
|
if cfg.JsUri == "" {
|
|
|
|
t.Error("the JavaScript asset URI must not be empty, make sure that the frontend has been built")
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.CssUri == "" {
|
|
|
|
t.Error("the CSS asset URI must not be empty, make sure that the frontend has been built")
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.NotEmpty(t, cfg.Name)
|
|
|
|
assert.NotEmpty(t, cfg.Version)
|
|
|
|
assert.NotEmpty(t, cfg.Copyright)
|
|
|
|
assert.NotEmpty(t, cfg.Thumbs)
|
|
|
|
assert.NotEmpty(t, cfg.ManifestUri)
|
|
|
|
assert.Equal(t, true, cfg.Debug)
|
|
|
|
assert.Equal(t, false, cfg.Demo)
|
|
|
|
assert.Equal(t, true, cfg.Sponsor)
|
|
|
|
assert.Equal(t, false, cfg.ReadOnly)
|
|
|
|
|
|
|
|
// Counts.
|
|
|
|
assert.NotEmpty(t, cfg.Count.All)
|
|
|
|
assert.NotEmpty(t, cfg.Count.Photos)
|
|
|
|
assert.LessOrEqual(t, 20, cfg.Count.Photos)
|
|
|
|
assert.LessOrEqual(t, 1, cfg.Count.Live)
|
|
|
|
assert.LessOrEqual(t, 4, cfg.Count.Videos)
|
|
|
|
assert.LessOrEqual(t, cfg.Count.Photos+cfg.Count.Live+cfg.Count.Videos, cfg.Count.All)
|
|
|
|
assert.LessOrEqual(t, 6, cfg.Count.Cameras)
|
|
|
|
assert.LessOrEqual(t, 1, cfg.Count.Lenses)
|
|
|
|
assert.LessOrEqual(t, 13, cfg.Count.Review)
|
|
|
|
assert.LessOrEqual(t, 1, cfg.Count.Private)
|
|
|
|
assert.LessOrEqual(t, 4, cfg.Count.Albums)
|
|
|
|
})
|
2020-07-13 15:37:43 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 07:01:17 +00:00
|
|
|
func TestConfig_ClientShareConfig(t *testing.T) {
|
2020-07-13 18:25:47 +00:00
|
|
|
config := TestConfig()
|
2022-09-28 07:01:17 +00:00
|
|
|
result := config.ClientShare()
|
2020-07-13 15:37:43 +00:00
|
|
|
assert.IsType(t, ClientConfig{}, result)
|
|
|
|
assert.Equal(t, true, result.Public)
|
2020-07-13 18:25:47 +00:00
|
|
|
assert.Equal(t, false, result.Experimental)
|
|
|
|
assert.Equal(t, true, result.ReadOnly)
|
2020-07-13 15:37:43 +00:00
|
|
|
}
|
2020-07-13 17:25:27 +00:00
|
|
|
|
2022-09-28 07:01:17 +00:00
|
|
|
func TestConfig_ClientRoleConfig(t *testing.T) {
|
|
|
|
c := NewTestConfig("config")
|
|
|
|
|
|
|
|
c.Options().AuthMode = AuthModePasswd
|
|
|
|
c.Options().Public = false
|
|
|
|
|
|
|
|
assert.Equal(t, AuthModePasswd, c.AuthMode())
|
|
|
|
|
|
|
|
adminFeatures := c.ClientRole(acl.RoleAdmin).Settings.Features
|
|
|
|
|
|
|
|
t.Run("RoleAdmin", func(t *testing.T) {
|
|
|
|
cfg := c.ClientRole(acl.RoleAdmin)
|
|
|
|
assert.IsType(t, ClientConfig{}, cfg)
|
|
|
|
assert.Equal(t, false, cfg.Public)
|
|
|
|
|
|
|
|
f := cfg.Settings.Features
|
|
|
|
assert.Equal(t, adminFeatures, f)
|
|
|
|
|
|
|
|
expected := customize.FeatureSettings{
|
|
|
|
Account: false,
|
|
|
|
Advanced: false,
|
|
|
|
Albums: true,
|
|
|
|
Archive: true,
|
|
|
|
Delete: false,
|
|
|
|
Download: true,
|
|
|
|
Edit: true,
|
|
|
|
Estimates: true,
|
|
|
|
Favorites: true,
|
|
|
|
Files: true,
|
|
|
|
Folders: true,
|
|
|
|
Import: true,
|
|
|
|
Labels: true,
|
|
|
|
Library: true,
|
|
|
|
Logs: true,
|
|
|
|
Moments: true,
|
|
|
|
People: true,
|
|
|
|
Places: true,
|
|
|
|
Private: true,
|
|
|
|
Ratings: true,
|
|
|
|
Reactions: true,
|
|
|
|
Review: true,
|
|
|
|
Search: true,
|
|
|
|
Settings: true,
|
|
|
|
Share: true,
|
|
|
|
Sync: true,
|
|
|
|
Upload: true,
|
|
|
|
Videos: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, expected, f)
|
|
|
|
})
|
|
|
|
t.Run("RoleVisitor", func(t *testing.T) {
|
|
|
|
cfg := c.ClientRole(acl.RoleVisitor)
|
|
|
|
f := cfg.Settings.Features
|
|
|
|
|
|
|
|
assert.NotEqual(t, adminFeatures, f)
|
|
|
|
|
|
|
|
expected := customize.FeatureSettings{
|
|
|
|
Account: false,
|
|
|
|
Advanced: false,
|
|
|
|
Albums: true,
|
|
|
|
Archive: false,
|
|
|
|
Delete: false,
|
|
|
|
Download: true,
|
|
|
|
Edit: false,
|
|
|
|
Estimates: true,
|
|
|
|
Favorites: false,
|
|
|
|
Files: false,
|
|
|
|
Folders: false,
|
|
|
|
Import: false,
|
|
|
|
Labels: false,
|
|
|
|
Library: false,
|
|
|
|
Logs: false,
|
|
|
|
Moments: false,
|
|
|
|
People: false,
|
2022-09-29 22:42:19 +00:00
|
|
|
Places: true,
|
2022-09-28 07:01:17 +00:00
|
|
|
Private: false,
|
|
|
|
Ratings: false,
|
|
|
|
Reactions: false,
|
|
|
|
Review: false,
|
|
|
|
Search: false,
|
|
|
|
Settings: false,
|
|
|
|
Share: false,
|
|
|
|
Sync: false,
|
|
|
|
Upload: false,
|
|
|
|
Videos: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, expected, f)
|
|
|
|
})
|
|
|
|
t.Run("RoleUnauthorized", func(t *testing.T) {
|
|
|
|
cfg := c.ClientRole(acl.RoleUnauthorized)
|
|
|
|
f := cfg.Settings.Features
|
|
|
|
|
|
|
|
assert.NotEqual(t, adminFeatures, f)
|
|
|
|
assert.False(t, f.Search)
|
|
|
|
assert.False(t, f.Videos)
|
|
|
|
assert.False(t, f.Albums)
|
|
|
|
assert.False(t, f.Moments)
|
|
|
|
assert.False(t, f.Labels)
|
|
|
|
assert.False(t, f.People)
|
|
|
|
assert.False(t, f.Settings)
|
|
|
|
assert.False(t, f.Edit)
|
|
|
|
assert.False(t, f.Private)
|
|
|
|
assert.False(t, f.Advanced)
|
|
|
|
assert.False(t, f.Upload)
|
|
|
|
assert.False(t, f.Download)
|
|
|
|
assert.False(t, f.Sync)
|
|
|
|
assert.False(t, f.Delete)
|
|
|
|
assert.False(t, f.Import)
|
|
|
|
assert.False(t, f.Library)
|
|
|
|
assert.False(t, f.Logs)
|
|
|
|
assert.False(t, f.Review)
|
|
|
|
assert.False(t, f.Share)
|
|
|
|
assert.False(t, f.Favorites)
|
|
|
|
assert.False(t, f.Reactions)
|
|
|
|
assert.False(t, f.Ratings)
|
|
|
|
})
|
|
|
|
t.Run("RoleUnknown", func(t *testing.T) {
|
|
|
|
cfg := c.ClientRole(acl.RoleUnknown)
|
|
|
|
f := cfg.Settings.Features
|
|
|
|
|
|
|
|
assert.NotEqual(t, adminFeatures, f)
|
|
|
|
assert.False(t, f.Search)
|
|
|
|
assert.False(t, f.Videos)
|
|
|
|
assert.False(t, f.Albums)
|
|
|
|
assert.False(t, f.Settings)
|
|
|
|
assert.False(t, f.Edit)
|
|
|
|
assert.False(t, f.Private)
|
|
|
|
assert.False(t, f.Advanced)
|
|
|
|
assert.False(t, f.Upload)
|
|
|
|
assert.False(t, f.Download)
|
|
|
|
assert.False(t, f.Sync)
|
|
|
|
assert.False(t, f.Delete)
|
|
|
|
assert.False(t, f.Import)
|
|
|
|
assert.False(t, f.Library)
|
|
|
|
assert.False(t, f.Logs)
|
|
|
|
assert.False(t, f.Review)
|
|
|
|
assert.False(t, f.Share)
|
|
|
|
assert.False(t, f.Favorites)
|
|
|
|
assert.False(t, f.Reactions)
|
|
|
|
assert.False(t, f.Ratings)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_ClientSessionConfig(t *testing.T) {
|
|
|
|
c := NewTestConfig("config")
|
|
|
|
|
|
|
|
c.Options().AuthMode = AuthModePasswd
|
|
|
|
c.Options().Public = false
|
|
|
|
|
|
|
|
assert.Equal(t, AuthModePasswd, c.AuthMode())
|
|
|
|
|
|
|
|
adminFeatures := c.ClientRole(acl.RoleAdmin).Settings.Features
|
|
|
|
|
|
|
|
t.Run("RoleAdmin", func(t *testing.T) {
|
|
|
|
cfg := c.ClientSession(entity.SessionFixtures.Pointer("alice"))
|
|
|
|
assert.IsType(t, ClientConfig{}, cfg)
|
|
|
|
assert.Equal(t, false, cfg.Public)
|
|
|
|
|
|
|
|
f := cfg.Settings.Features
|
|
|
|
assert.Equal(t, adminFeatures, f)
|
|
|
|
|
|
|
|
assert.True(t, f.Search)
|
|
|
|
assert.True(t, f.Videos)
|
|
|
|
assert.True(t, f.Albums)
|
|
|
|
assert.True(t, f.Moments)
|
|
|
|
assert.True(t, f.Labels)
|
|
|
|
assert.True(t, f.People)
|
|
|
|
assert.True(t, f.Settings)
|
|
|
|
assert.True(t, f.Edit)
|
|
|
|
assert.True(t, f.Private)
|
|
|
|
assert.False(t, f.Advanced)
|
|
|
|
assert.True(t, f.Upload)
|
|
|
|
assert.True(t, f.Download)
|
|
|
|
assert.True(t, f.Sync)
|
|
|
|
assert.False(t, f.Delete)
|
|
|
|
assert.True(t, f.Import)
|
|
|
|
assert.True(t, f.Library)
|
|
|
|
assert.True(t, f.Logs)
|
|
|
|
assert.True(t, f.Review)
|
|
|
|
assert.True(t, f.Share)
|
|
|
|
})
|
|
|
|
t.Run("RoleVisitor", func(t *testing.T) {
|
|
|
|
cfg := c.ClientSession(entity.SessionFixtures.Pointer("visitor"))
|
|
|
|
|
|
|
|
assert.IsType(t, ClientConfig{}, cfg)
|
|
|
|
assert.Equal(t, false, cfg.Public)
|
|
|
|
|
|
|
|
f := cfg.Settings.Features
|
|
|
|
assert.NotEqual(t, adminFeatures, f)
|
|
|
|
|
|
|
|
assert.False(t, f.Search)
|
|
|
|
assert.False(t, f.Videos)
|
|
|
|
assert.True(t, f.Albums)
|
|
|
|
assert.False(t, f.Moments)
|
|
|
|
assert.False(t, f.Labels)
|
|
|
|
assert.False(t, f.People)
|
|
|
|
assert.False(t, f.Settings)
|
|
|
|
assert.False(t, f.Edit)
|
|
|
|
assert.False(t, f.Private)
|
|
|
|
assert.False(t, f.Advanced)
|
|
|
|
assert.False(t, f.Upload)
|
|
|
|
assert.True(t, f.Download)
|
|
|
|
assert.False(t, f.Sync)
|
|
|
|
assert.False(t, f.Delete)
|
|
|
|
assert.False(t, f.Import)
|
|
|
|
assert.False(t, f.Library)
|
|
|
|
assert.False(t, f.Logs)
|
|
|
|
assert.False(t, f.Review)
|
|
|
|
assert.False(t, f.Share)
|
|
|
|
})
|
|
|
|
t.Run("RoleUnauthorized", func(t *testing.T) {
|
|
|
|
sess := entity.SessionFixtures.Pointer("unauthorized")
|
|
|
|
|
|
|
|
cfg := c.ClientSession(sess)
|
|
|
|
|
|
|
|
assert.IsType(t, ClientConfig{}, cfg)
|
|
|
|
assert.Equal(t, false, cfg.Public)
|
|
|
|
|
|
|
|
f := cfg.Settings.Features
|
|
|
|
assert.NotEqual(t, adminFeatures, f)
|
|
|
|
|
|
|
|
assert.False(t, f.Search)
|
|
|
|
assert.False(t, f.Videos)
|
|
|
|
assert.False(t, f.Albums)
|
|
|
|
assert.False(t, f.Moments)
|
|
|
|
assert.False(t, f.Labels)
|
|
|
|
assert.False(t, f.People)
|
|
|
|
assert.False(t, f.Settings)
|
|
|
|
assert.False(t, f.Edit)
|
|
|
|
assert.False(t, f.Private)
|
|
|
|
assert.False(t, f.Advanced)
|
|
|
|
assert.False(t, f.Upload)
|
|
|
|
assert.False(t, f.Download)
|
|
|
|
assert.False(t, f.Sync)
|
|
|
|
assert.False(t, f.Delete)
|
|
|
|
assert.False(t, f.Import)
|
|
|
|
assert.False(t, f.Library)
|
|
|
|
assert.False(t, f.Logs)
|
|
|
|
assert.False(t, f.Review)
|
|
|
|
assert.False(t, f.Share)
|
|
|
|
})
|
|
|
|
t.Run("Bob", func(t *testing.T) {
|
|
|
|
cfg := c.ClientSession(entity.SessionFixtures.Pointer("bob"))
|
|
|
|
|
|
|
|
assert.IsType(t, ClientConfig{}, cfg)
|
|
|
|
assert.Equal(t, false, cfg.Public)
|
|
|
|
|
|
|
|
f := cfg.Settings.Features
|
|
|
|
|
|
|
|
assert.True(t, f.Search)
|
|
|
|
assert.True(t, f.Videos)
|
|
|
|
assert.True(t, f.Albums)
|
|
|
|
assert.True(t, f.Moments)
|
|
|
|
assert.True(t, f.Labels)
|
|
|
|
assert.True(t, f.People)
|
|
|
|
assert.True(t, f.Settings)
|
|
|
|
assert.True(t, f.Edit)
|
|
|
|
assert.True(t, f.Private)
|
|
|
|
assert.False(t, f.Advanced)
|
|
|
|
assert.True(t, f.Upload)
|
|
|
|
assert.True(t, f.Download)
|
|
|
|
assert.True(t, f.Sync)
|
|
|
|
assert.False(t, f.Delete)
|
|
|
|
assert.True(t, f.Import)
|
|
|
|
assert.True(t, f.Library)
|
|
|
|
assert.True(t, f.Logs)
|
|
|
|
assert.True(t, f.Review)
|
|
|
|
assert.True(t, f.Share)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-13 17:25:27 +00:00
|
|
|
func TestConfig_Flags(t *testing.T) {
|
2020-07-13 18:25:47 +00:00
|
|
|
config := TestConfig()
|
2020-12-18 19:42:12 +00:00
|
|
|
config.options.Experimental = true
|
|
|
|
config.options.ReadOnly = true
|
2021-02-18 10:41:51 +00:00
|
|
|
config.settings.UI.Scrollbar = false
|
2020-07-13 17:25:27 +00:00
|
|
|
|
|
|
|
result := config.Flags()
|
2022-03-16 16:41:50 +00:00
|
|
|
assert.Equal(t, []string{"public", "debug", "test", "sponsor", "experimental", "readonly", "settings", "hide-scrollbar"}, result)
|
2020-07-13 18:25:47 +00:00
|
|
|
|
2020-12-18 19:42:12 +00:00
|
|
|
config.options.Experimental = false
|
|
|
|
config.options.ReadOnly = false
|
2020-07-13 17:25:27 +00:00
|
|
|
}
|