Skip to content

Commit

Permalink
Fix login, announcements test and compatibility problem in redirect h…
Browse files Browse the repository at this point in the history
…andler
  • Loading branch information
developerfromjokela committed Sep 5, 2023
1 parent 04d0745 commit 68a115f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Sources/openwilma/Clients/WilmaHTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions Sources/openwilma/Methods/Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions Sources/openwilma/OpenWilma.swift
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 4 additions & 2 deletions Tests/openwilmaTests/AnnouncementsTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand Down

0 comments on commit 68a115f

Please sign in to comment.