Skip to content

Commit

Permalink
Merge branch 'main' into custom-auth-with-srp-parity-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gpanshu committed Dec 15, 2022
2 parents 5b7e969 + d24b15d commit 4b286ba
Show file tree
Hide file tree
Showing 54 changed files with 1,733 additions and 339 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codecov_code_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: '8'
java-version: '11'
distribution: 'corretto'

- name: Run test and generate jacoco report
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/maven_release_publisher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ jobs:
with:
project-name: AmplifyAndroid-IntegrationTest
env-vars-for-codebuild: |
ORG_GRADLE_PROJECT_useAwsSdkReleaseBuild
ORG_GRADLE_PROJECT_useAwsSdkReleaseBuild,
NUMBER_OF_DEVICES_TO_TEST
env:
ORG_GRADLE_PROJECT_useAwsSdkReleaseBuild: true
NUMBER_OF_DEVICES_TO_TEST: 3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
Expand Down
10 changes: 8 additions & 2 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.amplifyframework.analytics.pinpoint.models

import java.util.Locale
import org.junit.Assert.assertEquals
import org.junit.Test

Expand Down Expand Up @@ -41,7 +42,7 @@ class PinpointEventTest {
eventTimestamp = 1657035956917L,
uniqueId = "UNIQUE_ID",
androidAppDetails = AndroidAppDetails("appId", "appTitle", "packageName", "versionCode", "versionName"),
androidDeviceDetails = AndroidDeviceDetails()
androidDeviceDetails = AndroidDeviceDetails(locale = Locale.US)
)
assertEquals(expectedOutput, pinpointEvent.toJsonString())
}
Expand All @@ -58,7 +59,7 @@ class PinpointEventTest {
eventTimestamp = 1657035956917L,
uniqueId = "UNIQUE_ID",
androidAppDetails = AndroidAppDetails("appId", "appTitle", "packageName", "versionCode", "versionName"),
androidDeviceDetails = AndroidDeviceDetails()
androidDeviceDetails = AndroidDeviceDetails(locale = Locale.US)
)

