From a42cfcc83f0551cf1645d2a21f018ff89c64e01f Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 15 Jan 2025 10:12:10 -0500 Subject: [PATCH] fix: profile credentials provider tests --- .../ProfileCredentialsProviderTest.kt | 57 ---------------- .../ProfileCredentialsProviderTestJVM.kt | 68 +++++++++++++++++++ 2 files changed, 68 insertions(+), 57 deletions(-) create mode 100644 aws-runtime/aws-config/jvm/test/aws/sdk/kotlin/runtime/auth/credentials/ProfileCredentialsProviderTestJVM.kt diff --git a/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/auth/credentials/ProfileCredentialsProviderTest.kt b/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/auth/credentials/ProfileCredentialsProviderTest.kt index d4f6eaf51c4..52147854751 100644 --- a/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/auth/credentials/ProfileCredentialsProviderTest.kt +++ b/aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/auth/credentials/ProfileCredentialsProviderTest.kt @@ -9,7 +9,6 @@ import aws.sdk.kotlin.runtime.auth.credentials.internal.credentials import aws.sdk.kotlin.runtime.client.AwsClientOption import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetric -import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetrics import aws.sdk.kotlin.runtime.util.testAttributes import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials import aws.smithy.kotlin.runtime.auth.awscredentials.copy @@ -17,10 +16,7 @@ import aws.smithy.kotlin.runtime.collections.attributesOf import aws.smithy.kotlin.runtime.httptest.TestConnection import aws.smithy.kotlin.runtime.httptest.buildTestConnection import aws.smithy.kotlin.runtime.net.Host -import aws.smithy.kotlin.runtime.time.Instant import aws.smithy.kotlin.runtime.util.TestPlatformProvider -import io.mockk.coEvery -import io.mockk.mockkStatic import kotlinx.coroutines.test.runTest import kotlin.test.Test import kotlin.test.assertEquals @@ -377,57 +373,4 @@ class ProfileCredentialsProviderTest { ) assertEquals(expected, actual) } - - @Test - fun processBusinessMetrics() = runTest { - val testProvider = TestPlatformProvider( - env = mapOf( - "AWS_CONFIG_FILE" to "config", - ), - fs = mapOf( - "config" to """ - [default] - credential_process = awscreds-custom - """.trimIndent(), - "awscreds-custom" to "some-process", - ), - ) - val testEngine = TestConnection() - val provider = ProfileCredentialsProvider( - platformProvider = testProvider, - httpClient = testEngine, - ) - - mockkStatic(::executeCommand) - coEvery { executeCommand(any(), any(), any(), any(), any()) }.returns( - Pair( - 0, - """ - { - "Version": 1, - "AccessKeyId": "AKID-Default", - "SecretAccessKey": "Default-Secret", - "SessionToken": "SessionToken", - "Expiration" : "2019-05-29T00:21:43Z" - } - """.trimIndent(), - ), - ) - - val actual = provider.resolve() - val expected = credentials( - "AKID-Default", - "Default-Secret", - "SessionToken", - Instant.fromIso8601("2019-05-29T00:21:43Z"), - "Process", - ).withBusinessMetrics( - setOf( - AwsBusinessMetric.Credentials.CREDENTIALS_PROFILE_PROCESS, - AwsBusinessMetric.Credentials.CREDENTIALS_PROCESS, - ), - ) - - assertEquals(expected, actual) - } } diff --git a/aws-runtime/aws-config/jvm/test/aws/sdk/kotlin/runtime/auth/credentials/ProfileCredentialsProviderTestJVM.kt b/aws-runtime/aws-config/jvm/test/aws/sdk/kotlin/runtime/auth/credentials/ProfileCredentialsProviderTestJVM.kt new file mode 100644 index 00000000000..802f8f253db --- /dev/null +++ b/aws-runtime/aws-config/jvm/test/aws/sdk/kotlin/runtime/auth/credentials/ProfileCredentialsProviderTestJVM.kt @@ -0,0 +1,68 @@ +package aws.sdk.kotlin.runtime.auth.credentials + +import aws.sdk.kotlin.runtime.auth.credentials.internal.credentials +import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric +import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetrics +import aws.smithy.kotlin.runtime.httptest.TestConnection +import aws.smithy.kotlin.runtime.time.Instant +import aws.smithy.kotlin.runtime.util.TestPlatformProvider +import io.mockk.coEvery +import io.mockk.mockkStatic +import kotlinx.coroutines.test.runTest +import kotlin.test.Test +import kotlin.test.assertEquals + +class ProfileCredentialsProviderTestJVM { + @Test + fun processBusinessMetrics() = runTest { + val testProvider = TestPlatformProvider( + env = mapOf( + "AWS_CONFIG_FILE" to "config", + ), + fs = mapOf( + "config" to """ + [default] + credential_process = awscreds-custom + """.trimIndent(), + "awscreds-custom" to "some-process", + ), + ) + val testEngine = TestConnection() + val provider = ProfileCredentialsProvider( + platformProvider = testProvider, + httpClient = testEngine, + ) + + mockkStatic(::executeCommand) + coEvery { executeCommand(any(), any(), any(), any(), any()) }.returns( + Pair( + 0, + """ + { + "Version": 1, + "AccessKeyId": "AKID-Default", + "SecretAccessKey": "Default-Secret", + "SessionToken": "SessionToken", + "Expiration" : "2019-05-29T00:21:43Z" + } + """.trimIndent(), + ), + ) + + val actual = provider.resolve() + val expected = credentials( + "AKID-Default", + "Default-Secret", + "SessionToken", + Instant.fromIso8601("2019-05-29T00:21:43Z"), + "Process", + ).withBusinessMetrics( + setOf( + AwsBusinessMetric.Credentials.CREDENTIALS_PROFILE_PROCESS, + AwsBusinessMetric.Credentials.CREDENTIALS_PROCESS, + ), + ) + + assertEquals(expected, actual) + } +}