Pārlūkot izejas kodu

fix(ldap): convert default total GB to bytes when auto-creating clients (#5854)

* fix(ldap): convert default total GB to bytes when auto-creating clients

LdapSyncJob.buildClient stored ldapDefaultTotalGB directly into
Client.TotalGB without the GB-to-bytes conversion every other client
creation path applies (client form's gbToBytes, tgbot's
limitTraffic*1024^3, client_inbound_apply.go's totalGB*1024^3). A
"Default total (GB)" of 10 was persisted as 10 bytes, depleting the
client almost immediately.

Closes #5852

* test(ldap): pin the GB-to-bytes conversion in buildClient

Per review feedback on #5854: the existing test only exercised
defGB=0, so it wouldn't have caught the missing conversion.
mrnickson-hue 22 stundas atpakaļ
vecāks
revīzija
57300f44bd

+ 1 - 1
internal/web/job/ldap_sync_job.go

@@ -189,7 +189,7 @@ func (j *LdapSyncJob) buildClient(email string, defGB, defExpiryDays, defLimitIP
 		Email:   email,
 		Enable:  true,
 		LimitIP: defLimitIP,
-		TotalGB: int64(defGB),
+		TotalGB: int64(defGB) * 1024 * 1024 * 1024,
 	}
 	if defExpiryDays > 0 {
 		c.ExpiryTime = time.Now().Add(time.Duration(defExpiryDays) * 24 * time.Hour).UnixMilli()

+ 8 - 0
internal/web/job/ldap_sync_job_test.go

@@ -19,6 +19,14 @@ func initLdapJobDB(t *testing.T) {
 	t.Cleanup(func() { _ = database.CloseDB() })
 }
 
+func TestBuildClient_ConvertsDefaultTotalGBToBytes(t *testing.T) {
+	j := NewLdapSyncJob()
+	c := j.buildClient("[email protected]", 10, 0, 0)
+	if want := int64(10) * 1024 * 1024 * 1024; c.TotalGB != want {
+		t.Errorf("TotalGB = %d, want %d", c.TotalGB, want)
+	}
+}
+
 func TestLdapCreateClients_AttachesToAllConfiguredInbounds(t *testing.T) {
 	initLdapJobDB(t)
 	db := database.GetDB()