@@ -24,7 +24,7 @@ import XCTest
2424class AWSAuthNetworkTimeoutDuringTokenRefreshTests : BaseAuthorizationTests {
2525
2626 // MARK: - Test: Network timeout during token refresh should preserve isSignedIn = true
27-
27+
2828 /// Test that network timeout during token refresh preserves signed-in state
2929 ///
3030 /// - Given: A signed-in user with expired tokens that need refresh
@@ -38,7 +38,7 @@ class AWSAuthNetworkTimeoutDuringTokenRefreshTests: BaseAuthorizationTests {
3838 func testNetworkTimeoutDuringTokenRefresh_ShouldPreserveSignedInState( ) async throws {
3939 // Expectation to verify the mock was actually called
4040 let tokenRefreshExpectation = expectation ( description: " Token refresh should be called " )
41-
41+
4242 // Setup: User is signed in with expired tokens
4343 let initialState = AuthState . configured (
4444 AuthenticationState . signedIn ( . testData) ,
@@ -51,7 +51,7 @@ class AWSAuthNetworkTimeoutDuringTokenRefreshTests: BaseAuthorizationTests {
5151 let getTokensFromRefreshToken : MockIdentityProvider . MockGetTokensFromRefreshTokenResponse = { _ in
5252 // Fulfill expectation to prove this mock was called
5353 tokenRefreshExpectation. fulfill ( )
54-
54+
5555 // Simulate NSURLErrorTimedOut (-1001)
5656 let networkError = NSError (
5757 domain: NSURLErrorDomain,
@@ -111,7 +111,7 @@ class AWSAuthNetworkTimeoutDuringTokenRefreshTests: BaseAuthorizationTests {
111111 }
112112
113113 // MARK: - Test: Network timeout should NOT clear credentials
114-
114+
115115 /// Test that network timeout during token refresh does not clear stored credentials
116116 ///
117117 /// - Given: A signed-in user with expired tokens
@@ -121,7 +121,7 @@ class AWSAuthNetworkTimeoutDuringTokenRefreshTests: BaseAuthorizationTests {
121121 func testNetworkTimeoutDuringTokenRefresh_ShouldNotClearCredentials( ) async throws {
122122 // Expectation to verify the mock was actually called
123123 let tokenRefreshExpectation = expectation ( description: " Token refresh should be called " )
124-
124+
125125 let initialState = AuthState . configured (
126126 AuthenticationState . signedIn ( . testData) ,
127127 AuthorizationState . sessionEstablished (
@@ -152,19 +152,19 @@ class AWSAuthNetworkTimeoutDuringTokenRefreshTests: BaseAuthorizationTests {
152152 XCTAssertTrue ( session. isSignedIn)
153153
154154 // Identity ID should still be available (from cached credentials)
155- let identityIdResult = ( session as? AuthCognitoIdentityProvider ) ? . getIdentityId ( )
155+ _ = ( session as? AuthCognitoIdentityProvider ) ? . getIdentityId ( )
156156 // Note: Identity ID may fail if it depends on token refresh, but the key point
157157 // is that isSignedIn remains true
158158 }
159159
160160 // MARK: - Test: Connection lost during token refresh
161-
161+
162162 /// Test that connection lost error during token refresh preserves signed-in state
163163 ///
164164 func testConnectionLostDuringTokenRefresh_ShouldPreserveSignedInState( ) async throws {
165165 // Expectation to verify the mock was actually called
166166 let tokenRefreshExpectation = expectation ( description: " Token refresh should be called " )
167-
167+
168168 let initialState = AuthState . configured (
169169 AuthenticationState . signedIn ( . testData) ,
170170 AuthorizationState . sessionEstablished (
@@ -199,13 +199,13 @@ class AWSAuthNetworkTimeoutDuringTokenRefreshTests: BaseAuthorizationTests {
199199 }
200200
201201 // MARK: - Test: No internet connection during token refresh
202-
202+
203203 /// Test that no internet connection error during token refresh preserves signed-in state
204204 ///
205205 func testNoInternetDuringTokenRefresh_ShouldPreserveSignedInState( ) async throws {
206206 // Expectation to verify the mock was actually called
207207 let tokenRefreshExpectation = expectation ( description: " Token refresh should be called " )
208-
208+
209209 let initialState = AuthState . configured (
210210 AuthenticationState . signedIn ( . testData) ,
211211 AuthorizationState . sessionEstablished (
@@ -240,7 +240,7 @@ class AWSAuthNetworkTimeoutDuringTokenRefreshTests: BaseAuthorizationTests {
240240 }
241241
242242 // MARK: - Test: Contrast with actual session expiry (NotAuthorizedException)
243-
243+
244244 /// Test that NotAuthorizedException correctly results in sessionExpired error
245245 /// This contrasts with network errors to show the difference in handling
246246 ///
@@ -253,7 +253,7 @@ class AWSAuthNetworkTimeoutDuringTokenRefreshTests: BaseAuthorizationTests {
253253 func testNotAuthorizedException_ShouldResultInSessionExpired( ) async throws {
254254 // Expectation to verify the mock was actually called
255255 let tokenRefreshExpectation = expectation ( description: " Token refresh should be called " )
256-
256+
257257 let initialState = AuthState . configured (
258258 AuthenticationState . signedIn ( . testData) ,
259259 AuthorizationState . sessionEstablished (
@@ -290,14 +290,14 @@ class AWSAuthNetworkTimeoutDuringTokenRefreshTests: BaseAuthorizationTests {
290290 }
291291
292292 // MARK: - Test: App-level error handling simulation
293-
293+
294294 /// This test demonstrates how apps might incorrectly handle session errors
295295 /// and provides guidance on correct error handling
296296 ///
297297 func testAppErrorHandling_ShouldDistinguishNetworkFromSessionExpiry( ) async throws {
298298 // Expectation to verify the mock was actually called
299299 let tokenRefreshExpectation = expectation ( description: " Token refresh should be called " )
300-
300+
301301 let initialState = AuthState . configured (
302302 AuthenticationState . signedIn ( . testData) ,
303303 AuthorizationState . sessionEstablished (
@@ -330,29 +330,29 @@ class AWSAuthNetworkTimeoutDuringTokenRefreshTests: BaseAuthorizationTests {
330330 if session. isSignedIn {
331331 // User is authenticated, check token availability
332332 let tokensResult = ( session as? AuthCognitoTokensProvider ) ? . getCognitoTokens ( )
333-
333+
334334 switch tokensResult {
335335 case . success:
336336 // Tokens available - proceed normally
337337 break
338-
338+
339339 case . failure( let error) :
340340 switch error {
341341 case . sessionExpired:
342342 // ONLY in this case should the app prompt for re-login
343343 // This means the refresh token is invalid
344344 break
345-
345+
346346 case . service:
347347 // Network or service error - DO NOT log out!
348348 // Retry later or show "offline" message
349349 XCTAssertTrue ( session. isSignedIn, " User should remain signed in for service errors " )
350-
350+
351351 default :
352352 // Other errors - handle appropriately but don't log out
353353 break
354354 }
355-
355+
356356 case . none:
357357 break
358358 }
0 commit comments