-
Notifications
You must be signed in to change notification settings - Fork 48
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
Fix issue #43—Callback url registered incorrectly if using route groups #102
Conversation
@@ -4,7 +4,20 @@ import XCTest | |||
class ImperialTests: XCTestCase { | |||
func testExists() {} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests for different kinds of grouped scenarios
public func configureRoutes(withAuthURL authURL: String, authenticateCallback: ((Request) throws -> (EventLoopFuture<Void>))?, on router: RoutesBuilder) throws { | ||
router.get(callbackURL.pathComponents, use: callback) | ||
router.get(authURL.pathComponents) { req -> EventLoopFuture<Response> in | ||
public func configureRoutes(grouped: [PathComponent], withAuthURL authURL: String, authenticateCallback: ((Request) throws -> (EventLoopFuture<Void>))?, on router: RoutesBuilder) throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new func pathComponents(grouped:) on both callbackURL and authURL
@@ -2,16 +2,31 @@ import Foundation | |||
import RoutingKit | |||
|
|||
extension String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change pathComponents
var to a func with grouped: [PathComponent]
parameter.
Break url path into array of components like before.
Remove any duplicates with grouped
at beginning of array.
Stop immediately when a component at the same index does not match.
@@ -6,6 +6,7 @@ public class DeviantArt: FederatedService { | |||
|
|||
@discardableResult | |||
public required init( | |||
grouped: [PathComponent], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add parameter grouped: [PathComponent]
It gets passed down in to where the callback
url is parsed into path components and registered.
Any overlap between callback url path components and grouped
parameter is removed before registration.
So the grouped route matches the callback url.
Just an FYI I'm going to be doing an Imperial code sprint next week to go through all the issues and PRs |
@fpseverino can we check that this is fixed in 2.0.0 beta? |
Yeas, it looks like it's fixed now. In #109 I switched from using a custom implementation of |
Attempt to fix issue #43—Callback url registered incorrectly if using route groups.
It adds an optional parameter to
ServiceRegister
calledgrouped: [PathComponent]
Can be used with group routes like this...
Ungroued routes can omit the parameter. So existing usage should not change.
The parameter is passed down to FederatedServiceRouter
configureRoutes(grouped:withAuthURL:authenticateCallback:on:)
where the callback URL gets registered.When breaking the
callbackURL
into path components, duplicate components at the head of the path are removed. So the grouped route is registered properly and matches the callback url.Most of the work happens inside
ImperialCore
>Helpers
>String + Tools.swift
>pathComponents(grouped:)
Also added a few tests for different kinds of groups and callback urls.
Happy to add readme stuff if you like the fix.