精简初始化通知设置并默认使用Smail系统通知身份发信
This commit is contained in:
1 parent
229d150a08
commit
a9937c3e6a
16 files changed
+186
-48
No files matched your search
@@ -97,6 +97,13 @@ func (completer *Completer) prepareNotification(ctx context.Context, current con
|
||||
return candidate, nil, completeError(CompleteErrorInput, "SMTP 通知主机、账号、密码或连接安全参数无效", nil)
|
||||
}
|
||||
credentials := make(map[string]map[string]string)
|
||||
if candidate.SMTPEnabled {
|
||||
name, email, err := candidate.SenderIdentity()
|
||||
if err != nil {
|
||||
return candidate, nil, completeError(CompleteErrorInput, "SMTP 发件账号无效,请使用 Smail 系统通知页提供的完整用户名", err)
|
||||
}
|
||||
candidate.SenderName, candidate.SenderEmail = name, email
|
||||
}
|
||||
if candidate.HTTPEnabled && candidate.HTTPAuthMode != "none" {
|
||||
values, err := notificationCredentials(candidate.HTTPAuthMode, input.HTTPCredentials)
|
||||
if err != nil {
|
||||
|
||||
@@ -15,7 +15,7 @@ func completionNotificationInput() *NotificationInput {
|
||||
return &NotificationInput{
|
||||
HTTPEnabled: true, Endpoint: "https://mail.example.test", HTTPAuthMode: "session",
|
||||
HTTPCredentials: map[string]string{"account": "mail-owner", "password": "private-http-password"},
|
||||
SMTPEnabled: true, SMTPHost: "smtp.example.test", SMTPUsername: "smtp-owner", SMTPPassword: "private-smtp-password",
|
||||
SMTPEnabled: true, SMTPHost: "smtp.example.test", SMTPUsername: "notify:smtp-owner@example.test", SMTPPassword: "private-smtp-password",
|
||||
IncludeManagementURL: true, IncludeCertificateSerial: true,
|
||||
Recipients: []string{"notify@example.test"}, TimeoutSecs: 15, RetryCount: 0, RetryIntervalsSecs: []int{},
|
||||
}
|
||||
@@ -59,6 +59,9 @@ func TestCompleterStoresNotificationCredentialsWithoutPlaintext(t *testing.T) {
|
||||
t.Fatalf("通知选项未完整保存:%+v", stored.Notification)
|
||||
}
|
||||
httpCredentials, err := fixture.store.Get(t.Context(), stored.Notification.HTTPCredentialRef)
|
||||
if stored.Notification.SenderEmail != "notification+system@example.test" || stored.Notification.SenderName != "系统通知" {
|
||||
t.Fatal("初始化没有保存 Smail 系统通知发件人")
|
||||
}
|
||||
if err != nil || httpCredentials["password"] != "private-http-password" {
|
||||
t.Fatalf("HTTP 通知凭据未进入敏感存储:%v", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user