Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support regular urls that have a path component #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion Sources/Compass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public struct Compass {
}

static func parseComponents(url: URL, payload: Any? = nil) -> Location? {
guard let route = url.host else { return nil }
guard let host = url.host else { return nil }
let route = "\(host)\(url.path)"

let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false)
var arguments = [String : String]()
Expand Down
38 changes: 19 additions & 19 deletions Tests/Compass/CompassTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CompassTests: XCTestCase {
"profile:{user}",
"profile:admin",
"login",
"callback",
"callback/path",
"user:list:{userId}:{kind}",
"user:list",
"{appId}:user:list:{userId}:{kind}"
Expand Down Expand Up @@ -130,134 +130,134 @@ class CompassTests: XCTestCase {
}

func testParseRegularURLWithFragments() {
let url = URL(string: "compassTests://callback/#access_token=IjvcgrkQk1p7TyJxKa26rzM1wBMFZW6XoHK4t5Gkt1xQLTN8l7ppR0H3EZXpoP0uLAN49oCDqTHsvnEV&token_type=Bearer&expires_in=3600")!
let url = URL(string: "compassTests://callback/path/#access_token=IjvcgrkQk1p7TyJxKa26rzM1wBMFZW6XoHK4t5Gkt1xQLTN8l7ppR0H3EZXpoP0uLAN49oCDqTHsvnEV&token_type=Bearer&expires_in=3600")!

guard let location = Compass.parse(url: url) else {
XCTFail("Compass parsing failed")
return
}

XCTAssertEqual(location.path, "callback")
XCTAssertEqual(location.path, "callback/path")
XCTAssertEqual(location.arguments.count, 3)
XCTAssertEqual(location.arguments["access_token"], "IjvcgrkQk1p7TyJxKa26rzM1wBMFZW6XoHK4t5Gkt1xQLTN8l7ppR0H3EZXpoP0uLAN49oCDqTHsvnEV")
XCTAssertEqual(location.arguments["expires_in"], "3600")
XCTAssertEqual(location.arguments["token_type"], "Bearer")
}

func testParseRegularURLWithFragmentsAndGoogleOAuth2AccessToken() {
let url = URL(string: "compassTests://callback/#access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ&token_type=Bearer&expires_in=3600")!
let url = URL(string: "compassTests://callback/path/#access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ&token_type=Bearer&expires_in=3600")!

guard let location = Compass.parse(url: url) else {
XCTFail("Compass parsing failed")
return
}

XCTAssertEqual(location.path, "callback")
XCTAssertEqual(location.path, "callback/path")
XCTAssertEqual(location.arguments.count, 3)
XCTAssertEqual(location.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ")
XCTAssertEqual(location.arguments["expires_in"], "3600")
XCTAssertEqual(location.arguments["token_type"], "Bearer")
}

func testParseRegularURLWithFragmentsAndAlternativeAccessToken() {
let url = URL(string: "compassTests://callback/#access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=&token_type=Bearer&expires_in=3600")!
let url = URL(string: "compassTests://callback/path/#access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=&token_type=Bearer&expires_in=3600")!

guard let location = Compass.parse(url: url) else {
XCTFail("Compass parsing failed")
return
}

XCTAssertEqual(location.path, "callback")
XCTAssertEqual(location.path, "callback/path")
XCTAssertEqual(location.arguments.count, 3)
XCTAssertEqual(location.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=")
XCTAssertEqual(location.arguments["expires_in"], "3600")
XCTAssertEqual(location.arguments["token_type"], "Bearer")
}

func testParseRegularURLWithSlashQuery() {
let url = URL(string: "compassTests://callback/?access_token=Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l&token_type=Bearer&expires_in=3600")!
let url = URL(string: "compassTests://callback/path/?access_token=Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l&token_type=Bearer&expires_in=3600")!

guard let location = Compass.parse(url: url) else {
XCTFail("Compass parsing failed")
return
}

XCTAssertEqual(location.path, "callback")
XCTAssertEqual(location.path, "callback/path")
XCTAssertEqual(location.arguments.count, 3)
XCTAssertEqual(location.arguments["access_token"], "Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l")
XCTAssertEqual(location.arguments["expires_in"], "3600")
XCTAssertEqual(location.arguments["token_type"], "Bearer")
}

func testParseRegularURLWithSlashQueryAndGoogleOAuth2AccessToken() {
let url = URL(string: "compassTests://callback/?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ&token_type=Bearer&expires_in=3600")!
let url = URL(string: "compassTests://callback/path/?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ&token_type=Bearer&expires_in=3600")!

guard let location = Compass.parse(url: url) else {
XCTFail("Compass parsing failed")
return
}

XCTAssertEqual(location.path, "callback")
XCTAssertEqual(location.path, "callback/path")
XCTAssertEqual(location.arguments.count, 3)
XCTAssertEqual(location.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ")
XCTAssertEqual(location.arguments["expires_in"], "3600")
XCTAssertEqual(location.arguments["token_type"], "Bearer")
}

func testParseRegularURLWithSlashQueryAndAlternativeAccessToken() {
let url = URL(string: "compassTests://callback/?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=&token_type=Bearer&expires_in=3600")!
let url = URL(string: "compassTests://callback/path/?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=&token_type=Bearer&expires_in=3600")!

guard let location = Compass.parse(url: url) else {
XCTFail("Compass parsing failed")
return
}

XCTAssertEqual(location.path, "callback")
XCTAssertEqual(location.path, "callback/path")
XCTAssertEqual(location.arguments.count, 3)
XCTAssertEqual(location.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=")
XCTAssertEqual(location.arguments["expires_in"], "3600")
XCTAssertEqual(location.arguments["token_type"], "Bearer")
}

func testParseRegularURLWithQuery() {
let url = URL(string: "compassTests://callback?access_token=Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l&token_type=Bearer&expires_in=3600")!
let url = URL(string: "compassTests://callback/path?access_token=Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l&token_type=Bearer&expires_in=3600")!

guard let location = Compass.parse(url: url) else {
XCTFail("Compass parsing failed")
return
}

XCTAssertEqual(location.path, "callback")
XCTAssertEqual(location.path, "callback/path")
XCTAssertEqual(location.arguments.count, 3)
XCTAssertEqual(location.arguments["access_token"], "Yo0OMrVZbRWNmgA6BT99hyuTUTNRGvqEEAQyeN1eslclzhFD0M8AidB4Z7Vs2NU8WoSNW0vYb961O38l")
XCTAssertEqual(location.arguments["expires_in"], "3600")
XCTAssertEqual(location.arguments["token_type"], "Bearer")
}

func testParseRegularURLWithQueryAndGoogleOAuth2AccessToken() {
let url = URL(string: "compassTests://callback?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ&token_type=Bearer&expires_in=3600")!
let url = URL(string: "compassTests://callback/path?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ&token_type=Bearer&expires_in=3600")!

guard let location = Compass.parse(url: url) else {
XCTFail("Compass parsing failed")
return
}

XCTAssertEqual(location.path, "callback")
XCTAssertEqual(location.path, "callback/path")
XCTAssertEqual(location.arguments.count, 3)
XCTAssertEqual(location.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ")
XCTAssertEqual(location.arguments["expires_in"], "3600")
XCTAssertEqual(location.arguments["token_type"], "Bearer")
}

func testParseRegularURLWithQueryAndAlternativeAccessToken() {
let url = URL(string: "compassTests://callback?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=&token_type=Bearer&expires_in=3600")!
let url = URL(string: "compassTests://callback/path?access_token=ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=&token_type=Bearer&expires_in=3600")!

guard let location = Compass.parse(url: url) else {
XCTFail("Compass parsing failed")
return
}

XCTAssertEqual(location.path, "callback")
XCTAssertEqual(location.path, "callback/path")
XCTAssertEqual(location.arguments.count, 3)
XCTAssertEqual(location.arguments["access_token"], "ya29.Ci8nA1pNVMFffHkS5-sXooNGvTB9q8QPtoM56sWpipRyjhwwEiKyZxvRQTR8saqWzQ=")
XCTAssertEqual(location.arguments["expires_in"], "3600")
Expand Down