refactor(doctor): drop redundant password check
All checks were successful
Release / release (push) Successful in 27s
All checks were successful
Release / release (push) Successful in 27s
Le check "password" ouvrait le store et lisait le secret indépendamment du ConnectivityCheck, provoquant deux appels bw --version + bw status. La connectivité échoue déjà si le mot de passe est inaccessible, donc le check était redondant. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
235727106d
commit
23fff88ccb
2 changed files with 3 additions and 66 deletions
|
|
@ -964,9 +964,8 @@ base_url = "https://gitea.lclr.dev"
|
||||||
for _, needle := range []string{
|
for _, needle := range []string{
|
||||||
"[OK] config: config file is readable",
|
"[OK] config: config file is readable",
|
||||||
"[OK] profile: required profile values are resolved",
|
"[OK] profile: required profile values are resolved",
|
||||||
"[OK] password: stored password is present",
|
|
||||||
"[OK] connectivity: IMAP server is reachable",
|
"[OK] connectivity: IMAP server is reachable",
|
||||||
"Summary: 5 ok, 0 warning(s), 0 failure(s), 5 total",
|
"Summary: 4 ok, 0 warning(s), 0 failure(s), 4 total",
|
||||||
} {
|
} {
|
||||||
if !strings.Contains(text, needle) {
|
if !strings.Contains(text, needle) {
|
||||||
t.Fatalf("output = %q, want substring %q", text, needle)
|
t.Fatalf("output = %q, want substring %q", text, needle)
|
||||||
|
|
@ -1018,7 +1017,7 @@ func TestAppRunDoctorReturnsErrorWhenChecksFail(t *testing.T) {
|
||||||
if !strings.Contains(err.Error(), "doctor checks failed") {
|
if !strings.Contains(err.Error(), "doctor checks failed") {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(output.String(), "[FAIL] password: stored password is missing") {
|
if !strings.Contains(output.String(), "[FAIL] connectivity: cannot load IMAP credentials") {
|
||||||
t.Fatalf("unexpected output: %q", output.String())
|
t.Fatalf("unexpected output: %q", output.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1065,7 +1064,7 @@ func TestAppRunDoctorAcceptsPasswordFromEnvironment(t *testing.T) {
|
||||||
if err := app.Run([]string{"doctor"}); err != nil {
|
if err := app.Run([]string{"doctor"}); err != nil {
|
||||||
t.Fatalf("doctor returned error: %v", err)
|
t.Fatalf("doctor returned error: %v", err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(output.String(), "[OK] password: password is provided via environment") {
|
if !strings.Contains(output.String(), "[OK] connectivity: IMAP server is reachable") {
|
||||||
t.Fatalf("unexpected output: %q", output.String())
|
t.Fatalf("unexpected output: %q", output.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -33,7 +32,6 @@ func (a *App) runDoctor(ctx context.Context, args []string) error {
|
||||||
ConnectivityCheck: a.doctorConnectivityCheck(profileFlag),
|
ConnectivityCheck: a.doctorConnectivityCheck(profileFlag),
|
||||||
ExtraChecks: []frameworkcli.DoctorCheck{
|
ExtraChecks: []frameworkcli.DoctorCheck{
|
||||||
a.doctorRequiredProfileFieldsCheck(profileFlag),
|
a.doctorRequiredProfileFieldsCheck(profileFlag),
|
||||||
a.doctorPasswordCheck(profileFlag),
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err := frameworkcli.RenderDoctorReport(a.stdout, report); err != nil {
|
if err := frameworkcli.RenderDoctorReport(a.stdout, report); err != nil {
|
||||||
|
|
@ -86,66 +84,6 @@ func (a *App) doctorRequiredProfileFieldsCheck(profileFlag string) frameworkcli.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) doctorPasswordCheck(profileFlag string) frameworkcli.DoctorCheck {
|
|
||||||
return func(context.Context) frameworkcli.DoctorResult {
|
|
||||||
profileName := a.resolveDoctorProfileName(profileFlag)
|
|
||||||
store, err := a.openSecretStore()
|
|
||||||
if err != nil {
|
|
||||||
return frameworkcli.DoctorResult{
|
|
||||||
Name: "password",
|
|
||||||
Status: frameworkcli.DoctorStatusFail,
|
|
||||||
Summary: "cannot inspect stored password",
|
|
||||||
Detail: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resolution, err := resolveCredentialFields(
|
|
||||||
ProfileConfig{},
|
|
||||||
store,
|
|
||||||
passwordOnlyFieldSpecs(profileName),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
var missingErr *frameworkcli.MissingRequiredValuesError
|
|
||||||
if errors.As(err, &missingErr) {
|
|
||||||
return frameworkcli.DoctorResult{
|
|
||||||
Name: "password",
|
|
||||||
Status: frameworkcli.DoctorStatusFail,
|
|
||||||
Summary: "stored password is missing",
|
|
||||||
Detail: fmt.Sprintf(
|
|
||||||
"set %q or secret %q",
|
|
||||||
passwordEnv,
|
|
||||||
passwordSecretName(profileName),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return frameworkcli.DoctorResult{
|
|
||||||
Name: "password",
|
|
||||||
Status: frameworkcli.DoctorStatusFail,
|
|
||||||
Summary: "cannot read stored password",
|
|
||||||
Detail: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
password, _ := resolution.Get("password")
|
|
||||||
if password.Source == frameworkcli.SourceEnv {
|
|
||||||
return frameworkcli.DoctorResult{
|
|
||||||
Name: "password",
|
|
||||||
Status: frameworkcli.DoctorStatusOK,
|
|
||||||
Summary: "password is provided via environment",
|
|
||||||
Detail: fmt.Sprintf("variable %q", passwordEnv),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return frameworkcli.DoctorResult{
|
|
||||||
Name: "password",
|
|
||||||
Status: frameworkcli.DoctorStatusOK,
|
|
||||||
Summary: "stored password is present",
|
|
||||||
Detail: fmt.Sprintf("secret %q", passwordSecretName(profileName)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *App) doctorConnectivityCheck(profileFlag string) frameworkcli.DoctorCheck {
|
func (a *App) doctorConnectivityCheck(profileFlag string) frameworkcli.DoctorCheck {
|
||||||
return func(parent context.Context) frameworkcli.DoctorResult {
|
return func(parent context.Context) frameworkcli.DoctorResult {
|
||||||
ctx, cancel := context.WithTimeout(parent, 35*time.Second)
|
ctx, cancel := context.WithTimeout(parent, 35*time.Second)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue