优化本机重置不可用提示
当系统通知或本机重置通道不可用时,向运维人员显示明确的中文原因,并补充回归测试。
This commit is contained in:
parent
86a89e385f
commit
9cd8ce3530
@ -90,6 +90,10 @@ func runConnected(ctx context.Context, conn net.Conn, screen terminal) error {
|
||||
}
|
||||
}
|
||||
if err := resetFlow(ctx, client, screen); err != nil {
|
||||
if errors.Is(err, localreset.ErrUnavailable) {
|
||||
showResetFailure(screen, err)
|
||||
return localreset.ErrProtocol
|
||||
}
|
||||
_ = screen.Show("密码重置未完成:操作已取消、验证失败、会话过期或保存失败。请检查服务日志后重新启动。")
|
||||
return localreset.ErrProtocol
|
||||
}
|
||||
@ -99,6 +103,14 @@ func runConnected(ctx context.Context, conn net.Conn, screen terminal) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func showResetFailure(screen terminal, err error) {
|
||||
message := `密码重置未完成:操作已取消、验证失败、会话过期或保存失败。请检查服务日志后重新启动。`
|
||||
if errors.Is(err, localreset.ErrUnavailable) {
|
||||
message = `密码重置未完成:验证码发送服务或本机重置通道不可用。请先恢复系统通知服务后重新启动。`
|
||||
}
|
||||
_ = screen.Show(message)
|
||||
}
|
||||
|
||||
func resetFlow(ctx context.Context, client resetClient, screen terminal) error {
|
||||
methods := client.Methods()
|
||||
if len(methods) != 1 || methods[0].ID != "email" {
|
||||
|
||||
@ -14,6 +14,7 @@ type testTerminalInput struct {
|
||||
values []string
|
||||
hidden []bool
|
||||
prompts []string
|
||||
shown []string
|
||||
failAt int
|
||||
readHook func(int)
|
||||
}
|
||||
@ -36,7 +37,10 @@ func (s *testTerminalInput) Read(ctx context.Context, prompt string, hidden bool
|
||||
}
|
||||
return s.values[index-1], nil
|
||||
}
|
||||
func (*testTerminalInput) Show(string) error { return nil }
|
||||
func (s *testTerminalInput) Show(message string) error {
|
||||
s.shown = append(s.shown, message)
|
||||
return nil
|
||||
}
|
||||
|
||||
type testResetClient struct {
|
||||
methods []localreset.Method
|
||||
@ -133,6 +137,14 @@ func TestAdminConsoleFailureNeverSubmitsPassword(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminConsoleShowsUnavailableResetCause(t *testing.T) {
|
||||
screen := &testTerminalInput{}
|
||||
showResetFailure(screen, localreset.ErrUnavailable)
|
||||
if len(screen.shown) != 1 || !strings.Contains(screen.shown[0], `验证码发送服务或本机重置通道不可用`) {
|
||||
t.Fatalf(`未显示SMTP或本机通道不可用提示:%v`, screen.shown)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminConsoleRejectsAllArgumentBasedInput(t *testing.T) {
|
||||
for _, args := range [][]string{
|
||||
{"--password", "TestPass123!"}, {"--config", "scert.json"}, {"--code-output", "reset-code"}, {"TestPass123!"}, {"--help"},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user