Fix signature verification fallback urls (#5756)

* Fix signature verification for fallback URLs

* Add tests for signing with fallback path

* Lint

* Add log
This commit is contained in:
Antonio Pallares authored and GitHub committed 2025-11-06 22:43:27 +01:00
1 parent 09302f508a
commit eaee0c3592
16 files changed
+4357 -46

No files matched your search

@@ -40,6 +40,9 @@ protocol HTTPRequestPath {
/// The full relative path for this endpoint.
var relativePath: String { get }
/// The fallback relative path for this endpoint, if any.
var fallbackRelativePath: String? { get }
}
extension HTTPRequestPath {
@@ -48,6 +51,10 @@ extension HTTPRequestPath {
return []
}
var fallbackRelativePath: String? {
return nil
}
var url: URL? { return self.url(proxyURL: nil) }
func url(proxyURL: URL? = nil, fallbackUrlIndex: Int? = nil) -> URL? {
@@ -127,23 +134,36 @@ extension HTTPRequest.Path: HTTPRequestPath {
SystemInfo.apiBaseURL
}
private static let fallbackServerHostURL = URL(string: "https://api-production.8-lives-cat.io")
private static let fallbackServerHostURLs = [
URL(string: "https://api-production.8-lives-cat.io")
]
var fallbackUrls: [URL] {
var fallbackRelativePath: String? {
switch self {
case .getOfferings:
return [
// swiftlint:disable:next force_unwrapping
URL(string: "/v1/offerings", relativeTo: Self.fallbackServerHostURL)!
]
return "/v1/offerings"
case .getProductEntitlementMapping:
return [
// swiftlint:disable:next force_unwrapping
URL(string: "/v1/product_entitlement_mapping", relativeTo: Self.fallbackServerHostURL)!
]
return "/v1/product_entitlement_mapping"
default:
return nil
}
}
var fallbackUrls: [URL] {
guard let fallbackRelativePath = self.fallbackRelativePath else {
return []
}
return Self.fallbackServerHostURLs.compactMap { baseURL in
guard let baseURL = baseURL,
let fallbackUrl = URL(string: fallbackRelativePath, relativeTo: baseURL) else {
let errorMessage = "Invalid fallback URL configuration for path: \(self.name)"
assertionFailure(errorMessage)
Logger.error(errorMessage)
return nil
}
return fallbackUrl
}
}
var authenticated: Bool {