From 68a115f823ed093ed624085f1472ae615dff0b94 Mon Sep 17 00:00:00 2001 From: Developer From Jokela Date: Tue, 5 Sep 2023 14:53:46 +0300 Subject: [PATCH] Fix login, announcements test and compatibility problem in redirect handler --- Sources/openwilma/Clients/WilmaHTTPClient.swift | 2 +- Sources/openwilma/Methods/Authentication.swift | 1 + Sources/openwilma/OpenWilma.swift | 4 ++-- Tests/openwilmaTests/AnnouncementsTest.swift | 6 ++++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Sources/openwilma/Clients/WilmaHTTPClient.swift b/Sources/openwilma/Clients/WilmaHTTPClient.swift index 2cc93be..84bd3cc 100644 --- a/Sources/openwilma/Clients/WilmaHTTPClient.swift +++ b/Sources/openwilma/Clients/WilmaHTTPClient.swift @@ -12,7 +12,7 @@ struct WilmaRedirectHandler: RedirectHandler { func task(_ task: URLSessionTask, willBeRedirectedTo request: URLRequest, for response: HTTPURLResponse, completion: @escaping (URLRequest?) -> Void) { if ((response.url?.query?.contains("invalidsession")) == true) { var newReq = request - newReq.url = URL(string: (request.url?.baseURL?.formatted() ?? "")+"/messages/index_json", relativeTo: request.url) + newReq.url = URL(string: (request.url?.baseURL?.absoluteString ?? "")+"/messages/index_json", relativeTo: request.url) completion(newReq) return } diff --git a/Sources/openwilma/Methods/Authentication.swift b/Sources/openwilma/Methods/Authentication.swift index 4fbb26d..0a77ab3 100644 --- a/Sources/openwilma/Methods/Authentication.swift +++ b/Sources/openwilma/Methods/Authentication.swift @@ -29,6 +29,7 @@ public extension OpenWilma { "format": "json" ] urlRequest.httpBody = try URLEncodedFormEncoder().encode(parameters) + urlRequest.headers = [HTTPHeader(name: "Cookie", value: "Wilma2LoginID=\(sessionId.sessionId)")] let response = await WilmaHTTPClient.shared.postRequest(urlRequest, noRedirect: true).serializingString().response diff --git a/Sources/openwilma/OpenWilma.swift b/Sources/openwilma/OpenWilma.swift index cfe6202..0ac6779 100644 --- a/Sources/openwilma/OpenWilma.swift +++ b/Sources/openwilma/OpenWilma.swift @@ -1,6 +1,6 @@ public struct OpenWilma { public static var disableRoleRequirement = false - public static let versionName = "0.9-beta" - public static let version = 1 + public static let versionName = "0.9.1-beta" + public static let version = 2 public static let minimumSupportedWilmaVersion = 19 } diff --git a/Tests/openwilmaTests/AnnouncementsTest.swift b/Tests/openwilmaTests/AnnouncementsTest.swift index 2d9dd39..09b0af9 100644 --- a/Tests/openwilmaTests/AnnouncementsTest.swift +++ b/Tests/openwilmaTests/AnnouncementsTest.swift @@ -6,7 +6,9 @@ class AnnouncementsTest: XCTestCase { private var session: WilmaSession? = nil override func setUp() async throws { - session = try await OpenWilma.signIn(server, "oppilas", "oppilas") + session = try await OpenWilma.signIn(server, "ope", "ope") + let roles = try await OpenWilma.getRoles(session!) + session?.setRole((roles.payload?.first {$0.type != .wilma_account})!) } /// Network @@ -17,7 +19,7 @@ class AnnouncementsTest: XCTestCase { } func testLoadingContent() async throws { - let announcementsList = try await OpenWilma.getAnnouncement(session!, 57) + let announcementsList = try await OpenWilma.getAnnouncement(session!, 21) print(announcementsList) }