3825859da6
build / build (push) Successful in 2m20s
PP 增加受控凭据更新、真实登录与目录检查,待验证修改不会替换生效配置;扫描与取件共享生效修订。 钉钉来源向导、校验与登记共用 DWS 授权,支持中途恢复与换账号保护,取消旧扫码自动回落。 认证审计复用已有来源审计页,配置响应不回传密码;补齐运行镜像脚本与权限。 验证:make verify 退出 0;PP/DWS/httpapi 目标 race 回归通过;隔离 HTTP 服务验证 PP 协议及扫描/取件消费者。 尚未部署;真实 PP 凭据与目录可用性在测试站部署后验证。
105 lines
3.5 KiB
Go
105 lines
3.5 KiB
Go
package ppauth
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
"sync"
|
|
"sync/atomic"
|
|
"testing"
|
|
)
|
|
|
|
func TestPendingPasswordSurvivesRevalidationWithoutReturningSecrets(t *testing.T) {
|
|
state := "valid"
|
|
seen := ""
|
|
m := &Manager{Path: t.TempDir() + "/credentials/settings.json", Probe: func(_ context.Context, c Credentials) Observation {
|
|
seen = c.Password
|
|
return Observation{State: state, Message: state}
|
|
}}
|
|
v, err := m.Save(context.Background(), Draft{BaseURL: "https://api.example.invalid", Username: "example", Password: "example-old"}, "tester")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
state = "unavailable"
|
|
v, err = m.Save(context.Background(), Draft{BaseURL: "https://api.example.invalid", Username: "example", Password: "example-new", Revision: v.Revision}, "tester")
|
|
if err != nil || v.Pending == nil {
|
|
t.Fatalf("pending save: %v", err)
|
|
}
|
|
state = "valid"
|
|
v, err = m.Save(context.Background(), Draft{BaseURL: v.Pending.BaseURL, Username: v.Pending.Username, PendingID: v.Pending.ID, Revision: v.Revision}, "tester")
|
|
if err != nil || seen != "example-new" || v.Pending != nil {
|
|
t.Fatal("saved pending password was not reused")
|
|
}
|
|
raw, _ := json.Marshal(v)
|
|
if strings.Contains(string(raw), "example-new") || strings.Contains(string(raw), `"password":`) {
|
|
t.Fatal("metadata leaked secret")
|
|
}
|
|
info, err := os.Stat(m.Path)
|
|
if err != nil || info.Mode().Perm() != 0600 {
|
|
t.Fatal("secret file not mode 0600")
|
|
}
|
|
}
|
|
func TestConcurrentSavesCannotOverwriteANewerRevision(t *testing.T) {
|
|
var calls atomic.Int32
|
|
barrier := make(chan struct{})
|
|
m := &Manager{Path: t.TempDir() + "/credentials/settings.json", Probe: func(_ context.Context, c Credentials) Observation {
|
|
if calls.Add(1) == 2 {
|
|
close(barrier)
|
|
}
|
|
<-barrier
|
|
return Observation{State: "valid", Message: "valid"}
|
|
}}
|
|
outcomes := make(chan error, 2)
|
|
var wg sync.WaitGroup
|
|
for _, name := range []string{"example-one", "example-two"} {
|
|
wg.Add(1)
|
|
go func(user string) {
|
|
defer wg.Done()
|
|
_, err := m.Save(context.Background(), Draft{BaseURL: "https://api.example.invalid", Username: user, Password: "example-password"}, "tester")
|
|
outcomes <- err
|
|
}(name)
|
|
}
|
|
wg.Wait()
|
|
close(outcomes)
|
|
success, conflict := 0, 0
|
|
for err := range outcomes {
|
|
if err == nil {
|
|
success++
|
|
} else if errors.Is(err, ErrConflict) {
|
|
conflict++
|
|
} else {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if success != 1 || conflict != 1 {
|
|
t.Fatalf("success=%d conflict=%d", success, conflict)
|
|
}
|
|
}
|
|
func TestFailedObservationRetainsPreviousSuccess(t *testing.T) {
|
|
state := "valid"
|
|
m := &Manager{Path: t.TempDir() + "/credentials/settings.json", Probe: func(_ context.Context, c Credentials) Observation { return Observation{State: state, Message: state} }}
|
|
v, err := m.Save(context.Background(), Draft{BaseURL: "https://api.example.invalid", Username: "example", Password: "example-password"}, "tester")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
state = "unavailable"
|
|
_, err = m.Test(context.Background(), Draft{BaseURL: v.Active.BaseURL, Username: v.Active.Username, Revision: v.Revision}, "tester")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
v, err = m.View()
|
|
if err != nil || v.Observation.Previous == nil || v.Observation.Previous.State != "valid" {
|
|
t.Fatal("failed check erased previous successful observation")
|
|
}
|
|
}
|
|
func TestPPPythonProtocolAndConfigurationConsumers(t *testing.T) {
|
|
command := exec.Command("python3", "-m", "unittest", "discover", "-s", "../../scripts", "-p", "test_pp_client.py", "-v")
|
|
output, err := command.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("PP protocol regression: %v\n%s", err, output)
|
|
}
|
|
}
|