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

Commit

Permalink
Merge pull request #2333 from RocketChat/fix/oauth_callback_with_path
Browse files Browse the repository at this point in the history
[FIX] Include path in OAuth callback url building
  • Loading branch information
rafaelks authored Nov 20, 2018
2 parents c78b8e3 + b98279e commit e03e7fe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Rocket.Chat/Managers/OAuthManager.swift
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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() {
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

0 comments on commit e03e7fe

Please # to comment.