SMTP-Credentials und E_Mail-Adressen verschlüsselt abgelegt
This commit is contained in:
1 parent
781aa20253
commit
66659d9a23
32 files changed
+3276
-132
No files matched your search
@@ -7,6 +7,8 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"lektorenplan/store"
|
||||
)
|
||||
|
||||
// dispatchRange is a range with seeded demo services and liturgical days.
|
||||
@@ -218,18 +220,39 @@ func TestEditorManagesTenantSMTP(t *testing.T) {
|
||||
tenants, _ := st.Tenants(ctx)
|
||||
found := false
|
||||
for _, tenant := range tenants {
|
||||
if st.TenantSetting(ctx, tenant.ID, "smtp.host") == "smtp.example.org" {
|
||||
if got := st.TenantSetting(ctx, tenant.ID, "smtp.host"); got == "smtp.example.org" {
|
||||
t.Fatalf("SMTP host was stored as plaintext tenant setting")
|
||||
}
|
||||
if st.SecretExists(ctx, tenant.ID, store.ScopeTenant, tenant.ID, "smtp.host") {
|
||||
found = true
|
||||
if got := st.TenantSetting(ctx, tenant.ID, "smtp.port"); got != "587" {
|
||||
t.Fatalf("smtp port = %q", got)
|
||||
if !st.SecretIsInitialized(ctx, tenant.ID) {
|
||||
t.Fatal("tenant secrets are not marked as initialized")
|
||||
}
|
||||
if got := st.TenantSetting(ctx, tenant.ID, "smtp.password"); got != "secret" {
|
||||
t.Fatalf("smtp password = %q", got)
|
||||
editor, err := st.UserByUsername(ctx, "editor")
|
||||
if err != nil {
|
||||
t.Fatalf("editor account: %v", err)
|
||||
}
|
||||
keyring, err := st.EnsureUserKeys(ctx, editor.ID, "editor1231")
|
||||
if err != nil {
|
||||
t.Fatalf("unlock editor keys: %v", err)
|
||||
}
|
||||
if err := st.UnlockAccessibleKeys(ctx, keyring); err != nil {
|
||||
t.Fatalf("unwrap data keys: %v", err)
|
||||
}
|
||||
secretCtx := store.WithKeyring(ctx, keyring)
|
||||
if got, ok := st.SecretValue(secretCtx, tenant.ID, store.ScopeTenant, tenant.ID, "smtp.host"); !ok || got != "smtp.example.org" {
|
||||
t.Fatalf("smtp host = %q, ok=%v", got, ok)
|
||||
}
|
||||
if got, ok := st.SecretValue(secretCtx, tenant.ID, store.ScopeTenant, tenant.ID, "smtp.port"); !ok || got != "587" {
|
||||
t.Fatalf("smtp port = %q, ok=%v", got, ok)
|
||||
}
|
||||
if got, ok := st.SecretValue(secretCtx, tenant.ID, store.ScopeTenant, tenant.ID, "smtp.password"); !ok || got != "secret" {
|
||||
t.Fatalf("smtp password = %q, ok=%v", got, ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("SMTP host was not stored as a tenant setting")
|
||||
t.Fatal("SMTP host was not stored as an encrypted secret")
|
||||
}
|
||||
|
||||
// The dispatch page now reports a ready SMTP configuration.
|
||||
@@ -237,6 +260,12 @@ func TestEditorManagesTenantSMTP(t *testing.T) {
|
||||
if !strings.Contains(page, "SMTP bereit") {
|
||||
t.Fatal("dispatch page does not reflect the SMTP configuration")
|
||||
}
|
||||
if !strings.Contains(page, `formaction="/dispatch/send"`) {
|
||||
t.Fatal("dispatch page does not offer direct sending with SMTP configured")
|
||||
}
|
||||
if strings.Contains(page, "data-mailto-link") {
|
||||
t.Fatal("dispatch page must not offer mailto drafts when SMTP is configured")
|
||||
}
|
||||
|
||||
// Readers may not change these settings.
|
||||
reader := newClient(t)
|
||||
@@ -247,6 +276,49 @@ func TestEditorManagesTenantSMTP(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatchMailtoEncodesDraft(t *testing.T) {
|
||||
href := dispatchMailto("anna.berg@example.org", "Plan März", "Hallo & Grüße\nZeile 2")
|
||||
if !strings.HasPrefix(href, "mailto:") {
|
||||
t.Fatalf("mailto link = %q", href)
|
||||
}
|
||||
if !strings.Contains(href, "subject=Plan%20M%C3%A4rz") {
|
||||
t.Fatalf("subject is not encoded: %q", href)
|
||||
}
|
||||
body := "body=Hallo%20%26%20Gr%C3%BC%C3%9Fe%0D%0AZeile%202"
|
||||
if !strings.Contains(href, body) {
|
||||
t.Fatalf("body is not encoded: %q", href)
|
||||
}
|
||||
if strings.Contains(href, "+") {
|
||||
t.Fatalf("mailto link must not use plus signs for spaces: %q", href)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatchOffersMailtoAndCopyWithoutSMTP(t *testing.T) {
|
||||
ts, _ := newTestServer(t)
|
||||
client := newClient(t)
|
||||
login(t, client, ts.URL, "editor", "editor123")
|
||||
|
||||
body := get(t, client, ts.URL+"/dispatch?"+dispatchRange, http.StatusOK)
|
||||
if !strings.Contains(body, "Kein SMTP-Konto hinterlegt") {
|
||||
t.Fatal("dispatch page is missing the mailto fallback notice")
|
||||
}
|
||||
if strings.Contains(body, `formaction="/dispatch/send"`) {
|
||||
t.Fatal("dispatch page must not offer direct sending without SMTP")
|
||||
}
|
||||
if !strings.Contains(body, "data-copy-person") {
|
||||
t.Fatal("dispatch page is missing per-person copy controls")
|
||||
}
|
||||
if !strings.Contains(body, "data-copy-shared") {
|
||||
t.Fatal("dispatch page is missing the shared-text copy control")
|
||||
}
|
||||
if !strings.Contains(body, "data-mailto-link") || !strings.Contains(body, `data-mailto-email="anna.berg@example.org"`) {
|
||||
t.Fatal("dispatch page is missing the mailto fallback for recipients")
|
||||
}
|
||||
if !strings.Contains(body, "mailto:anna.berg@example.org?subject=") {
|
||||
t.Fatal("dispatch page is missing a prepared mailto link")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGuestAccessIsReadOnlyAndAnonymous(t *testing.T) {
|
||||
ts, st := newTestServer(t)
|
||||
client := newClient(t)
|
||||
|
||||
Reference in new issue
Block a user