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

fix(predictions): Use English locale for date/time #2491

Merged
merged 7 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ internal class AWSV4Signer {

// Initial prior signature will be signature of initial request (web socket connection request)
private var priorSignature = ""
private val dateFormatter = SimpleDateFormat(DATE_PATTERN, Locale.getDefault())
private val timeFormatter = SimpleDateFormat(TIME_PATTERN, Locale.getDefault())
private val dateFormatter = SimpleDateFormat(DATE_PATTERN, Locale("en", "US", "POSIX"))
private val timeFormatter = SimpleDateFormat(TIME_PATTERN, Locale("en", "US", "POSIX"))
private val sha256Algorithm = MessageDigest.getInstance("SHA-256")
val encodedSpace: String = Uri.encode(" ")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

@RunWith(RobolectricTestRunner::class)
internal class AWSV4SignerTest {
Expand Down Expand Up @@ -91,6 +92,35 @@ internal class AWSV4SignerTest {
assertEquals(expectedUrl, signedUri.toString())
}

@Test
@Config(qualifiers = "ar")
fun `get signed uri for different locale`() {
signer = AWSV4Signer()
val expectedUrl = "wss://streaming-rekognition.us-east-1.amazon.com/start-face-liveness-session-websocket" +
"?X-Amz-Algorithm=AWS4-HMAC-SHA256" +
"&X-Amz-Credential=accessKeyIdTest%252F19700120%252Fus-east-1%252Frekognition%252Faws4_request" +
"&X-Amz-Date=19700120T104017Z" +
"&X-Amz-Expires=299" +
"&X-Amz-SignedHeaders=host" +
"&tK=tV" +
"&x-amz-user-agent=userAgentTest" +
"&X-Amz-Signature=8bf221f80e5f69908ce8e3be0f03ad7cf96c1d329795218ca7ba5322056628ef"

val uri = URI(
"wss://streaming-rekognition.us-east-1.amazon.com/start-face-liveness-session-websocket?tK=tV"
)
val credentials = Credentials(
accessKeyId = "accessKeyIdTest",
secretAccessKey = "secretAccessKeyTest",
expiration = Instant.fromIso8601("2023-03-28T15:28:29+0000"),
providerName = "providerNameTest"
)
val dateMillis = 1680017309L
val signedUri = signer.getSignedUri(uri, credentials, "us-east-1", "userAgentTest", dateMillis)

assertEquals(expectedUrl, signedUri.toString())
}

@Test
fun `get signed frame returns expected and stores previous signature`() {
val expectedFirstFrame = "1415d07838d82f035231c87641b2477c2fa4f00e9813a04ee95d45368d6b1051"
Expand All @@ -113,6 +143,30 @@ internal class AWSV4SignerTest {
assertEquals(expectedSecondFrame, secondFrame)
}

@Test
@Config(qualifiers = "ar")
fun `get signed frame for different locale returns expected and stores previous signature`() {
signer = AWSV4Signer()
val expectedFirstFrame = "1415d07838d82f035231c87641b2477c2fa4f00e9813a04ee95d45368d6b1051"
val expectedSecondFrame = "31df24081f0088143236e16a1230b0690a29bedf8c7f9a7dbf3f211d176baf73"

val firstFrame = signer.getSignedFrame(
"us-east-1-test",
"testFrame1".toByteArray(),
"sKey1",
Pair(":date", Date(1680017309L))
)
val secondFrame = signer.getSignedFrame(
"us-east-1-test",
"testFrame2".toByteArray(),
"sKey2",
Pair(":date", Date(1680018309L))
)

assertEquals(expectedFirstFrame, firstFrame)
assertEquals(expectedSecondFrame, secondFrame)
}

@Test
fun `get signed uri with special characters in user agent`() {
val expectedUrl = "wss://streaming-rekognition.us-east-1.amazon.com/start-face-liveness-session-websocket" +
Expand Down