55// SPDX-License-Identifier: Apache-2.0
66//
77
8- import XCTest
9- import Amplify
10- import AWSPluginsCore
118import AWSCognitoIdentityProvider
9+ import AWSPluginsCore
10+ import Amplify
11+ import XCTest
1212
1313@testable import AWSCognitoAuthPlugin
1414
@@ -20,18 +20,19 @@ class RefreshUserPoolTokensTests: XCTestCase {
2020
2121 let action = RefreshUserPoolTokens ( existingSignedIndata: . testData)
2222
23- await action. execute ( withDispatcher: MockDispatcher { event in
23+ await action. execute (
24+ withDispatcher: MockDispatcher { event in
2425
25- guard let event = event as? RefreshSessionEvent else {
26- return
27- }
26+ guard let event = event as? RefreshSessionEvent else {
27+ return
28+ }
2829
29- if case let . throwError( error) = event. eventType {
30- XCTAssertNotNil ( error)
31- XCTAssertEqual ( error, . noUserPool)
32- expectation. fulfill ( )
33- }
34- } , environment: MockInvalidEnvironment ( )
30+ if case let . throwError( error) = event. eventType {
31+ XCTAssertNotNil ( error)
32+ XCTAssertEqual ( error, . noUserPool)
33+ expectation. fulfill ( )
34+ }
35+ } , environment: MockInvalidEnvironment ( )
3536 )
3637
3738 await fulfillment (
@@ -53,17 +54,19 @@ class RefreshUserPoolTokensTests: XCTestCase {
5354
5455 let action = RefreshUserPoolTokens ( existingSignedIndata: . testData)
5556
56- await action. execute ( withDispatcher: MockDispatcher { event in
57+ await action. execute (
58+ withDispatcher: MockDispatcher { event in
5759
58- guard let event = event as? RefreshSessionEvent else { return }
60+ guard let event = event as? RefreshSessionEvent else { return }
5961
60- if case let . throwError( error) = event. eventType {
61- XCTAssertNotNil ( error)
62- XCTAssertEqual ( error, . invalidTokens)
63- expectation. fulfill ( )
64- }
65- } , environment: Defaults . makeDefaultAuthEnvironment (
66- userPoolFactory: identityProviderFactory)
62+ if case let . throwError( error) = event. eventType {
63+ XCTAssertNotNil ( error)
64+ XCTAssertEqual ( error, . invalidTokens)
65+ expectation. fulfill ( )
66+ }
67+ } ,
68+ environment: Defaults . makeDefaultAuthEnvironment (
69+ userPoolFactory: identityProviderFactory)
6770 )
6871
6972 await fulfillment (
@@ -90,14 +93,17 @@ class RefreshUserPoolTokensTests: XCTestCase {
9093
9194 let action = RefreshUserPoolTokens ( existingSignedIndata: . testData)
9295
93- await action. execute ( withDispatcher: MockDispatcher { event in
96+ await action. execute (
97+ withDispatcher: MockDispatcher { event in
9498
95- if let userPoolEvent = event as? RefreshSessionEvent ,
96- case . refreshIdentityInfo = userPoolEvent. eventType {
97- expectation. fulfill ( )
98- }
99- } , environment: Defaults . makeDefaultAuthEnvironment (
100- userPoolFactory: identityProviderFactory)
99+ if let userPoolEvent = event as? RefreshSessionEvent ,
100+ case . refreshIdentityInfo = userPoolEvent. eventType
101+ {
102+ expectation. fulfill ( )
103+ }
104+ } ,
105+ environment: Defaults . makeDefaultAuthEnvironment (
106+ userPoolFactory: identityProviderFactory)
101107 )
102108
103109 await fulfillment (
@@ -128,15 +134,17 @@ class RefreshUserPoolTokensTests: XCTestCase {
128134
129135 let action = RefreshUserPoolTokens ( existingSignedIndata: . testData)
130136
131- await action. execute ( withDispatcher: MockDispatcher { event in
137+ await action. execute (
138+ withDispatcher: MockDispatcher { event in
132139
133- if let userPoolEvent = event as? RefreshSessionEvent ,
134- case let . throwError( error) = userPoolEvent. eventType {
135- XCTAssertNotNil ( error)
136- XCTAssertEqual ( error, . service( testError) )
137- expectation. fulfill ( )
138- }
139- } , environment: environment)
140+ if let userPoolEvent = event as? RefreshSessionEvent ,
141+ case let . throwError( error) = userPoolEvent. eventType
142+ {
143+ XCTAssertNotNil ( error)
144+ XCTAssertEqual ( error, . service( testError) )
145+ expectation. fulfill ( )
146+ }
147+ } , environment: environment)
140148
141149 await fulfillment (
142150 of: [ expectation] ,
@@ -162,26 +170,29 @@ class RefreshUserPoolTokensTests: XCTestCase {
162170
163171 let action = RefreshUserPoolTokens ( existingSignedIndata: . testData)
164172
165- await action. execute ( withDispatcher: MockDispatcher { event in
173+ await action. execute (
174+ withDispatcher: MockDispatcher { event in
166175
167- if let userPoolEvent = event as? RefreshSessionEvent ,
168- case let . refreshIdentityInfo( signedInData, _) = userPoolEvent. eventType {
169- XCTAssertEqual ( signedInData. cognitoUserPoolTokens. refreshToken, " refreshTokenRotated " )
170- expectation. fulfill ( )
171- }
172- } , environment: Defaults . makeDefaultAuthEnvironment (
173- userPoolFactory: identityProviderFactory)
176+ if let userPoolEvent = event as? RefreshSessionEvent ,
177+ case let . refreshIdentityInfo( signedInData, _) = userPoolEvent. eventType
178+ {
179+ XCTAssertEqual (
180+ signedInData. cognitoUserPoolTokens. refreshToken, " refreshTokenRotated " )
181+ expectation. fulfill ( )
182+ }
183+ } ,
184+ environment: Defaults . makeDefaultAuthEnvironment (
185+ userPoolFactory: identityProviderFactory)
174186 )
175187
176188 await fulfillment (
177189 of: [ expectation] ,
178190 timeout: 0.1
179191 )
180192 }
193+ func testRefreshTokenMissing( ) async {
181194
182- func testRefreshTokenNoRotation( ) async {
183-
184- let expectation = expectation ( description: " refreshTokenNoRotation " )
195+ let expectation = expectation ( description: " refreshTokenMissing " )
185196 let identityProviderFactory : BasicSRPAuthEnvironment . CognitoUserPoolFactory = {
186197 MockIdentityProvider (
187198 mockGetTokensFromRefreshTokenResponse: { _ in
@@ -197,21 +208,23 @@ class RefreshUserPoolTokensTests: XCTestCase {
197208
198209 let action = RefreshUserPoolTokens ( existingSignedIndata: . testData)
199210
200- await action. execute ( withDispatcher: MockDispatcher { event in
211+ await action. execute (
212+ withDispatcher: MockDispatcher { event in
201213
202- if let userPoolEvent = event as? RefreshSessionEvent ,
203- case let . refreshIdentityInfo( signedInData, _) = userPoolEvent. eventType {
204- XCTAssertEqual ( signedInData. cognitoUserPoolTokens. refreshToken, " refreshToken " )
205- expectation. fulfill ( )
206- }
207- } , environment: Defaults . makeDefaultAuthEnvironment (
208- userPoolFactory: identityProviderFactory)
214+ if let userPoolEvent = event as? RefreshSessionEvent ,
215+ case let . throwError( error) = userPoolEvent. eventType
216+ {
217+ XCTAssertEqual ( error, . invalidTokens)
218+ expectation. fulfill ( )
219+ }
220+ } ,
221+ environment: Defaults . makeDefaultAuthEnvironment (
222+ userPoolFactory: identityProviderFactory)
209223 )
210224
211225 await fulfillment (
212226 of: [ expectation] ,
213227 timeout: 0.1
214228 )
215229 }
216-
217230}
0 commit comments