val pinpointEventJson =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,34 +181,32 @@ internal class KotlinAuthFacadeInternal(private val delegate: RealAWSCognitoAuth
suspend fun signInWithSocialWebUI(
provider: AuthProvider,
callingActivity: Activity
):
AuthSignInResult {
return suspendCoroutine { continuation ->
delegate.signInWithSocialWebUI(
provider,
callingActivity,
{ continuation.resume(it) },
{ continuation.resumeWithException(it) }
)
}
): AuthSignInResult {
return suspendCoroutine { continuation ->
delegate.signInWithSocialWebUI(
provider,
callingActivity,
{ continuation.resume(it) },
{ continuation.resumeWithException(it) }
)
}
}

suspend fun signInWithSocialWebUI(
provider: AuthProvider,
callingActivity: Activity,
options: AuthWebUISignInOptions
):
AuthSignInResult {
return suspendCoroutine { continuation ->
delegate.signInWithSocialWebUI(
provider,
callingActivity,
options,
{ continuation.resume(it) },
{ continuation.resumeWithException(it) }
)
}
): AuthSignInResult {
return suspendCoroutine { continuation ->
delegate.signInWithSocialWebUI(
provider,
callingActivity,
options,
{ continuation.resume(it) },
{ continuation.resumeWithException(it) }
)
}
}

suspend fun signInWithWebUI(
callingActivity: Activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ internal class RealAWSCognitoAuthPlugin(
}
}
}
authNState is AuthenticationState.SignedIn
&& authZState is AuthorizationState.SessionEstablished -> {
authNState is AuthenticationState.SignedIn &&
authZState is AuthorizationState.SessionEstablished -> {
authStateMachine.cancel(token)
val authSignInResult = AuthSignInResult(
true,
Expand Down Expand Up @@ -594,8 +594,8 @@ internal class RealAWSCognitoAuthPlugin(
val signInState = (authNState as? AuthenticationState.SigningIn)?.signInState
val challengeState = (signInState as? SignInState.ResolvingChallenge)?.challengeState
when {
authNState is AuthenticationState.SignedIn
&& authZState is AuthorizationState.SessionEstablished -> {
authNState is AuthenticationState.SignedIn &&
authZState is AuthorizationState.SessionEstablished -> {
authStateMachine.cancel(token)
val authSignInResult = AuthSignInResult(
true,
Expand Down Expand Up @@ -740,8 +740,8 @@ internal class RealAWSCognitoAuthPlugin(
authStateMachine.send(AuthenticationEvent(AuthenticationEvent.EventType.CancelSignIn()))
}
}
authNState is AuthenticationState.SignedIn
&& authZState is AuthorizationState.SessionEstablished -> {
authNState is AuthenticationState.SignedIn &&
authZState is AuthorizationState.SessionEstablished -> {
authStateMachine.cancel(token)
val authSignInResult =
AuthSignInResult(
Expand Down Expand Up @@ -1798,8 +1798,8 @@ internal class RealAWSCognitoAuthPlugin(
val authNState = authState.authNState
val authZState = authState.authZState
when {
authNState is AuthenticationState.FederatedToIdentityPool
&& authZState is AuthorizationState.SessionEstablished -> {
authNState is AuthenticationState.FederatedToIdentityPool &&
authZState is AuthorizationState.SessionEstablished -> {
authStateMachine.cancel(token)
val credential = authZState.amplifyCredential as? AmplifyCredential.IdentityPoolFederated
val identityId = credential?.identityId
Expand Down Expand Up @@ -1853,12 +1853,11 @@ internal class RealAWSCognitoAuthPlugin(
(
authNState is AuthenticationState.FederatedToIdentityPool &&
authZState is AuthorizationState.SessionEstablished
) ||
(
authZState is AuthorizationState.Error &&
authZState.exception is SessionError &&
authZState.exception.amplifyCredential is AmplifyCredential.IdentityPoolFederated
) -> {
) || (
authZState is AuthorizationState.Error &&
authZState.exception is SessionError &&
authZState.exception.amplifyCredential is AmplifyCredential.IdentityPoolFederated
) -> {
val event = AuthenticationEvent(AuthenticationEvent.EventType.ClearFederationToIdentityPool())
authStateMachine.send(event)
_clearFederationToIdentityPool(onSuccess, onError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import java.net.HttpURLConnection
import java.net.URL
import java.net.URLEncoder
import javax.net.ssl.HttpsURLConnection
import kotlin.jvm.Throws
import kotlin.time.Duration.Companion.seconds
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand All @@ -39,39 +38,42 @@ internal object HostedUIHttpHelper {
private val json = Json { ignoreUnknownKeys = true }

@Throws(Exception::class)
fun fetchTokens(url: URL, headerParams: Map<String, String>, bodyParams: Map<String, String>):
CognitoUserPoolTokens {
val connection = (url.openConnection() as HttpsURLConnection).apply {
requestMethod = "POST"
doOutput = true
// add headers
headerParams.map { addRequestProperty(it.key, it.value) }
// add body
DataOutputStream(outputStream).use { dos ->
val requestBody = bodyParams.map {
"${URLEncoder.encode(it.key, "UTF-8")}=${URLEncoder.encode(it.value, "UTF-8")}"
}.joinToString("&")
dos.writeBytes(requestBody)
}
fun fetchTokens(
url: URL,
headerParams: Map<String, String>,
bodyParams: Map<String, String>
): CognitoUserPoolTokens {
val connection = (url.openConnection() as HttpsURLConnection).apply {
requestMethod = "POST"
doOutput = true
// add headers
headerParams.map { addRequestProperty(it.key, it.value) }
// add body
DataOutputStream(outputStream).use { dos ->
val requestBody = bodyParams.map {
"${URLEncoder.encode(it.key, "UTF-8")}=${URLEncoder.encode(it.value, "UTF-8")}"
}.joinToString("&")
dos.writeBytes(requestBody)
}
}

val responseCode = connection.responseCode
val responseCode = connection.responseCode

if (responseCode >= HttpURLConnection.HTTP_OK && responseCode < HttpURLConnection.HTTP_INTERNAL_ERROR) {
val responseStream = if (responseCode < HttpURLConnection.HTTP_MULT_CHOICE) {
connection.inputStream
} else {
connection.errorStream
}
val responseString = responseStream.bufferedReader().use(BufferedReader::readText)
return parseTokenResponse(responseString)
if (responseCode >= HttpURLConnection.HTTP_OK && responseCode < HttpURLConnection.HTTP_INTERNAL_ERROR) {
val responseStream = if (responseCode < HttpURLConnection.HTTP_MULT_CHOICE) {
connection.inputStream
} else {
throw ServiceException(
message = connection.responseMessage,
recoverySuggestion = AmplifyException.TODO_RECOVERY_SUGGESTION
)
connection.errorStream
}
val responseString = responseStream.bufferedReader().use(BufferedReader::readText)
return parseTokenResponse(responseString)
} else {
throw ServiceException(
message = connection.responseMessage,
recoverySuggestion = AmplifyException.TODO_RECOVERY_SUGGESTION
)
}
}

private fun parseTokenResponse(responseString: String): CognitoUserPoolTokens {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ internal object SignInChallengeHelper {
}
}
challengeNameType is ChallengeNameType.SmsMfa ||
challengeNameType is ChallengeNameType.CustomChallenge
|| challengeNameType is ChallengeNameType.NewPasswordRequired -> {
challengeNameType is ChallengeNameType.CustomChallenge ||
challengeNameType is ChallengeNameType.NewPasswordRequired -> {
val challenge =
AuthChallenge(challengeNameType.value, username, session, challengeParameters)
SignInEvent(SignInEvent.EventType.ReceivedChallenge(challenge))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,19 @@ object SignUpTestCaseGenerator : SerializableProvider {
ExpectationShapes.Amplify(
apiName = AuthAPI.signUp,
responseType = ResponseType.Success,
response =
AuthSignUpResult(
false,
AuthNextSignUpStep(
AuthSignUpStep.CONFIRM_SIGN_UP_STEP,
emptyMap(),
AuthCodeDeliveryDetails(
email,
AuthCodeDeliveryDetails.DeliveryMedium.EMAIL,
"attributeName"
)
),
null
).toJsonElement()
response = AuthSignUpResult(
false,
AuthNextSignUpStep(
AuthSignUpStep.CONFIRM_SIGN_UP_STEP,
emptyMap(),
AuthCodeDeliveryDetails(
email,
AuthCodeDeliveryDetails.DeliveryMedium.EMAIL,
"attributeName"
)
),
null
).toJsonElement()
)
)
)
Expand Down Expand Up @@ -131,15 +130,15 @@ object SignUpTestCaseGenerator : SerializableProvider {
apiName = AuthAPI.signUp,
responseType = ResponseType.Success,
response =
AuthSignUpResult(
true,
AuthNextSignUpStep(
AuthSignUpStep.DONE,
emptyMap(),
null
),
AuthSignUpResult(
true,
AuthNextSignUpStep(
AuthSignUpStep.DONE,
emptyMap(),
null
).toJsonElement()
),
null
).toJsonElement()
)
)
)
Expand Down
1 change: 1 addition & 0 deletions aws-datastore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {

testImplementation project(path: ':testmodels')
testImplementation project(path: ':testutils')
testImplementation project(path: ':aws-datastore')
testImplementation dependency.jsonassert
testImplementation dependency.junit
testImplementation dependency.mockito
Expand Down
5 changes: 4 additions & 1 deletion aws-datastore/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
-->

<manifest package="com.amplifyframework.datastore"
xmlns:android="http://schemas.android.com/apk/res/android" />
xmlns:android="http://schemas.android.com/apk/res/android" >

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

0 comments on commit 4b286ba

Please sign in to comment.