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: profile credentials provider test #1501

Merged
merged 1 commit into from
Jan 15, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@ 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
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
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading