This commit is contained in:
CN-JS-HuiBai
2026-04-15 11:30:21 +08:00
parent e4fdc1791a
commit 0afdc9cc89
2 changed files with 31 additions and 2 deletions

View File

@@ -902,6 +902,10 @@ func (s *Service) syncUsers() {
}
for _, u := range users {
userName := u.Identifier()
if userName == "" {
continue
}
key := s.resolveUserKey(u, isSS2022)
if key == "" {
continue
@@ -914,9 +918,9 @@ func (s *Service) syncUsers() {
s.logger.Info("User [", u.ID, "] ID[:", ss2022KeyLen, "]=", originalKey, " → b64_PSK=", key)
}
newUsers[u.Email] = userData{
newUsers[userName] = userData{
ID: u.ID,
Email: u.Email,
Email: userName,
Key: key,
Flow: u.Flow,
}
@@ -1084,6 +1088,19 @@ type XUser struct {
Flow string `json:"flow"`
}
func (u *XUser) Identifier() string {
if u.UUID != "" {
return u.UUID
}
if u.Email != "" {
return u.Email
}
if u.ID != 0 {
return strconv.Itoa(u.ID)
}
return ""
}
func (u *XUser) ResolveKey() string {
if u.Passwd != "" {
return u.Passwd

View File

@@ -15,6 +15,18 @@ func TestXUserResolveKeyPrefersPasswordFields(t *testing.T) {
}
}
func TestXUserIdentifierPrefersUUID(t *testing.T) {
user := XUser{
ID: 7,
UUID: "uuid-value",
Email: "user@example.com",
}
if got := user.Identifier(); got != "uuid-value" {
t.Fatalf("Identifier() = %q, want %q", got, "uuid-value")
}
}
func TestResolveUserKeyForSS2022CombinedPassword(t *testing.T) {
service := &Service{ssServerKey: "master-key"}
user := XUser{