2019-06-02 03:18:09 +02:00
|
|
|
// Copyright 2019 Frédéric Guillot. All rights reserved.
|
2018-02-01 06:57:20 +01:00
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
package config // import "miniflux.app/config"
|
2018-02-01 06:57:20 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2019-06-02 03:18:09 +02:00
|
|
|
func TestDebugModeOn(t *testing.T) {
|
2018-09-24 00:23:46 +02:00
|
|
|
os.Clearenv()
|
2019-06-02 03:18:09 +02:00
|
|
|
os.Setenv("DEBUG", "1")
|
2018-09-24 00:23:46 +02:00
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2018-09-24 00:23:46 +02:00
|
|
|
}
|
|
|
|
|
2019-06-02 03:18:09 +02:00
|
|
|
if !opts.HasDebugMode() {
|
|
|
|
t.Fatalf(`Unexpected debug mode value, got "%v"`, opts.HasDebugMode())
|
2018-09-24 00:23:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 03:18:09 +02:00
|
|
|
func TestDebugModeOff(t *testing.T) {
|
2018-02-04 00:33:17 +01:00
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2018-02-04 00:33:17 +01:00
|
|
|
}
|
|
|
|
|
2019-06-02 03:18:09 +02:00
|
|
|
if opts.HasDebugMode() {
|
|
|
|
t.Fatalf(`Unexpected debug mode value, got "%v"`, opts.HasDebugMode())
|
2018-02-04 00:33:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCustomBaseURL(t *testing.T) {
|
2018-02-01 06:57:20 +01:00
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("BASE_URL", "http://example.org")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2018-02-01 06:57:20 +01:00
|
|
|
}
|
2018-02-04 00:33:17 +01:00
|
|
|
|
2019-06-02 03:18:09 +02:00
|
|
|
if opts.BaseURL() != "http://example.org" {
|
|
|
|
t.Fatalf(`Unexpected base URL, got "%s"`, opts.BaseURL())
|
2018-02-04 00:33:17 +01:00
|
|
|
}
|
|
|
|
|
2019-06-02 03:18:09 +02:00
|
|
|
if opts.RootURL() != "http://example.org" {
|
|
|
|
t.Fatalf(`Unexpected root URL, got "%s"`, opts.RootURL())
|
|
|
|
}
|
|
|
|
|
|
|
|
if opts.BasePath() != "" {
|
|
|
|
t.Fatalf(`Unexpected base path, got "%s"`, opts.BasePath())
|
2018-02-04 00:33:17 +01:00
|
|
|
}
|
2018-02-01 06:57:20 +01:00
|
|
|
}
|
|
|
|
|
2018-02-04 00:33:17 +01:00
|
|
|
func TestCustomBaseURLWithTrailingSlash(t *testing.T) {
|
2018-02-01 06:57:20 +01:00
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("BASE_URL", "http://example.org/folder/")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2018-02-01 06:57:20 +01:00
|
|
|
}
|
2018-02-04 00:33:17 +01:00
|
|
|
|
2019-06-02 03:18:09 +02:00
|
|
|
if opts.BaseURL() != "http://example.org/folder" {
|
|
|
|
t.Fatalf(`Unexpected base URL, got "%s"`, opts.BaseURL())
|
2018-02-04 00:33:17 +01:00
|
|
|
}
|
|
|
|
|
2019-06-02 03:18:09 +02:00
|
|
|
if opts.RootURL() != "http://example.org" {
|
|
|
|
t.Fatalf(`Unexpected root URL, got "%s"`, opts.RootURL())
|
|
|
|
}
|
|
|
|
|
|
|
|
if opts.BasePath() != "/folder" {
|
|
|
|
t.Fatalf(`Unexpected base path, got "%s"`, opts.BasePath())
|
2018-02-04 00:33:17 +01:00
|
|
|
}
|
2018-02-01 06:57:20 +01:00
|
|
|
}
|
|
|
|
|
2018-07-07 23:01:02 +02:00
|
|
|
func TestBaseURLWithoutScheme(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("BASE_URL", "example.org/folder/")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
_, err := NewParser().ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf(`Parsing must fail`)
|
2018-07-07 23:01:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBaseURLWithInvalidScheme(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("BASE_URL", "ftp://example.org/folder/")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
_, err := NewParser().ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf(`Parsing must fail`)
|
2018-07-07 23:01:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
func TestInvalidBaseURL(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("BASE_URL", "http://example|org")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
_, err := NewParser().ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf(`Parsing must fail`)
|
2018-09-24 00:23:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-04 00:33:17 +01:00
|
|
|
func TestDefaultBaseURL(t *testing.T) {
|
2018-02-01 06:57:20 +01:00
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2018-02-01 06:57:20 +01:00
|
|
|
}
|
2018-02-04 00:33:17 +01:00
|
|
|
|
2019-06-02 03:18:09 +02:00
|
|
|
if opts.BaseURL() != defaultBaseURL {
|
|
|
|
t.Fatalf(`Unexpected base URL, got "%s"`, opts.BaseURL())
|
2018-02-04 00:33:17 +01:00
|
|
|
}
|
|
|
|
|
2019-06-02 03:18:09 +02:00
|
|
|
if opts.RootURL() != defaultBaseURL {
|
|
|
|
t.Fatalf(`Unexpected root URL, got "%s"`, opts.RootURL())
|
|
|
|
}
|
|
|
|
|
|
|
|
if opts.BasePath() != "" {
|
|
|
|
t.Fatalf(`Unexpected base path, got "%s"`, opts.BasePath())
|
2018-02-04 00:33:17 +01:00
|
|
|
}
|
2018-02-01 06:57:20 +01:00
|
|
|
}
|
2018-02-04 00:54:02 +01:00
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
func TestDatabaseURL(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("DATABASE_URL", "foobar")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := "foobar"
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.DatabaseURL()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Errorf(`Unexpected DATABASE_URL value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
if opts.IsDefaultDatabaseURL() {
|
|
|
|
t.Errorf(`This is not the default database URL and it should returns false`)
|
2018-09-24 00:23:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultDatabaseURLValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
2019-06-02 03:18:09 +02:00
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := defaultDatabaseURL
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.DatabaseURL()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Errorf(`Unexpected DATABASE_URL value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !opts.IsDefaultDatabaseURL() {
|
|
|
|
t.Errorf(`This is the default database URL and it should returns true`)
|
2018-09-24 00:23:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultDatabaseMaxConnsValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := defaultDatabaseMaxConns
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.DatabaseMaxConns()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected DATABASE_MAX_CONNS value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 03:18:09 +02:00
|
|
|
func TestDatabaseMaxConns(t *testing.T) {
|
2018-09-24 00:23:46 +02:00
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("DATABASE_MAX_CONNS", "42")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := 42
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.DatabaseMaxConns()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected DATABASE_MAX_CONNS value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultDatabaseMinConnsValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := defaultDatabaseMinConns
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.DatabaseMinConns()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected DATABASE_MIN_CONNS value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDatabaseMinConns(t *testing.T) {
|
2018-02-04 00:54:02 +01:00
|
|
|
os.Clearenv()
|
2018-09-24 00:23:46 +02:00
|
|
|
os.Setenv("DATABASE_MIN_CONNS", "42")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := 42
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.DatabaseMinConns()
|
2018-02-04 00:54:02 +01:00
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected DATABASE_MIN_CONNS value, got %v instead of %v`, result, expected)
|
2018-02-04 00:54:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
func TestListenAddr(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("LISTEN_ADDR", "foobar")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := "foobar"
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.ListenAddr()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected LISTEN_ADDR value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestListenAddrWithPortDefined(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("PORT", "3000")
|
|
|
|
os.Setenv("LISTEN_ADDR", "foobar")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := ":3000"
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.ListenAddr()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected LISTEN_ADDR value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultListenAddrValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
2019-06-02 03:18:09 +02:00
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := defaultListenAddr
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.ListenAddr()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected LISTEN_ADDR value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCertFile(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("CERT_FILE", "foobar")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := "foobar"
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.CertFile()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected CERT_FILE value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultCertFileValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
2019-06-02 03:18:09 +02:00
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := defaultCertFile
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.CertFile()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected CERT_FILE value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestKeyFile(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("KEY_FILE", "foobar")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := "foobar"
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.CertKeyFile()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected KEY_FILE value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultKeyFileValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
2019-06-02 03:18:09 +02:00
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := defaultKeyFile
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.CertKeyFile()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected KEY_FILE value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCertDomain(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("CERT_DOMAIN", "example.org")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := "example.org"
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.CertDomain()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected CERT_DOMAIN value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultCertDomainValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
2019-06-02 03:18:09 +02:00
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := defaultCertDomain
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.CertDomain()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected CERT_DOMAIN value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-15 20:47:39 +02:00
|
|
|
func TestDefaultCleanupFrequencyHoursValue(t *testing.T) {
|
2018-09-24 00:23:46 +02:00
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2019-09-15 20:47:39 +02:00
|
|
|
expected := defaultCleanupFrequencyHours
|
|
|
|
result := opts.CleanupFrequencyHours()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
2019-09-15 20:47:39 +02:00
|
|
|
t.Fatalf(`Unexpected CLEANUP_FREQUENCY_HOURS value, got %v instead of %v`, result, expected)
|
2018-09-24 00:23:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-15 20:47:39 +02:00
|
|
|
func TestCleanupFrequencyHours(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("CLEANUP_FREQUENCY_HOURS", "42")
|
|
|
|
os.Setenv("CLEANUP_FREQUENCY", "19")
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := 42
|
|
|
|
result := opts.CleanupFrequencyHours()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected CLEANUP_FREQUENCY_HOURS value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultCleanupArchiveReadDaysValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := 60
|
|
|
|
result := opts.CleanupArchiveReadDays()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected CLEANUP_ARCHIVE_READ_DAYS value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCleanupArchiveReadDays(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("CLEANUP_ARCHIVE_READ_DAYS", "7")
|
|
|
|
os.Setenv("ARCHIVE_READ_DAYS", "19")
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := 7
|
|
|
|
result := opts.CleanupArchiveReadDays()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected CLEANUP_ARCHIVE_READ_DAYS value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultCleanupRemoveSessionsDaysValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := 30
|
|
|
|
result := opts.CleanupRemoveSessionsDays()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected CLEANUP_REMOVE_SESSIONS_DAYS value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCleanupRemoveSessionsDays(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("CLEANUP_REMOVE_SESSIONS_DAYS", "7")
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := 7
|
|
|
|
result := opts.CleanupRemoveSessionsDays()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected CLEANUP_REMOVE_SESSIONS_DAYS value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
func TestDefaultWorkerPoolSizeValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := defaultWorkerPoolSize
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.WorkerPoolSize()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected WORKER_POOL_SIZE value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWorkerPoolSize(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("WORKER_POOL_SIZE", "42")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := 42
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.WorkerPoolSize()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected WORKER_POOL_SIZE value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefautPollingFrequencyValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := defaultPollingFrequency
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.PollingFrequency()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected POLLING_FREQUENCY value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPollingFrequency(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("POLLING_FREQUENCY", "42")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := 42
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.PollingFrequency()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected POLLING_FREQUENCY value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultBatchSizeValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := defaultBatchSize
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.BatchSize()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected BATCH_SIZE value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBatchSize(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("BATCH_SIZE", "42")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := 42
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.BatchSize()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected BATCH_SIZE value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-25 23:06:56 +02:00
|
|
|
func TestDefautPollingSchedulerValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := defaultPollingScheduler
|
|
|
|
result := opts.PollingScheduler()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected POLLING_SCHEDULER value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPollingScheduler(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("POLLING_SCHEDULER", "entry_count_based")
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := "entry_count_based"
|
|
|
|
result := opts.PollingScheduler()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected POLLING_SCHEDULER value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefautSchedulerCountBasedMaxIntervalValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
2020-05-25 23:59:15 +02:00
|
|
|
expected := defaultSchedulerEntryFrequencyMaxInterval
|
|
|
|
result := opts.SchedulerEntryFrequencyMaxInterval()
|
2020-05-25 23:06:56 +02:00
|
|
|
|
|
|
|
if result != expected {
|
2020-05-25 23:59:15 +02:00
|
|
|
t.Fatalf(`Unexpected SCHEDULER_ENTRY_FREQUENCY_MAX_INTERVAL value, got %v instead of %v`, result, expected)
|
2020-05-25 23:06:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefautSchedulerCountBasedMaxInterval(t *testing.T) {
|
|
|
|
os.Clearenv()
|
2020-05-25 23:59:15 +02:00
|
|
|
os.Setenv("SCHEDULER_ENTRY_FREQUENCY_MAX_INTERVAL", "30")
|
2020-05-25 23:06:56 +02:00
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := 30
|
2020-05-25 23:59:15 +02:00
|
|
|
result := opts.SchedulerEntryFrequencyMaxInterval()
|
2020-05-25 23:06:56 +02:00
|
|
|
|
|
|
|
if result != expected {
|
2020-05-25 23:59:15 +02:00
|
|
|
t.Fatalf(`Unexpected SCHEDULER_ENTRY_FREQUENCY_MAX_INTERVAL value, got %v instead of %v`, result, expected)
|
2020-05-25 23:06:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefautSchedulerCountBasedMinIntervalValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
2020-05-25 23:59:15 +02:00
|
|
|
expected := defaultSchedulerEntryFrequencyMinInterval
|
|
|
|
result := opts.SchedulerEntryFrequencyMinInterval()
|
2020-05-25 23:06:56 +02:00
|
|
|
|
|
|
|
if result != expected {
|
2020-05-25 23:59:15 +02:00
|
|
|
t.Fatalf(`Unexpected SCHEDULER_ENTRY_FREQUENCY_MIN_INTERVAL value, got %v instead of %v`, result, expected)
|
2020-05-25 23:06:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefautSchedulerCountBasedMinInterval(t *testing.T) {
|
|
|
|
os.Clearenv()
|
2020-05-25 23:59:15 +02:00
|
|
|
os.Setenv("SCHEDULER_ENTRY_FREQUENCY_MIN_INTERVAL", "30")
|
2020-05-25 23:06:56 +02:00
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := 30
|
2020-05-25 23:59:15 +02:00
|
|
|
result := opts.SchedulerEntryFrequencyMinInterval()
|
2020-05-25 23:06:56 +02:00
|
|
|
|
|
|
|
if result != expected {
|
2020-05-25 23:59:15 +02:00
|
|
|
t.Fatalf(`Unexpected SCHEDULER_ENTRY_FREQUENCY_MIN_INTERVAL value, got %v instead of %v`, result, expected)
|
2020-05-25 23:06:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-26 06:41:36 +01:00
|
|
|
func TestPollingParsingErrorLimit(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("POLLING_PARSING_ERROR_LIMIT", "100")
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := 100
|
|
|
|
result := opts.PollingParsingErrorLimit()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected POLLING_SCHEDULER value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
func TestOAuth2UserCreationWhenUnset(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := false
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.IsOAuth2UserCreationAllowed()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected OAUTH2_USER_CREATION value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOAuth2UserCreationAdmin(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("OAUTH2_USER_CREATION", "1")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := true
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.IsOAuth2UserCreationAllowed()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected OAUTH2_USER_CREATION value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOAuth2ClientID(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("OAUTH2_CLIENT_ID", "foobar")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := "foobar"
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.OAuth2ClientID()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected OAUTH2_CLIENT_ID value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultOAuth2ClientIDValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
2019-06-02 03:18:09 +02:00
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := defaultOAuth2ClientID
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.OAuth2ClientID()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected OAUTH2_CLIENT_ID value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOAuth2ClientSecret(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("OAUTH2_CLIENT_SECRET", "secret")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := "secret"
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.OAuth2ClientSecret()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected OAUTH2_CLIENT_SECRET value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultOAuth2ClientSecretValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
2019-06-02 03:18:09 +02:00
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := defaultOAuth2ClientSecret
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.OAuth2ClientSecret()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected OAUTH2_CLIENT_SECRET value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOAuth2RedirectURL(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("OAUTH2_REDIRECT_URL", "http://example.org")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := "http://example.org"
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.OAuth2RedirectURL()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected OAUTH2_REDIRECT_URL value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultOAuth2RedirectURLValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
2019-06-02 03:18:09 +02:00
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := defaultOAuth2RedirectURL
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.OAuth2RedirectURL()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected OAUTH2_REDIRECT_URL value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-08 03:45:19 +01:00
|
|
|
func TestOAuth2OidcDiscoveryEndpoint(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("OAUTH2_OIDC_DISCOVERY_ENDPOINT", "http://example.org")
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := "http://example.org"
|
|
|
|
result := opts.OAuth2OidcDiscoveryEndpoint()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected OAUTH2_OIDC_DISCOVERY_ENDPOINT value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultOAuth2OidcDiscoveryEndpointValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := defaultOAuth2OidcDiscoveryEndpoint
|
|
|
|
result := opts.OAuth2OidcDiscoveryEndpoint()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected OAUTH2_REDIRECT_URL value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
func TestOAuth2Provider(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("OAUTH2_PROVIDER", "google")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := "google"
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.OAuth2Provider()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected OAUTH2_PROVIDER value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultOAuth2ProviderValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
2019-06-02 03:18:09 +02:00
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := defaultOAuth2Provider
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.OAuth2Provider()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected OAUTH2_PROVIDER value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHSTSWhenUnset(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := true
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.HasHSTS()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected DISABLE_HSTS value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHSTS(t *testing.T) {
|
2018-02-04 00:54:02 +01:00
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("DISABLE_HSTS", "1")
|
2018-09-24 00:23:46 +02:00
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := false
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.HasHSTS()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected DISABLE_HSTS value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-12 00:54:19 +01:00
|
|
|
func TestDisableHTTPServiceWhenUnset(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-11-12 00:54:19 +01:00
|
|
|
expected := true
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.HasHTTPService()
|
2018-11-12 00:54:19 +01:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected DISABLE_HTTP_SERVICE value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDisableHTTPService(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("DISABLE_HTTP_SERVICE", "1")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-11-12 00:54:19 +01:00
|
|
|
expected := false
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.HasHTTPService()
|
2018-11-12 00:54:19 +01:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected DISABLE_HTTP_SERVICE value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDisableSchedulerServiceWhenUnset(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-11-12 00:54:19 +01:00
|
|
|
expected := true
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.HasSchedulerService()
|
2018-11-12 00:54:19 +01:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected DISABLE_SCHEDULER_SERVICE value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDisableSchedulerService(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("DISABLE_SCHEDULER_SERVICE", "1")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-11-12 00:54:19 +01:00
|
|
|
expected := false
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.HasSchedulerService()
|
2018-11-12 00:54:19 +01:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected DISABLE_SCHEDULER_SERVICE value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
func TestRunMigrationsWhenUnset(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := false
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.RunMigrations()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected RUN_MIGRATIONS value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunMigrations(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("RUN_MIGRATIONS", "yes")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := true
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.RunMigrations()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected RUN_MIGRATIONS value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateAdminWhenUnset(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := false
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.CreateAdmin()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected CREATE_ADMIN value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateAdmin(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("CREATE_ADMIN", "true")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := true
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.CreateAdmin()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected CREATE_ADMIN value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPocketConsumerKeyFromEnvVariable(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("POCKET_CONSUMER_KEY", "something")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := "something"
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.PocketConsumerKey("default")
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected POCKET_CONSUMER_KEY value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPocketConsumerKeyFromUserPrefs(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := "default"
|
2019-06-02 03:18:09 +02:00
|
|
|
result := opts.PocketConsumerKey("default")
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected POCKET_CONSUMER_KEY value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-25 09:36:19 +01:00
|
|
|
func TestProxyOption(t *testing.T) {
|
2018-09-24 00:23:46 +02:00
|
|
|
os.Clearenv()
|
2023-02-25 09:36:19 +01:00
|
|
|
os.Setenv("PROXY_OPTION", "all")
|
2018-09-24 00:23:46 +02:00
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 00:23:46 +02:00
|
|
|
expected := "all"
|
2023-02-25 09:36:19 +01:00
|
|
|
result := opts.ProxyOption()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
2023-02-25 09:36:19 +01:00
|
|
|
t.Fatalf(`Unexpected PROXY_OPTION value, got %q instead of %q`, result, expected)
|
2018-09-24 00:23:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-25 09:36:19 +01:00
|
|
|
func TestDefaultProxyOptionValue(t *testing.T) {
|
2018-09-24 00:23:46 +02:00
|
|
|
os.Clearenv()
|
2019-06-02 03:18:09 +02:00
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
2023-02-25 09:36:19 +01:00
|
|
|
expected := defaultProxyOption
|
|
|
|
result := opts.ProxyOption()
|
2018-09-24 00:23:46 +02:00
|
|
|
|
|
|
|
if result != expected {
|
2023-02-25 09:36:19 +01:00
|
|
|
t.Fatalf(`Unexpected PROXY_OPTION value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProxyMediaTypes(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("PROXY_MEDIA_TYPES", "image,audio")
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := []string{"audio", "image"}
|
|
|
|
|
|
|
|
if len(expected) != len(opts.ProxyMediaTypes()) {
|
|
|
|
t.Fatalf(`Unexpected PROXY_MEDIA_TYPES value, got %v instead of %v`, opts.ProxyMediaTypes(), expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
resultMap := make(map[string]bool)
|
|
|
|
for _, mediaType := range opts.ProxyMediaTypes() {
|
|
|
|
resultMap[mediaType] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, mediaType := range expected {
|
|
|
|
if !resultMap[mediaType] {
|
|
|
|
t.Fatalf(`Unexpected PROXY_MEDIA_TYPES value, got %v instead of %v`, opts.ProxyMediaTypes(), expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultProxyMediaTypes(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := []string{"image"}
|
|
|
|
|
|
|
|
if len(expected) != len(opts.ProxyMediaTypes()) {
|
|
|
|
t.Fatalf(`Unexpected PROXY_MEDIA_TYPES value, got %v instead of %v`, opts.ProxyMediaTypes(), expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
resultMap := make(map[string]bool)
|
|
|
|
for _, mediaType := range opts.ProxyMediaTypes() {
|
|
|
|
resultMap[mediaType] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, mediaType := range expected {
|
|
|
|
if !resultMap[mediaType] {
|
|
|
|
t.Fatalf(`Unexpected PROXY_MEDIA_TYPES value, got %v instead of %v`, opts.ProxyMediaTypes(), expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProxyHTTPClientTimeout(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("PROXY_HTTP_CLIENT_TIMEOUT", "24")
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := 24
|
|
|
|
result := opts.ProxyHTTPClientTimeout()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected PROXY_HTTP_CLIENT_TIMEOUT value, got %d instead of %d`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultProxyHTTPClientTimeoutValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := defaultProxyHTTPClientTimeout
|
|
|
|
result := opts.ProxyHTTPClientTimeout()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected PROXY_HTTP_CLIENT_TIMEOUT value, got %d instead of %d`, result, expected)
|
2018-09-24 00:23:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTPSOff(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if opts.HTTPS {
|
|
|
|
t.Fatalf(`Unexpected HTTPS value, got "%v"`, opts.HTTPS)
|
2018-09-24 00:23:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTPSOn(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("HTTPS", "on")
|
2018-02-04 00:54:02 +01:00
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 03:18:09 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 03:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if !opts.HTTPS {
|
|
|
|
t.Fatalf(`Unexpected HTTPS value, got "%v"`, opts.HTTPS)
|
2018-02-04 00:54:02 +01:00
|
|
|
}
|
|
|
|
}
|
2019-06-02 16:13:35 +02:00
|
|
|
|
|
|
|
func TestHTTPClientTimeout(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("HTTP_CLIENT_TIMEOUT", "42")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 16:13:35 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 16:13:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
expected := 42
|
|
|
|
result := opts.HTTPClientTimeout()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected HTTP_CLIENT_TIMEOUT value, got %d instead of %d`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultHTTPClientTimeoutValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 16:13:35 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 16:13:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
expected := defaultHTTPClientTimeout
|
|
|
|
result := opts.HTTPClientTimeout()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected HTTP_CLIENT_TIMEOUT value, got %d instead of %d`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHTTPClientMaxBodySize(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("HTTP_CLIENT_MAX_BODY_SIZE", "42")
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 16:13:35 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 16:13:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
expected := int64(42 * 1024 * 1024)
|
|
|
|
result := opts.HTTPClientMaxBodySize()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected HTTP_CLIENT_MAX_BODY_SIZE value, got %d instead of %d`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultHTTPClientMaxBodySizeValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
2019-06-02 16:13:35 +02:00
|
|
|
if err != nil {
|
2019-06-03 03:20:59 +02:00
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
2019-06-02 16:13:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
expected := int64(defaultHTTPClientMaxBodySize * 1024 * 1024)
|
|
|
|
result := opts.HTTPClientMaxBodySize()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected HTTP_CLIENT_MAX_BODY_SIZE value, got %d instead of %d`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
2019-06-03 03:20:59 +02:00
|
|
|
|
2023-02-25 09:36:19 +01:00
|
|
|
func TestHTTPServerTimeout(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("HTTP_SERVER_TIMEOUT", "342")
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := 342
|
|
|
|
result := opts.HTTPServerTimeout()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected HTTP_SERVER_TIMEOUT value, got %d instead of %d`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultHTTPServerTimeoutValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := defaultHTTPServerTimeout
|
|
|
|
result := opts.HTTPServerTimeout()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected HTTP_SERVER_TIMEOUT value, got %d instead of %d`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
func TestParseConfigFile(t *testing.T) {
|
|
|
|
content := []byte(`
|
|
|
|
# This is a comment
|
|
|
|
|
|
|
|
DEBUG = yes
|
|
|
|
|
|
|
|
POCKET_CONSUMER_KEY= >#1234
|
|
|
|
|
|
|
|
Invalid text
|
|
|
|
`)
|
|
|
|
|
2021-02-17 06:19:03 +01:00
|
|
|
tmpfile, err := os.CreateTemp(".", "miniflux.*.unit_test.conf")
|
2019-06-03 03:20:59 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := tmpfile.Write(content); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Clearenv()
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseFile(tmpfile.Name())
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if opts.HasDebugMode() != true {
|
|
|
|
t.Errorf(`Unexpected debug mode value, got "%v"`, opts.HasDebugMode())
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := ">#1234"
|
|
|
|
result := opts.PocketConsumerKey("default")
|
|
|
|
if result != expected {
|
|
|
|
t.Errorf(`Unexpected POCKET_CONSUMER_KEY value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := tmpfile.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.Remove(tmpfile.Name()); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 11:45:59 +01:00
|
|
|
|
|
|
|
func TestAuthProxyHeader(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("AUTH_PROXY_HEADER", "X-Forwarded-User")
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := "X-Forwarded-User"
|
|
|
|
result := opts.AuthProxyHeader()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected AUTH_PROXY_HEADER value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultAuthProxyHeaderValue(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := defaultAuthProxyHeader
|
|
|
|
result := opts.AuthProxyHeader()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected AUTH_PROXY_HEADER value, got %q instead of %q`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAuthProxyUserCreationWhenUnset(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := false
|
|
|
|
result := opts.IsAuthProxyUserCreationAllowed()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected AUTH_PROXY_USER_CREATION value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAuthProxyUserCreationAdmin(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("AUTH_PROXY_USER_CREATION", "1")
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := true
|
|
|
|
result := opts.IsAuthProxyUserCreationAllowed()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected AUTH_PROXY_USER_CREATION value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
2021-01-27 13:50:34 +01:00
|
|
|
|
|
|
|
func TestFetchYouTubeWatchTime(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
os.Setenv("FETCH_YOUTUBE_WATCH_TIME", "1")
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
opts, err := parser.ParseEnvironmentVariables()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := true
|
|
|
|
result := opts.FetchYouTubeWatchTime()
|
|
|
|
|
|
|
|
if result != expected {
|
|
|
|
t.Fatalf(`Unexpected FETCH_YOUTUBE_WATCH_TIME value, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
2021-09-26 17:35:31 +02:00
|
|
|
|
|
|
|
func TestParseConfigDumpOutput(t *testing.T) {
|
|
|
|
os.Clearenv()
|
|
|
|
|
|
|
|
wantOpts := NewOptions()
|
|
|
|
wantOpts.adminUsername = "my-username"
|
|
|
|
|
|
|
|
serialized := wantOpts.String()
|
|
|
|
tmpfile, err := os.CreateTemp(".", "miniflux.*.unit_test.conf")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := tmpfile.Write([]byte(serialized)); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
parser := NewParser()
|
|
|
|
parsedOpts, err := parser.ParseFile(tmpfile.Name())
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf(`Parsing failure: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if parsedOpts.AdminUsername() != wantOpts.AdminUsername() {
|
|
|
|
t.Fatalf(`Unexpected ADMIN_USERNAME value, got %q instead of %q`, parsedOpts.AdminUsername(), wantOpts.AdminUsername())
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := tmpfile.Close(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.Remove(tmpfile.Name()); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|