@@ -150,6 +150,10 @@ class AWSAuthSignInPluginTests: BasePluginTest {
150
150
///
151
151
func testSignInWithEmptyPassword( ) async {
152
152
153
+ self . mockIdentity = MockIdentity (
154
+ mockGetIdResponse: getId,
155
+ mockGetCredentialsResponse: getCredentials)
156
+
153
157
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
154
158
InitiateAuthOutputResponse (
155
159
authenticationResult: . none,
@@ -674,6 +678,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
674
678
/// - I should get a .service error with .lambda error
675
679
///
676
680
func testSignInWithInvalidLambdaResponseException( ) async {
681
+
677
682
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
678
683
throw InitiateAuthOutputError . invalidLambdaResponseException ( . init( ) )
679
684
} )
@@ -702,6 +707,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
702
707
/// - I should get a .service error with .invalidParameter error
703
708
///
704
709
func testSignInWithInvalidParameterException( ) async {
710
+
705
711
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
706
712
throw InitiateAuthOutputError . invalidParameterException ( . init( ) )
707
713
} )
@@ -730,6 +736,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
730
736
/// - I should get a .configuration error
731
737
///
732
738
func testSignInWithInvalidUserPoolConfigurationException( ) async {
739
+
733
740
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
734
741
throw InitiateAuthOutputError . invalidUserPoolConfigurationException ( . init( ) )
735
742
} )
@@ -757,6 +764,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
757
764
/// - I should get a .notAuthorized error
758
765
///
759
766
func testSignInWithNotAuthorizedException( ) async {
767
+
760
768
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
761
769
throw InitiateAuthOutputError . notAuthorizedException ( . init( ) )
762
770
} )
@@ -784,6 +792,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
784
792
/// - I should get a .resetPassword as next step
785
793
///
786
794
func testSignInWithPasswordResetRequiredException( ) async {
795
+
787
796
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
788
797
throw InitiateAuthOutputError . passwordResetRequiredException ( . init( ) )
789
798
} )
@@ -812,6 +821,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
812
821
/// - I should get a .resetPassword as next step
813
822
///
814
823
func testSignInWithPasswordResetRequiredException2( ) async {
824
+
815
825
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
816
826
let serviceError = SdkError< InitiateAuthOutputError>
817
827
. service( . passwordResetRequiredException( PasswordResetRequiredException ( ) ) ,
@@ -843,6 +853,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
843
853
/// - I should get a .service error with .resourceNotFound error
844
854
///
845
855
func testSignInWithResourceNotFoundException( ) async {
856
+
846
857
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
847
858
throw InitiateAuthOutputError . resourceNotFoundException ( . init( ) )
848
859
} )
@@ -871,6 +882,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
871
882
/// - I should get a .service error with .requestLimitExceeded error
872
883
///
873
884
func testSignInWithTooManyRequestsException( ) async {
885
+
874
886
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
875
887
throw InitiateAuthOutputError . tooManyRequestsException ( . init( ) )
876
888
} )
@@ -899,6 +911,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
899
911
/// - I should get a .service error with .lambda error
900
912
///
901
913
func testSignInWithUnexpectedLambdaException( ) async {
914
+
902
915
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
903
916
throw InitiateAuthOutputError . unexpectedLambdaException ( . init( ) )
904
917
} )
@@ -927,6 +940,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
927
940
/// - I should get a .service error with .lambda error
928
941
///
929
942
func testSignInWithUserLambdaValidationException( ) async {
943
+
930
944
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
931
945
throw InitiateAuthOutputError . userLambdaValidationException ( . init( ) )
932
946
} )
@@ -983,6 +997,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
983
997
/// - I should get a .confirmSignUp as next step
984
998
///
985
999
func testSignInWithUserNotConfirmedException2( ) async {
1000
+
986
1001
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
987
1002
let serviceError = SdkError< InitiateAuthOutputError>
988
1003
. service( . userNotConfirmedException( UserNotConfirmedException ( ) ) ,
@@ -1014,6 +1029,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
1014
1029
/// - I should get a .service error with .userNotFound error
1015
1030
///
1016
1031
func testSignInWithUserNotFoundException( ) async {
1032
+
1017
1033
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
1018
1034
throw InitiateAuthOutputError . userNotFoundException ( . init( ) )
1019
1035
} )
@@ -1044,6 +1060,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
1044
1060
/// - I should get a .service error with .aliasExists error
1045
1061
///
1046
1062
func testSignInWithAliasExistsException( ) async {
1063
+
1047
1064
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
1048
1065
InitiateAuthOutputResponse (
1049
1066
authenticationResult: . none,
@@ -1078,6 +1095,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
1078
1095
/// - I should get a .service error with .invalidPassword error
1079
1096
///
1080
1097
func testSignInWithInvalidPasswordException( ) async {
1098
+
1081
1099
self . mockIdentityProvider = MockIdentityProvider ( mockInitiateAuthResponse: { _ in
1082
1100
InitiateAuthOutputResponse (
1083
1101
authenticationResult: . none,
@@ -1166,4 +1184,69 @@ class AWSAuthSignInPluginTests: BasePluginTest {
1166
1184
XCTFail ( " Received failure with error \( error) " )
1167
1185
}
1168
1186
}
1187
+
1188
+ /// Test a signIn with valid inputs
1189
+ ///
1190
+ /// - Given: Given an auth plugin with mocked service.
1191
+ ///
1192
+ /// - When:
1193
+ /// - I invoke signIn with valid values, and
1194
+ /// AuthN is success whereas AuthZ fails
1195
+ /// In This case, GetId throws an exception
1196
+ /// - Then:
1197
+ /// - I should get a service exception and should not be signed in
1198
+ ///
1199
+ func testSuccessfulSignInWithFailingIdentity( ) async {
1200
+
1201
+ self . mockIdentity = MockIdentity (
1202
+ mockGetIdResponse: { _ in
1203
+ throw GetIdOutputError . invalidParameterException ( . init( message: " Invalid parameter passed " ) )
1204
+ } ,
1205
+ mockGetCredentialsResponse: getCredentials)
1206
+
1207
+ self . mockIdentityProvider = MockIdentityProvider ( mockRevokeTokenResponse: { _ in
1208
+ RevokeTokenOutputResponse ( )
1209
+ } , mockInitiateAuthResponse: { _ in
1210
+ InitiateAuthOutputResponse (
1211
+ authenticationResult: . none,
1212
+ challengeName: . passwordVerifier,
1213
+ challengeParameters: InitiateAuthOutputResponse . validChalengeParams,
1214
+ session: " someSession " )
1215
+ } , mockRespondToAuthChallengeResponse: { _ in
1216
+ RespondToAuthChallengeOutputResponse (
1217
+ authenticationResult: . init(
1218
+ accessToken: Defaults . validAccessToken,
1219
+ expiresIn: 300 ,
1220
+ idToken: " idToken " ,
1221
+ newDeviceMetadata: nil ,
1222
+ refreshToken: " refreshToken " ,
1223
+ tokenType: " " ) ,
1224
+ challengeName: . none,
1225
+ challengeParameters: [ : ] ,
1226
+ session: " session " )
1227
+ } )
1228
+
1229
+ let pluginOptions = AWSAuthSignInOptions ( validationData: [ " somekey " : " somevalue " ] ,
1230
+ metadata: [ " somekey " : " somevalue " ] )
1231
+ let options = AuthSignInRequest . Options ( pluginOptions: pluginOptions)
1232
+
1233
+ do {
1234
+ _ = try await plugin. signIn ( username: " username " , password: " password " , options: options)
1235
+ XCTFail ( " Sign In with failing authorization should throw an error " )
1236
+
1237
+ } catch AuthError . service( _, _, let error) {
1238
+ guard let cognitoError = error as? AWSCognitoAuthError else {
1239
+ XCTFail ( " Underlying error should be of type AWSCognitoAuthError " )
1240
+ return
1241
+ }
1242
+
1243
+ guard case AWSCognitoAuthError . invalidParameter = cognitoError else {
1244
+ XCTFail ( " Error thrown should be an AWSCognitoAuthError.invalidParameter " )
1245
+ return
1246
+ }
1247
+
1248
+ } catch {
1249
+ XCTFail ( " Error thrown should be an AuthError but got: \n \( error) " )
1250
+ }
1251
+ }
1169
1252
}
0 commit comments