2022-10-19 05:09:09 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConfig_CertificatesPath(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
if dir := c.CertificatesPath(); dir == "" {
|
|
|
|
t.Fatal("certificates path is empty")
|
|
|
|
} else if !strings.HasPrefix(dir, c.ConfigPath()) {
|
|
|
|
t.Fatalf("unexpected certificates path: %s", dir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_TLSEmail(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.Equal(t, "", c.TLSEmail())
|
|
|
|
c.options.TLSEmail = "hello@example.com"
|
|
|
|
assert.Equal(t, "hello@example.com", c.TLSEmail())
|
|
|
|
c.options.TLSEmail = "hello"
|
|
|
|
assert.Equal(t, "", c.TLSEmail())
|
|
|
|
c.options.TLSEmail = ""
|
|
|
|
assert.Equal(t, "", c.TLSEmail())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_TLSCert(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2023-07-15 12:01:06 +02:00
|
|
|
c.options.DefaultTLS = false
|
|
|
|
assert.Equal(t, "", c.TLSCert())
|
|
|
|
c.options.DefaultTLS = true
|
2023-06-28 16:50:04 +02:00
|
|
|
assert.True(t, strings.HasSuffix(c.TLSCert(), "photoprism.crt"))
|
2023-07-15 12:01:06 +02:00
|
|
|
c.options.DefaultTLS = false
|
|
|
|
assert.Equal(t, "", c.TLSCert())
|
2022-10-19 05:09:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_TLSKey(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
2023-07-15 12:01:06 +02:00
|
|
|
c.options.DefaultTLS = false
|
|
|
|
assert.Equal(t, "", c.TLSKey())
|
|
|
|
c.options.DefaultTLS = true
|
2023-06-28 16:50:04 +02:00
|
|
|
assert.True(t, strings.HasSuffix(c.TLSKey(), "photoprism.key"))
|
2023-07-15 12:01:06 +02:00
|
|
|
c.options.DefaultTLS = false
|
|
|
|
assert.Equal(t, "", c.TLSKey())
|
2022-10-19 05:09:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_TLS(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
cert, key := c.TLS()
|
|
|
|
|
|
|
|
assert.Equal(t, "", cert)
|
|
|
|
assert.Equal(t, "", key)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_DisableTLS(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.True(t, c.DisableTLS())
|
|
|
|
}
|
2023-07-15 12:01:06 +02:00
|
|
|
|
|
|
|
func TestConfig_DefaultTLS(t *testing.T) {
|
|
|
|
c := NewConfig(CliTestContext())
|
|
|
|
|
|
|
|
assert.False(t, c.DefaultTLS())
|
|
|
|
}
|