Skip to content

Commit

Permalink
Use tenant.locality.auth0.com as CDN URL [SDK-2709] (#679)
Browse files Browse the repository at this point in the history
* Use tenant.locality.auth0.com as CDN URL

* Fix tests
  • Loading branch information
Widcket authored Sep 17, 2021
1 parent 61013f6 commit 4a2d45a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 27 deletions.
10 changes: 1 addition & 9 deletions Lock/CDNLoaderInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct CDNLoaderInteractor: RemoteConnectionLoader, Loggable {
let url: URL

init(baseURL: URL, clientId: String) {
self.url = URL(string: "client/\(clientId).js", relativeTo: cdnURL(from: baseURL))!
self.url = URL(string: "client/\(clientId).js", relativeTo: baseURL)!
}

func load(_ callback: @escaping (UnrecoverableError?, Connections?) -> Void) {
Expand Down Expand Up @@ -231,11 +231,3 @@ private struct ConnectionInfo {
self.name = name
}
}

private func cdnURL(from url: URL) -> URL {
guard let host = url.host, host.hasSuffix(".auth0.com") else { return url }
let components = host.components(separatedBy: ".")
guard components.count == 4 else { return URL(string: "https://cdn.auth0.com")! }
let region = components[1]
return URL(string: "https://cdn.\(region).auth0.com")!
}
19 changes: 2 additions & 17 deletions LockTests/Interactors/CDNLoaderInteractorSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,9 @@ class CDNLoaderInteractorSpec: QuickSpec {

describe("init") {

it("should build url from non-auth0 domain") {
let loader = CDNLoaderInteractor(baseURL: URL(string: "https://somewhere.far.beyond")!, clientId: clientId)
expect(loader.url.absoluteString) == "https://somewhere.far.beyond/client/\(clientId).js"
}

it("should build url from auth0 domain") {
it("should use the base url to load strategies") {
let loader = CDNLoaderInteractor(baseURL: URL(string: "https://samples.auth0.com")!, clientId: clientId)
expect(loader.url.absoluteString) == "https://cdn.auth0.com/client/\(clientId).js"
}

it("should build url from auth0 domain for eu region") {
let loader = CDNLoaderInteractor(baseURL: URL(string: "https://samples.eu.auth0.com")!, clientId: clientId)
expect(loader.url.absoluteString) == "https://cdn.eu.auth0.com/client/\(clientId).js"
}

it("should build url from auth0 domain for au region") {
let loader = CDNLoaderInteractor(baseURL: URL(string: "https://samples.au.auth0.com")!, clientId: clientId)
expect(loader.url.absoluteString) == "https://cdn.au.auth0.com/client/\(clientId).js"
expect(loader.url.absoluteString) == "https://samples.auth0.com/client/\(clientId).js"
}

}
Expand Down
2 changes: 1 addition & 1 deletion LockTests/Utils/NetworkStub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func isOAuthAccessToken(_ domain: String) -> HTTPStubsTestBlock {
}

func isCDN(forClientId clientId: String) -> HTTPStubsTestBlock {
return isMethodGET() && isHost("cdn.auth0.com") && isPath("/client/\(clientId).js")
return isMethodGET() && isHost("overmind.auth0.com") && isPath("/client/\(clientId).js")
}

// MARK: - Response Stubs
Expand Down

0 comments on commit 4a2d45a

Please sign in to comment.