Skip to content

Commit 8d82d3f

Browse files
authored
chore: kickoff release
2 parents e15aabc + 513e371 commit 8d82d3f

File tree

35 files changed

+351
-3006
lines changed

35 files changed

+351
-3006
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,18 @@ commands:
107107
- run:
108108
name: Checkout code shallow and change to working directory
109109
command: |
110-
git clone --depth 1 "$CIRCLE_REPOSITORY_URL" --branch "$CIRCLE_BRANCH" $CIRCLE_WORKING_DIRECTORY
110+
git clone --depth 10 "$CIRCLE_REPOSITORY_URL" --branch "$CIRCLE_BRANCH" $CIRCLE_WORKING_DIRECTORY
111111
cd $CIRCLE_WORKING_DIRECTORY
112112
113113
if [ -n "$CIRCLE_TAG" ]; then
114114
echo 'Fetch tag'
115-
git fetch --depth 1 --force origin "+refs/tags/${CIRCLE_TAG}:refs/tags/${CIRCLE_TAG}"
115+
git fetch --depth 10 --force origin "+refs/tags/${CIRCLE_TAG}:refs/tags/${CIRCLE_TAG}"
116116
elif [[ $(echo $CIRCLE_PULL_REQUEST | grep -E "${CIRCLE_BRANCH}$") ]]; then
117117
echo 'Fetch pull request'
118-
git fetch --depth 1 --force origin "$CIRCLE_BRANCH/head:remotes/origin/$CIRCLE_BRANCH"
118+
git fetch --depth 10 --force origin "$CIRCLE_BRANCH/head:remotes/origin/$CIRCLE_BRANCH"
119119
else
120120
echo 'Fetch branch'
121-
git fetch --depth 1 --force origin "$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH"
121+
git fetch --depth 10 --force origin "$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH"
122122
fi
123123
echo "Checking out the CI HEAD"
124124
git reset --hard "$CIRCLE_SHA1"

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/Helpers/HostedUISignInHelper.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@ struct HostedUISignInHelper: DefaultLogger {
2626

2727
func initiateSignIn() async throws -> AuthSignInResult {
2828
try await isValidState()
29-
log.verbose("Start signIn flow")
30-
return try await doSignIn()
29+
do {
30+
log.verbose("Start signIn flow")
31+
let result = try await doSignIn()
32+
log.verbose("Received result")
33+
return result
34+
} catch {
35+
await waitForSignInCancel()
36+
throw error
37+
}
3138
}
3239

3340
func isValidState() async throws {
@@ -80,23 +87,20 @@ struct HostedUISignInHelper: DefaultLogger {
8087
switch authNState {
8188
case .signedIn:
8289
if case .sessionEstablished = authZState {
83-
return AuthSignInResult(nextStep: .done)
90+
return AuthSignInResult(nextStep: .done)
91+
} else if case .error(let error) = authZState {
92+
log.verbose("Authorization reached an error state \(error)")
93+
throw error.authError
8494
}
8595

8696
case .error(let error):
87-
await waitForSignInCancel()
8897
throw error.authError
8998

9099
case .signingIn(let signInState):
91-
do {
92-
guard let result = try UserPoolSignInHelper.checkNextStep(signInState) else {
93-
continue
94-
}
95-
return result
96-
} catch {
97-
await waitForSignInCancel()
98-
throw error
100+
guard let result = try UserPoolSignInHelper.checkNextStep(signInState) else {
101+
continue
99102
}
103+
return result
100104
default:
101105
continue
102106
}
@@ -143,6 +147,10 @@ struct HostedUISignInHelper: DefaultLogger {
143147
switch authenticationState {
144148
case .signedOut:
145149
return
150+
case .signingOut(let signingOutState):
151+
if case .error = signingOutState {
152+
return
153+
}
146154
default: continue
147155
}
148156
}

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Errors/AuthorizationError.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ extension AuthorizationError: AuthErrorConvertible {
2626
case .configuration(let message):
2727
return .configuration(message, "")
2828
case .service(let error):
29-
if let getIdOutputError = error as? SdkError<GetIdOutputError> {
30-
return getIdOutputError.authError
31-
} else if let getCredentialForIdentityError = error as? SdkError<GetCredentialsForIdentityOutputError> {
32-
return getCredentialForIdentityError.authError
33-
} else if let authError = error as? AuthError {
34-
return authError
29+
if let convertibleError = error as? AuthErrorConvertible {
30+
return convertibleError.authError
3531
} else {
36-
return AuthError.unknown("", error)
32+
return .service(
33+
"Service error occurred",
34+
AmplifyErrorMessages.reportBugToAWS(),
35+
error)
3736
}
3837
case .invalidState(let message):
3938
return .invalidState(message, AuthPluginErrorConstants.invalidStateError, nil)

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Errors/FetchSessionError.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,14 @@ extension FetchSessionError: AuthErrorConvertible {
7979
return .unknown(
8080
"Refreshing credentials from federationToIdentityPool is not supported \(AmplifyErrorMessages.reportBugToAWS())")
8181
case .service(let error):
82-
return .service(
83-
"Service error occurred",
84-
AmplifyErrorMessages.reportBugToAWS(),
85-
error)
82+
if let convertibleError = error as? AuthErrorConvertible {
83+
return convertibleError.authError
84+
} else {
85+
return .service(
86+
"Service error occurred",
87+
AmplifyErrorMessages.reportBugToAWS(),
88+
error)
89+
}
8690
}
8791
}
8892

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/Authentication/AuthenticationState+Resolver.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ extension AuthenticationState {
202202
)
203203
return resolution
204204

205+
case .cancelSignIn:
206+
let action = InitiateSignOut(
207+
signedInData: currentSignedInData,
208+
signOutEventData: .init(globalSignOut: false))
209+
let signOutState = SignOutState.notStarted
210+
let resolution = StateResolution(
211+
newState: AuthenticationState.signingOut(signOutState),
212+
actions: [action]
213+
)
214+
return resolution
205215
default:
206216
return .from(.signedIn(currentSignedInData))
207217
}

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Helpers/UserPoolSignInHelper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct UserPoolSignInHelper: DefaultLogger {
8181

8282
let client = try environment.cognitoUserPoolFactory()
8383
let response = try await client.respondToAuthChallenge(input: request)
84-
let event = try self.parseResponse(response, for: username, signInMethod: signInMethod)
84+
let event = self.parseResponse(response, for: username, signInMethod: signInMethod)
8585
return event
8686
}
8787

@@ -90,7 +90,7 @@ struct UserPoolSignInHelper: DefaultLogger {
9090
static func parseResponse(
9191
_ response: SignInResponseBehavior,
9292
for username: String,
93-
signInMethod: SignInMethod) throws -> StateMachineEvent {
93+
signInMethod: SignInMethod) -> StateMachineEvent {
9494

9595
if let authenticationResult = response.authenticationResult,
9696
let idToken = authenticationResult.idToken,

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignInTask.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class AWSAuthSignInTask: AuthSignInTask, DefaultLogger {
4545
let authflowType = authFlowType(userPoolConfiguration: userPoolConfiguration)
4646
do {
4747
log.verbose("Signing with \(authflowType)")
48-
let result = try await doSignIn(authflowType: authflowType)
48+
let result = try await doSignIn(authflowType: authflowType)
4949
log.verbose("Received result")
5050
return result
5151
} catch {
@@ -95,8 +95,7 @@ class AWSAuthSignInTask: AuthSignInTask, DefaultLogger {
9595
return AuthSignInResult(nextStep: .done)
9696
} else if case .error(let error) = authZState {
9797
log.verbose("Authorization reached an error state \(error)")
98-
let error = AuthError.unknown("Sign in reached an error state", error)
99-
throw error
98+
throw error.authError
10099
}
101100
case .error(let error):
102101
throw error.authError

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/AWSAuthSignInPluginTests.swift

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ class AWSAuthSignInPluginTests: BasePluginTest {
150150
///
151151
func testSignInWithEmptyPassword() async {
152152

153+
self.mockIdentity = MockIdentity(
154+
mockGetIdResponse: getId,
155+
mockGetCredentialsResponse: getCredentials)
156+
153157
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
154158
InitiateAuthOutputResponse(
155159
authenticationResult: .none,
@@ -674,6 +678,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
674678
/// - I should get a .service error with .lambda error
675679
///
676680
func testSignInWithInvalidLambdaResponseException() async {
681+
677682
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
678683
throw InitiateAuthOutputError.invalidLambdaResponseException(.init())
679684
})
@@ -702,6 +707,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
702707
/// - I should get a .service error with .invalidParameter error
703708
///
704709
func testSignInWithInvalidParameterException() async {
710+
705711
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
706712
throw InitiateAuthOutputError.invalidParameterException(.init())
707713
})
@@ -730,6 +736,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
730736
/// - I should get a .configuration error
731737
///
732738
func testSignInWithInvalidUserPoolConfigurationException() async {
739+
733740
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
734741
throw InitiateAuthOutputError.invalidUserPoolConfigurationException(.init())
735742
})
@@ -757,6 +764,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
757764
/// - I should get a .notAuthorized error
758765
///
759766
func testSignInWithNotAuthorizedException() async {
767+
760768
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
761769
throw InitiateAuthOutputError.notAuthorizedException(.init())
762770
})
@@ -784,6 +792,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
784792
/// - I should get a .resetPassword as next step
785793
///
786794
func testSignInWithPasswordResetRequiredException() async {
795+
787796
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
788797
throw InitiateAuthOutputError.passwordResetRequiredException(.init())
789798
})
@@ -812,6 +821,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
812821
/// - I should get a .resetPassword as next step
813822
///
814823
func testSignInWithPasswordResetRequiredException2() async {
824+
815825
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
816826
let serviceError = SdkError<InitiateAuthOutputError>
817827
.service(.passwordResetRequiredException(PasswordResetRequiredException()),
@@ -843,6 +853,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
843853
/// - I should get a .service error with .resourceNotFound error
844854
///
845855
func testSignInWithResourceNotFoundException() async {
856+
846857
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
847858
throw InitiateAuthOutputError.resourceNotFoundException(.init())
848859
})
@@ -871,6 +882,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
871882
/// - I should get a .service error with .requestLimitExceeded error
872883
///
873884
func testSignInWithTooManyRequestsException() async {
885+
874886
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
875887
throw InitiateAuthOutputError.tooManyRequestsException(.init())
876888
})
@@ -899,6 +911,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
899911
/// - I should get a .service error with .lambda error
900912
///
901913
func testSignInWithUnexpectedLambdaException() async {
914+
902915
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
903916
throw InitiateAuthOutputError.unexpectedLambdaException(.init())
904917
})
@@ -927,6 +940,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
927940
/// - I should get a .service error with .lambda error
928941
///
929942
func testSignInWithUserLambdaValidationException() async {
943+
930944
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
931945
throw InitiateAuthOutputError.userLambdaValidationException(.init())
932946
})
@@ -983,6 +997,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
983997
/// - I should get a .confirmSignUp as next step
984998
///
985999
func testSignInWithUserNotConfirmedException2() async {
1000+
9861001
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
9871002
let serviceError = SdkError<InitiateAuthOutputError>
9881003
.service(.userNotConfirmedException(UserNotConfirmedException()),
@@ -1014,6 +1029,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
10141029
/// - I should get a .service error with .userNotFound error
10151030
///
10161031
func testSignInWithUserNotFoundException() async {
1032+
10171033
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
10181034
throw InitiateAuthOutputError.userNotFoundException(.init())
10191035
})
@@ -1044,6 +1060,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
10441060
/// - I should get a .service error with .aliasExists error
10451061
///
10461062
func testSignInWithAliasExistsException() async {
1063+
10471064
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
10481065
InitiateAuthOutputResponse(
10491066
authenticationResult: .none,
@@ -1078,6 +1095,7 @@ class AWSAuthSignInPluginTests: BasePluginTest {
10781095
/// - I should get a .service error with .invalidPassword error
10791096
///
10801097
func testSignInWithInvalidPasswordException() async {
1098+
10811099
self.mockIdentityProvider = MockIdentityProvider(mockInitiateAuthResponse: { _ in
10821100
InitiateAuthOutputResponse(
10831101
authenticationResult: .none,
@@ -1166,4 +1184,69 @@ class AWSAuthSignInPluginTests: BasePluginTest {
11661184
XCTFail("Received failure with error \(error)")
11671185
}
11681186
}
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+
}
11691252
}

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/AuthorizationTests/AWSAuthFederationToIdentityPoolTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ class AWSAuthFederationToIdentityPoolTests: BaseAuthorizationTests {
787787

788788
let getCredentials: MockIdentity.MockGetCredentialsResponse = { input in
789789
if shouldThrowError {
790-
throw GetCredentialsForIdentityOutputError.internalErrorException(.init())
790+
throw GetCredentialsForIdentityOutputError.invalidParameterException(.init())
791791
} else {
792792
return .init(credentials: credentials, identityId: mockIdentityId)
793793
}

0 commit comments

Comments
 (0)