Production state
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func setRequiredConfig(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv("STUDENT_PIN", "student")
|
||||
t.Setenv("INSTRUCTOR_PIN", "instructor")
|
||||
t.Setenv("SESSION_SIGNING_SECRET", "12345678901234567890123456789012")
|
||||
t.Setenv("LOG_LEVEL", "info")
|
||||
t.Setenv("LOG_FORMAT", "text")
|
||||
}
|
||||
|
||||
func TestProductionConfigRequiresHTTPSPublicOrigin(t *testing.T) {
|
||||
setRequiredConfig(t)
|
||||
t.Setenv("APP_ENV", "production")
|
||||
t.Setenv("PUBLIC_BASE_URL", "http://preface-tools.example.test")
|
||||
if _, err := LoadConfigFromEnv(); err == nil {
|
||||
t.Fatal("production HTTP public URL accepted")
|
||||
}
|
||||
t.Setenv("PUBLIC_BASE_URL", "https://preface-tools.example.test")
|
||||
cfg, err := LoadConfigFromEnv()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cfg.WriteTimeout != 10*time.Minute {
|
||||
t.Fatalf("write timeout = %s", cfg.WriteTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigRejectsPublicURLWithPath(t *testing.T) {
|
||||
setRequiredConfig(t)
|
||||
t.Setenv("APP_ENV", "development")
|
||||
t.Setenv("PUBLIC_BASE_URL", "https://preface-tools.example.test/subpath")
|
||||
if _, err := LoadConfigFromEnv(); err == nil {
|
||||
t.Fatal("public URL with path accepted")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user