Skip to content

Commit 5dca4b4

Browse files
committed
update error message, add test for resolution order
1 parent afd01ff commit 5dca4b4

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

runtime/auth/http-auth/common/src/aws/smithy/kotlin/runtime/http/auth/EnvironmentBearerTokenProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class EnvironmentBearerTokenProvider(
2828
override suspend fun resolve(attributes: Attributes): BearerToken {
2929
val bearerToken = sysPropKey?.let { platform.getProperty(it) }
3030
?: envKey?.let { platform.getenv(it) }
31-
?: error("environment variable is not set")
31+
?: error("neither system property $sysPropKey nor environment variable $envKey is set")
3232
return object : BearerToken {
3333
override val token: String = bearerToken
3434
override val attributes: Attributes = mutableAttributes().apply {

runtime/auth/http-auth/common/test/aws/smithy/kotlin/runtime/http/auth/EnvironmentBearerTokenProviderTest.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ class EnvironmentBearerTokenProviderTest {
3737
assertEquals("test-sys-props-bearer-token", token.token)
3838
}
3939

40+
@Test
41+
fun testResolutionOrder() = runTest {
42+
val provider = EnvironmentBearerTokenProvider(
43+
"TEST_SYS_PROPS_TOKEN",
44+
"TEST_ENV_TOKEN",
45+
TestPlatformProvider(
46+
props = mutableMapOf("TEST_SYS_PROPS_TOKEN" to "test-sys-props-bearer-token"),
47+
env = mutableMapOf("TEST_ENV_TOKEN" to "test-env-bearer-token"),
48+
),
49+
)
50+
51+
val token = provider.resolve()
52+
53+
assertEquals("test-sys-props-bearer-token", token.token)
54+
}
55+
4056
@Test
4157
fun testResolveWithMissingToken() = runTest {
4258
val provider = EnvironmentBearerTokenProvider(
@@ -51,6 +67,6 @@ class EnvironmentBearerTokenProviderTest {
5167
val exception = assertFailsWith<IllegalStateException> {
5268
provider.resolve()
5369
}
54-
assertEquals("environment variable is not set", exception.message)
70+
assertEquals("neither system property MISSING_TEST_TOKEN nor environment variable MISSING_TEST_TOKEN is set", exception.message)
5571
}
5672
}

0 commit comments

Comments
 (0)