Fix failing tests and SQLITE_BUSY errors
Some checks failed
Build Docker and Deploy / Build Docker Container (push) Successful in 1m0s
Build Docker and Deploy / Run Unit-Tests (push) Failing after 10m35s
Build Docker and Deploy / Deploy to Server (push) Has been skipped

This commit is contained in:
2025-05-11 19:20:13 +02:00
parent 3e0c4845e9
commit 658dc4cc9c
11 changed files with 545 additions and 151 deletions

View File

@@ -6,7 +6,9 @@ import (
"fmt"
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
"github.com/gin-gonic/gin"
"strings"
"testing"
"time"
)
func TestTokenKeys(t *testing.T) {
@@ -722,3 +724,50 @@ func TestTokenKeysGetCurrent(t *testing.T) {
}
}
func TestKeyTokenLastUsed(t *testing.T) {
ws, baseUrl, stop := tt.StartSimpleWebserver(t)
defer stop()
data := tt.InitSingleData(t, ws)
type keyobj struct {
AllChannels bool `json:"all_channels"`
Channels []string `json:"channels"`
KeytokenId string `json:"keytoken_id"`
MessagesSent int `json:"messages_sent"`
Name string `json:"name"`
OwnerUserId string `json:"owner_user_id"`
Permissions string `json:"permissions"`
TimestampLastUsed *string `json:"timestamp_lastused"`
}
rkey1 := tt.RequestAuthGet[keyobj](t, data.ReadKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/current", data.UID))
readKeyID := rkey1.KeytokenId
time.Sleep(6 * time.Second) // wait for first DCI
rkey2 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, readKeyID))
tt.AssertNotNil(t, "timestamp_lastused", rkey2.TimestampLastUsed)
rkey3 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, readKeyID))
time.Sleep(6 * time.Second) // wait for first DCI
tt.AssertEqual(t, "timestamp_lastused", *rkey2.TimestampLastUsed, *rkey3.TimestampLastUsed) // should be unchanged, we did nothing with the readkey
tt.RequestAuthGetRaw(t, data.ReadKey, baseUrl, fmt.Sprintf("/api/v2/users/%s", data.UID))
rkey4 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, readKeyID))
tt.AssertEqual(t, "timestamp_lastused", *rkey2.TimestampLastUsed, *rkey4.TimestampLastUsed) // still the same - the DCI is pending
time.Sleep(6 * time.Second) // wait for second DCI
rkey5 := tt.RequestAuthGet[keyobj](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.UID, readKeyID))
tt.AssertNotEqual(t, "timestamp_lastused", *rkey2.TimestampLastUsed, *rkey5.TimestampLastUsed) // did
tt.AssertEqual(t, "timestamp_lastused", -1, strings.Compare(*rkey2.TimestampLastUsed, *rkey5.TimestampLastUsed))
}