Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

[FIX] Include path in OAuth callback url building #2333

Merged
merged 3 commits into from Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rocket.Chat/Managers/OAuthManager.swift
Expand Up @@ -86,7 +86,7 @@ final class OAuthManager {
portString = ":\(port)"
}

return URL(string: "https://\(host)\(portString)/_oauth/\(callbackPath)")
return URL(string: "https://\(host)\(portString)\(server.path)/_oauth/\(callbackPath)")
}

static func state() -> String? {
Expand Down
32 changes: 29 additions & 3 deletions Rocket.ChatTests/Managers/OAuthManagerSpec.swift
Expand Up @@ -43,11 +43,37 @@ class OAuthManagerSpec: XCTestCase {
let serverURL: URL! = URL(string: "https://open.rocket.chat")
let expectedURL: URL! = URL(string: "https://open.rocket.chat/_oauth/github")

XCTAssertEqual(OAuthManager.callbackUrl(for: loginService, server: serverURL), expectedURL, "callbackURL returns expected url")
XCTAssertEqual(
OAuthManager.callbackUrl(for: loginService, server: serverURL),
expectedURL,
"callbackURL returns expected url"
)
}

func testCallbackUrlWithPath() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

let loginService = LoginService()
loginService.service = "github"

let serverURL: URL! = URL(string: "https://open.rocket.chat/path")
let expectedURL: URL! = URL(string: "https://open.rocket.chat/path/_oauth/github")

XCTAssertEqual(
OAuthManager.callbackUrl(for: loginService, server: serverURL),
expectedURL,
"callbackURL returns expected url with path"
)
}

func testCallbackUrlMalformed() {
let loginService = LoginService()
loginService.service = "github"

let malformedServerURL: URL! = URL(string: "open.rocket.chat")
let serverURL: URL! = URL(string: "open.rocket.chat")

XCTAssertNil(OAuthManager.callbackUrl(for: loginService, server: malformedServerURL), "callbackURL returns nil with malformed server URL")
XCTAssertNil(
OAuthManager.callbackUrl(for: loginService, server: serverURL),
"callbackURL returns nil with malformed server URL"
)
}

func testState() {
Expand Down