test: update device authentication tests

- Change Kobo sync endpoints to use URL token authentication
- Update OPDS tests to use device tokens instead of user tokens
- Support both Bearer and query parameter authentication methods
- Return error when test user already exists instead of deleting
- Prevent test interference from cleanup operations
- Improve test isolation and reliability
This commit is contained in:
2026-02-13 16:38:00 -05:00
parent 527c406f75
commit b33b941d0e
2 changed files with 81 additions and 54 deletions
+6 -11
View File
@@ -1,4 +1,4 @@
package bookhoard/cmd/server/tests
package main
import (
"bookhoard/internal/handlers"
@@ -31,8 +31,7 @@ func TestKoboInitialization(t *testing.T) {
deviceSetup := setupDeviceTest(t)
koboDevice := deviceSetup.CreateDevice(t, "Test Kobo", "kobo", "kobo-clara-test")
req, _ := http.NewRequest("GET", setup.Server.URL+"/api/sync/kobo/v1/initialization", nil)
req.Header.Set("Authorization", "Bearer "+koboDevice.AuthToken)
req, _ := http.NewRequest("GET", setup.Server.URL+"/api/sync/kobo/"+koboDevice.AuthToken+"/v1/initialization", nil)
req.Header.Set("x-kobo-device", fmt.Sprintf(`{"DeviceId":"%s","Model":"Kobo Clara","SerialNumber":"%s"}`,
koboDevice.ID.String(), koboDevice.Identifier))
@@ -61,8 +60,7 @@ func TestKoboLibrarySync(t *testing.T) {
deviceSetup := setupDeviceTest(t)
koboDevice := deviceSetup.CreateDevice(t, "Test Kobo", "kobo", "kobo-clara-test")
req, _ := http.NewRequest("GET", setup.Server.URL+"/api/sync/kobo/v1/initialization", nil)
req.Header.Set("Authorization", "Bearer "+koboDevice.AuthToken)
req, _ := http.NewRequest("GET", setup.Server.URL+"/api/sync/kobo/"+koboDevice.AuthToken+"/v1/initialization", nil)
req.Header.Set("x-kobo-device", fmt.Sprintf(`{"DeviceId":"%s","Model":"Kobo Clara","SerialNumber":"%s"}`,
koboDevice.ID.String(), koboDevice.Identifier))
@@ -126,9 +124,8 @@ func TestKoboMarkupSync(t *testing.T) {
}
body, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("POST", setup.Server.URL+"/api/sync/kobo/markup", bytes.NewReader(body))
req, _ := http.NewRequest("POST", setup.Server.URL+"/api/sync/kobo/"+koboDevice.AuthToken+"/markup", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+koboDevice.AuthToken)
req.Header.Set("x-kobo-device", fmt.Sprintf(`{"DeviceId":"%s","Model":"Kobo Clara","SerialNumber":"%s"}`,
koboDevice.ID.String(), koboDevice.Identifier))
@@ -181,9 +178,8 @@ func TestKoboBookmarkSync(t *testing.T) {
}
body, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("POST", setup.Server.URL+"/api/sync/kobo/bookmark", bytes.NewReader(body))
req, _ := http.NewRequest("POST", setup.Server.URL+"/api/sync/kobo/"+koboDevice.AuthToken+"/bookmark", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+koboDevice.AuthToken)
req.Header.Set("x-kobo-device", fmt.Sprintf(`{"DeviceId":"%s","Model":"Kobo Clara","SerialNumber":"%s"}`,
koboDevice.ID.String(), koboDevice.Identifier))
@@ -225,9 +221,8 @@ func TestKoboAnalyticsGettests(t *testing.T) {
}
body, _ := json.Marshal(reqBody)
req, _ := http.NewRequest("POST", setup.Server.URL+"/api/sync/kobo/v1/analytics/gettests", bytes.NewReader(body))
req, _ := http.NewRequest("POST", setup.Server.URL+"/api/sync/kobo/"+koboDevice.AuthToken+"/v1/analytics/gettests", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+koboDevice.AuthToken)
req.Header.Set("x-kobo-device", fmt.Sprintf(`{"DeviceId":"%s","Model":"Kobo Clara","SerialNumber":"%s"}`,
koboDevice.ID.String(), koboDevice.Identifier))