Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Merge branch 'release-candidate' into main" #871

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/amplify_analytics_pinpoint/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ dependencies {
api amplifyCore

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.amplifyframework:aws-analytics-pinpoint:1.25.1'
implementation 'com.amplifyframework:aws-auth-cognito:1.25.1'
implementation 'com.amplifyframework:aws-analytics-pinpoint:1.24.1'
implementation 'com.amplifyframework:aws-auth-cognito:1.24.1'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:3.10.0'
testImplementation 'org.mockito:mockito-inline:3.10.0'
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify_api/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ dependencies {
api amplifyCore

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.amplifyframework:aws-api:1.25.1"
implementation "com.amplifyframework:aws-api-appsync:1.25.1"
implementation "com.amplifyframework:aws-api:1.24.1"
implementation "com.amplifyframework:aws-api-appsync:1.24.1"
implementation 'androidx.test.ext:junit-ktx:1.1.3'

testImplementation 'junit:junit:4.13.2'
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify_auth_cognito/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ android {
dependencies {
api amplifyCore
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.amplifyframework:aws-auth-cognito:1.25.1'
implementation 'com.amplifyframework:aws-auth-cognito:1.24.1'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:3.10.0'
testImplementation 'org.mockito:mockito-inline:3.10.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import com.amazonaws.amplify.amplify_auth_cognito.types.FlutterResendUserAttribu
import com.amazonaws.amplify.amplify_auth_cognito.types.FlutterResendUserAttributeConfirmationCodeResult
import com.amazonaws.amplify.amplify_core.exception.ExceptionUtil.Companion.handleAddPluginException
import com.amazonaws.amplify.amplify_auth_cognito.utils.isRedirectActivityDeclared
import com.amazonaws.mobile.client.AWSMobileClient
import com.amplifyframework.auth.AuthException
import com.amplifyframework.auth.AuthProvider
import com.amplifyframework.auth.AuthSession
Expand Down Expand Up @@ -387,37 +386,13 @@ public class AuthCognito : FlutterPlugin, ActivityAware, MethodCallHandler, Plug

private fun onGetCurrentUser(@NonNull flutterResult: Result) {
try {
/*
Because Android does not preserve the user after session expiration but iOS does so,
we need to use the mobileclient to get the old username to enforce platform parity.
*/
Amplify.Auth.fetchAuthSession(
{ result ->
val cognitoAuthSession = result as AWSCognitoAuthSession
when (cognitoAuthSession.userSub.type) {
// If the user sub accessor successful the user is present and the session should be valid
AuthSessionResult.Type.SUCCESS -> {
val awsMobileClient = AWSMobileClient.getInstance()
val username = awsMobileClient.username
prepareUserResult(flutterResult, AuthUser(cognitoAuthSession.userSub.toString(), username));
}
// If the user sub accessor failed, check the signIn state
AuthSessionResult.Type.FAILURE -> {
// if signedIn flag still true, we know session is expired so get the old user
if (result.isSignedIn) {
val awsMobileClient = AWSMobileClient.getInstance()
val username = awsMobileClient.username
val userid = awsMobileClient.userSub
prepareUserResult(flutterResult, AuthUser(userid, username));
// if signIn flag is false, we assume user is signed out so throw exception
} else {
errorHandler.handleAuthError(flutterResult, AuthException.SignedOutException())
}
}
}
},
{ error -> errorHandler.handleAuthError(flutterResult, error) }
)
var user: AuthUser? = Amplify.Auth.currentUser;
if (user is AuthUser) {
prepareUserResult(flutterResult, user);
} else {
// TODO: Mechanism to check guest access status
throw AuthException.SignedOutException(AuthException.GuestAccess.GUEST_ACCESS_DISABLED)
}
} catch (e: AuthException) {
errorHandler.handleAuthError(flutterResult, e)
} catch (e: Exception) {
Expand Down Expand Up @@ -602,15 +577,7 @@ public class AuthCognito : FlutterPlugin, ActivityAware, MethodCallHandler, Plug
}

fun prepareCognitoSessionFailure(@NonNull flutterResult: Result, @NonNull result: AWSCognitoAuthSession) {
// If a User Pool token's error is a SignedOutException, we send SignedOutException as
// method call response because this indicates that the problem is not expired tokens,
// but total lack of authentication (i.e. the user is signed out)
var sessionException: AuthException = if (result.userPoolTokens.error is AuthException.SignedOutException) {
AuthException.SignedOutException()
} else {
AuthException.SessionExpiredException()
}
errorHandler.handleAuthError(flutterResult, sessionException)
errorHandler.handleAuthError(flutterResult, AuthException.SessionExpiredException())
}

fun prepareSessionResult(@NonNull flutterResult: Result, @NonNull result: AuthSession) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,8 @@ class AmplifyAuthCognitoPluginTest {
private val mockSignInResult = AuthSignInResult(false, signInStep)
private val mockResetPasswordResult = AuthResetPasswordResult(false, resetStep)
private val mockUpdateUserAttributeResult = AuthUpdateAttributeResult(true, updateAttributeStep)
private val id = AuthSessionResult.success("id")
private val awsCredentials: AuthSessionResult<AWSCredentials> = AuthSessionResult.success(BasicAWSCredentials("access", "secret"))
private val userSub = AuthSessionResult.success("sub")
private val tokens = AuthSessionResult.success(AWSCognitoUserPoolTokens("access", "id", "refresh"))
private val mockSession = AWSCognitoAuthSession(
true,
id,
awsCredentials,
userSub,
tokens
)
private var mockAuth = mock(AuthCategory::class.java)


@Before
fun setup() {
plugin = AuthCognito(AuthCognitoHubEventStreamHandler(), mock(Activity::class.java))
Expand Down Expand Up @@ -688,18 +676,13 @@ class AmplifyAuthCognitoPluginTest {
fun getCurrentUser_returnsSuccess() {
// Arrange
doAnswer { invocation: InvocationOnMock ->
plugin.prepareUserResult(mockResult, AuthUser("username", "userSub"))
null as Void?
}.`when`(mockAuth).currentUser

doAnswer { invocation: InvocationOnMock ->
plugin.prepareCognitoSessionResult(mockResult, mockSession)
plugin.prepareUpdatePasswordResult(mockResult)
null as Void?
}.`when`(mockAuth).fetchAuthSession(any(), any())
}.`when`(mockAuth).getCurrentUser()

val data: HashMap<*, *> = hashMapOf(
"username" to "username",
"userSub" to "userSub"
"username" to "username",
"userSub" to "userSub"
)
val arguments: HashMap<String, Any> = hashMapOf("data" to data)
val call = MethodCall("getCurrentUser", arguments)
Expand Down Expand Up @@ -740,6 +723,18 @@ class AmplifyAuthCognitoPluginTest {

@Test
fun fetchSession_returnsSuccess() {
val id = AuthSessionResult.success("id")
val awsCredentials: AuthSessionResult<AWSCredentials> = AuthSessionResult.success(BasicAWSCredentials("access", "secret"))
val userSub = AuthSessionResult.success("sub")
val tokens = AuthSessionResult.success(AWSCognitoUserPoolTokens("access", "id", "refresh"))
val mockSession = AWSCognitoAuthSession(
true,
id,
awsCredentials,
userSub,
tokens
)

// Arrange
doAnswer { invocation: InvocationOnMock ->
plugin.prepareCognitoSessionResult(mockResult, mockSession)
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify_core/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.amplifyframework:core:1.25.1'
implementation 'com.amplifyframework:core:1.24.1'
implementation 'com.google.code.gson:gson:2.8.6'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:3.10.0'
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify_datastore/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.amplifyframework:aws-datastore:1.25.1"
implementation "com.amplifyframework:aws-api-appsync:1.25.1"
implementation "com.amplifyframework:aws-datastore:1.24.1"
implementation "com.amplifyframework:aws-api-appsync:1.24.1"
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:3.10.0'
testImplementation 'org.mockito:mockito-inline:3.10.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ data class FlutterModelFieldType(val map: Map<String, Any>) {
return when (fieldType) {
"string" -> String::class.java
"int" -> Integer::class.java
"double" -> Double::class.javaObjectType
"double" -> Double::class.java
"date" -> Temporal.Date::class.java
"dateTime" -> Temporal.DateTime::class.java
"time" -> Temporal.Time::class.java
"timestamp" -> Temporal.Timestamp::class.java
"bool" -> Boolean::class.javaObjectType
"bool" -> Boolean::class.java
"enumeration" -> String::class.java
"model" -> Model::class.java
"collection" -> List::class.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ val allTypeModelSchema = ModelSchema.builder()
"floatType" to
ModelField.builder()
.name("floatType")
.javaClassForValue(Double::class.javaObjectType)
.javaClassForValue(Double::class.java)
.targetType("Double")
.isRequired(true)
.isArray(false)
.build(),
"boolType" to
ModelField.builder()
.name("boolType")
.javaClassForValue(Boolean::class.javaObjectType)
.javaClassForValue(Boolean::class.java)
.targetType("Boolean")
.isRequired(true)
.isArray(false)
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify_flutter/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ android {

dependencies {
api amplifyCore
implementation 'com.amplifyframework:core:1.25.1'
implementation 'com.amplifyframework:core:1.24.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:3.10.0'
testImplementation 'org.mockito:mockito-inline:3.10.0'
testImplementation 'androidx.test:core:1.3.0'
testImplementation 'org.robolectric:robolectric:4.3.1'
testImplementation 'com.google.code.gson:gson:2.8.6'
testImplementation 'com.amplifyframework:aws-auth-cognito:1.25.1'
testImplementation 'com.amplifyframework:aws-auth-cognito:1.24.1'
}
2 changes: 1 addition & 1 deletion packages/amplify_storage_s3/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ android {
dependencies {
api amplifyCore
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.amplifyframework:aws-storage-s3:1.25.1'
implementation 'com.amplifyframework:aws-storage-s3:1.24.1'
}