Skip to content

Commit 7138f80

Browse files
authored
fix: profile credentials provider tests (#1501)
1 parent ee19684 commit 7138f80

File tree

2 files changed

+68
-57
lines changed

2 files changed

+68
-57
lines changed

aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/auth/credentials/ProfileCredentialsProviderTest.kt

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,14 @@ import aws.sdk.kotlin.runtime.auth.credentials.internal.credentials
99
import aws.sdk.kotlin.runtime.client.AwsClientOption
1010
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric
1111
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetric
12-
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetrics
1312
import aws.sdk.kotlin.runtime.util.testAttributes
1413
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
1514
import aws.smithy.kotlin.runtime.auth.awscredentials.copy
1615
import aws.smithy.kotlin.runtime.collections.attributesOf
1716
import aws.smithy.kotlin.runtime.httptest.TestConnection
1817
import aws.smithy.kotlin.runtime.httptest.buildTestConnection
1918
import aws.smithy.kotlin.runtime.net.Host
20-
import aws.smithy.kotlin.runtime.time.Instant
2119
import aws.smithy.kotlin.runtime.util.TestPlatformProvider
22-
import io.mockk.coEvery
23-
import io.mockk.mockkStatic
2420
import kotlinx.coroutines.test.runTest
2521
import kotlin.test.Test
2622
import kotlin.test.assertEquals
@@ -377,57 +373,4 @@ class ProfileCredentialsProviderTest {
377373
)
378374
assertEquals(expected, actual)
379375
}
380-
381-
@Test
382-
fun processBusinessMetrics() = runTest {
383-
val testProvider = TestPlatformProvider(
384-
env = mapOf(
385-
"AWS_CONFIG_FILE" to "config",
386-
),
387-
fs = mapOf(
388-
"config" to """
389-
[default]
390-
credential_process = awscreds-custom
391-
""".trimIndent(),
392-
"awscreds-custom" to "some-process",
393-
),
394-
)
395-
val testEngine = TestConnection()
396-
val provider = ProfileCredentialsProvider(
397-
platformProvider = testProvider,
398-
httpClient = testEngine,
399-
)
400-
401-
mockkStatic(::executeCommand)
402-
coEvery { executeCommand(any(), any(), any(), any(), any()) }.returns(
403-
Pair(
404-
0,
405-
"""
406-
{
407-
"Version": 1,
408-
"AccessKeyId": "AKID-Default",
409-
"SecretAccessKey": "Default-Secret",
410-
"SessionToken": "SessionToken",
411-
"Expiration" : "2019-05-29T00:21:43Z"
412-
}
413-
""".trimIndent(),
414-
),
415-
)
416-
417-
val actual = provider.resolve()
418-
val expected = credentials(
419-
"AKID-Default",
420-
"Default-Secret",
421-
"SessionToken",
422-
Instant.fromIso8601("2019-05-29T00:21:43Z"),
423-
"Process",
424-
).withBusinessMetrics(
425-
setOf(
426-
AwsBusinessMetric.Credentials.CREDENTIALS_PROFILE_PROCESS,
427-
AwsBusinessMetric.Credentials.CREDENTIALS_PROCESS,
428-
),
429-
)
430-
431-
assertEquals(expected, actual)
432-
}
433376
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package aws.sdk.kotlin.runtime.auth.credentials
2+
3+
import aws.sdk.kotlin.runtime.auth.credentials.internal.credentials
4+
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric
5+
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetrics
6+
import aws.smithy.kotlin.runtime.httptest.TestConnection
7+
import aws.smithy.kotlin.runtime.time.Instant
8+
import aws.smithy.kotlin.runtime.util.TestPlatformProvider
9+
import io.mockk.coEvery
10+
import io.mockk.mockkStatic
11+
import kotlinx.coroutines.test.runTest
12+
import kotlin.test.Test
13+
import kotlin.test.assertEquals
14+
15+
class ProfileCredentialsProviderTestJVM {
16+
@Test
17+
fun processBusinessMetrics() = runTest {
18+
val testProvider = TestPlatformProvider(
19+
env = mapOf(
20+
"AWS_CONFIG_FILE" to "config",
21+
),
22+
fs = mapOf(
23+
"config" to """
24+
[default]
25+
credential_process = awscreds-custom
26+
""".trimIndent(),
27+
"awscreds-custom" to "some-process",
28+
),
29+
)
30+
val testEngine = TestConnection()
31+
val provider = ProfileCredentialsProvider(
32+
platformProvider = testProvider,
33+
httpClient = testEngine,
34+
)
35+
36+
mockkStatic(::executeCommand)
37+
coEvery { executeCommand(any(), any(), any(), any(), any()) }.returns(
38+
Pair(
39+
0,
40+
"""
41+
{
42+
"Version": 1,
43+
"AccessKeyId": "AKID-Default",
44+
"SecretAccessKey": "Default-Secret",
45+
"SessionToken": "SessionToken",
46+
"Expiration" : "2019-05-29T00:21:43Z"
47+
}
48+
""".trimIndent(),
49+
),
50+
)
51+
52+
val actual = provider.resolve()
53+
val expected = credentials(
54+
"AKID-Default",
55+
"Default-Secret",
56+
"SessionToken",
57+
Instant.fromIso8601("2019-05-29T00:21:43Z"),
58+
"Process",
59+
).withBusinessMetrics(
60+
setOf(
61+
AwsBusinessMetric.Credentials.CREDENTIALS_PROFILE_PROCESS,
62+
AwsBusinessMetric.Credentials.CREDENTIALS_PROCESS,
63+
),
64+
)
65+
66+
assertEquals(expected, actual)
67+
}
68+
}

0 commit comments

Comments
 (0)