Skip to content

Commit f80f705

Browse files
committed
Add 501 as terminating for network switching
1 parent f0bd951 commit f80f705

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

Modules/Sources/NetworkingCore/ApplicationPassword/RequestProcessor.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ private extension RequestProcessor {
107107
} catch {
108108
return false
109109
}
110+
case NetworkError.unacceptableStatusCode(let statusCode, let response) where statusCode == 501:
111+
fallthrough // treat this the same as 404 code
110112
case NetworkError.notFound:
111113
/// Site doesn't support application password
112114
delegate?.didFailToAuthenticateRequestWithApplicationPassword(siteID: currentSiteID)

Modules/Tests/NetworkingTests/ApplicationPassword/RequestProcessorTests.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,36 @@ final class RequestProcessorTests: XCTestCase {
326326
}
327327
}
328328

329+
func test_delegate_called_when_501_error_occurs_with_wpcom_authentication() throws {
330+
// Given
331+
let session = Alamofire.Session(configuration: URLSessionConfiguration.default)
332+
let request = try mockRequest()
333+
let wpcomCredentials = Networking.Credentials.wpcom(username: "test", authToken: "token", siteAddress: "test.com")
334+
let mockDelegate = MockRequestProcessorDelegate()
335+
336+
mockRequestAuthenticator.credentials = wpcomCredentials
337+
mockRequestAuthenticator.jetpackSiteID = 123
338+
sut.updateAuthenticator(mockRequestAuthenticator)
339+
sut.delegate = mockDelegate
340+
341+
let notSupportedError = NetworkError.unacceptableStatusCode(statusCode: 501, response: nil)
342+
mockRequestAuthenticator.mockErrorWhileGeneratingPassword = notSupportedError
343+
344+
// When
345+
let error = RequestAuthenticatorError.applicationPasswordNotAvailable
346+
let shouldRetry = waitFor { promise in
347+
self.sut.retry(request, for: session, dueTo: error) { shouldRetry in
348+
promise(shouldRetry)
349+
}
350+
}
351+
352+
// Then
353+
XCTAssertFalse(shouldRetry.retryRequired)
354+
waitUntil {
355+
mockDelegate.didFailToAuthenticateRequestForSiteID == 123
356+
}
357+
}
358+
329359
func test_request_not_retried_when_other_error_occurs_with_wpcom_authentication() throws {
330360
// Given
331361
let session = Alamofire.Session(configuration: URLSessionConfiguration.default)

WooCommerce/Classes/Yosemite/DefaultStoresManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class DefaultStoresManager: StoresManager {
178178
queue: .main) { [weak self] note in
179179
guard let self else { return }
180180
if isAuthenticatedWithoutWPCom {
181-
deauthenticate()
181+
_ = deauthenticate()
182182
}
183183
}
184184
}

WooCommerce/WooCommerceTests/Yosemite/StoresManagerTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ final class StoresManagerTests: XCTestCase {
452452
MockNotificationCenter.testingInstance.post(name: .ApplicationPasswordsGenerationFailed, object: error, userInfo: nil)
453453

454454
// Assert
455+
XCTAssertFalse(manager.isAuthenticated)
455456
XCTAssertEqual(isLoggedInValues, [false, true, false])
456457
}
457458

0 commit comments

Comments
 (0)