Skip to content

Commit 140366e

Browse files
author
luigi
committed
fix
1 parent 47d7389 commit 140366e

File tree

4 files changed

+124
-10
lines changed

4 files changed

+124
-10
lines changed

tests/codegen/service-codegen-tests/src/main/kotlin/com/test/CborServiceTestGenerator.kt

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,47 @@ internal fun generateCborServiceTest() {
113113

114114
val bearerValidation = """
115115
package $packageName.auth
116-
117-
public fun bearerValidation(token: String): UserPrincipal? {
118-
if (token == "correctToken") return UserPrincipal("Authenticated User") else return null
116+
117+
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
118+
119+
internal object BearerValidation {
120+
public fun bearerValidation(token: String): UserPrincipal? {
121+
// TODO: implement me
122+
if (token == "correctToken") return UserPrincipal("Authenticated User") else return null
123+
}
124+
}
125+
126+
internal object SigV4CredentialStore {
127+
private val table: Map<String, Credentials> = mapOf(
128+
"AKIAIOSFODNN7EXAMPLE" to Credentials(accessKeyId = "AKIAIOSFODNN7EXAMPLE", secretAccessKey = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"),
129+
"EXAMPLEACCESSKEY1234" to Credentials(accessKeyId = "EXAMPLEACCESSKEY1234", secretAccessKey = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"),
130+
)
131+
internal fun get(accessKeyId: String): Credentials? {
132+
// TODO: implement me: return Credentials(accessKeyId = ..., secretAccessKey = ...)
133+
return table[accessKeyId]
134+
}
135+
}
136+
137+
internal object SigV4aPublicKeyStore {
138+
private val table: MutableMap<String, java.security.PublicKey> = mutableMapOf()
139+
140+
init {
141+
val pem = ""${'"'}
142+
-----BEGIN PUBLIC KEY-----
143+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE4BB0k4K89eCESVtC39Kzm0HA+lYx
144+
8YF3OZDop7htXAyhGAXn4U70ViNmtG+eWu2bQOXGEIMtoBAEoRk11WXOAw==
145+
-----END PUBLIC KEY-----
146+
""${'"'}.trimIndent()
147+
val clean = pem.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").replace("\\s".toRegex(), "")
148+
val keyBytes = java.util.Base64.getDecoder().decode(clean)
149+
val spec = java.security.spec.X509EncodedKeySpec(keyBytes)
150+
val kf = java.security.KeyFactory.getInstance("EC")
151+
table["EXAMPLEACCESSKEY1234"] = kf.generatePublic(spec)
152+
}
153+
154+
internal fun get(accessKeyId: String): java.security.PublicKey? {
155+
return table[accessKeyId]
156+
}
119157
}
120158
""".trimIndent()
121159
manifest.writeFile("src/main/kotlin/$packagePath/auth/Validation.kt", bearerValidation)

tests/codegen/service-codegen-tests/src/main/kotlin/com/test/ConstraintsServiceTestGenerator.kt

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,47 @@ internal fun generateServiceConstraintsTest() {
6363

6464
val bearerValidation = """
6565
package $packageName.auth
66-
67-
public fun bearerValidation(token: String): UserPrincipal? {
68-
if (token == "correctToken") return UserPrincipal("Authenticated User") else return null
66+
67+
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
68+
69+
internal object BearerValidation {
70+
public fun bearerValidation(token: String): UserPrincipal? {
71+
// TODO: implement me
72+
if (token == "correctToken") return UserPrincipal("Authenticated User") else return null
73+
}
74+
}
75+
76+
internal object SigV4CredentialStore {
77+
private val table: Map<String, Credentials> = mapOf(
78+
"AKIAIOSFODNN7EXAMPLE" to Credentials(accessKeyId = "AKIAIOSFODNN7EXAMPLE", secretAccessKey = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"),
79+
"EXAMPLEACCESSKEY1234" to Credentials(accessKeyId = "EXAMPLEACCESSKEY1234", secretAccessKey = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"),
80+
)
81+
internal fun get(accessKeyId: String): Credentials? {
82+
// TODO: implement me: return Credentials(accessKeyId = ..., secretAccessKey = ...)
83+
return table[accessKeyId]
84+
}
85+
}
86+
87+
internal object SigV4aPublicKeyStore {
88+
private val table: MutableMap<String, java.security.PublicKey> = mutableMapOf()
89+
90+
init {
91+
val pem = ""${'"'}
92+
-----BEGIN PUBLIC KEY-----
93+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE4BB0k4K89eCESVtC39Kzm0HA+lYx
94+
8YF3OZDop7htXAyhGAXn4U70ViNmtG+eWu2bQOXGEIMtoBAEoRk11WXOAw==
95+
-----END PUBLIC KEY-----
96+
""${'"'}.trimIndent()
97+
val clean = pem.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").replace("\\s".toRegex(), "")
98+
val keyBytes = java.util.Base64.getDecoder().decode(clean)
99+
val spec = java.security.spec.X509EncodedKeySpec(keyBytes)
100+
val kf = java.security.KeyFactory.getInstance("EC")
101+
table["EXAMPLEACCESSKEY1234"] = kf.generatePublic(spec)
102+
}
103+
104+
internal fun get(accessKeyId: String): java.security.PublicKey? {
105+
return table[accessKeyId]
106+
}
69107
}
70108
""".trimIndent()
71109
manifest.writeFile("src/main/kotlin/$packagePath/auth/Validation.kt", bearerValidation)

tests/codegen/service-codegen-tests/src/main/kotlin/com/test/JsonServiceTestGenerator.kt

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,47 @@ internal fun generateJsonServiceTest() {
189189

190190
val bearerValidation = """
191191
package $packageName.auth
192-
193-
public fun bearerValidation(token: String): UserPrincipal? {
194-
if (token == "correctToken") return UserPrincipal("Authenticated User") else return null
192+
193+
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
194+
195+
internal object BearerValidation {
196+
public fun bearerValidation(token: String): UserPrincipal? {
197+
// TODO: implement me
198+
if (token == "correctToken") return UserPrincipal("Authenticated User") else return null
199+
}
200+
}
201+
202+
internal object SigV4CredentialStore {
203+
private val table: Map<String, Credentials> = mapOf(
204+
"AKIAIOSFODNN7EXAMPLE" to Credentials(accessKeyId = "AKIAIOSFODNN7EXAMPLE", secretAccessKey = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"),
205+
"EXAMPLEACCESSKEY1234" to Credentials(accessKeyId = "EXAMPLEACCESSKEY1234", secretAccessKey = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"),
206+
)
207+
internal fun get(accessKeyId: String): Credentials? {
208+
// TODO: implement me: return Credentials(accessKeyId = ..., secretAccessKey = ...)
209+
return table[accessKeyId]
210+
}
211+
}
212+
213+
internal object SigV4aPublicKeyStore {
214+
private val table: MutableMap<String, java.security.PublicKey> = mutableMapOf()
215+
216+
init {
217+
val pem = ""${'"'}
218+
-----BEGIN PUBLIC KEY-----
219+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE4BB0k4K89eCESVtC39Kzm0HA+lYx
220+
8YF3OZDop7htXAyhGAXn4U70ViNmtG+eWu2bQOXGEIMtoBAEoRk11WXOAw==
221+
-----END PUBLIC KEY-----
222+
""${'"'}.trimIndent()
223+
val clean = pem.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").replace("\\s".toRegex(), "")
224+
val keyBytes = java.util.Base64.getDecoder().decode(clean)
225+
val spec = java.security.spec.X509EncodedKeySpec(keyBytes)
226+
val kf = java.security.KeyFactory.getInstance("EC")
227+
table["EXAMPLEACCESSKEY1234"] = kf.generatePublic(spec)
228+
}
229+
230+
internal fun get(accessKeyId: String): java.security.PublicKey? {
231+
return table[accessKeyId]
232+
}
195233
}
196234
""".trimIndent()
197235
manifest.writeFile("src/main/kotlin/$packagePath/auth/Validation.kt", bearerValidation)

tests/codegen/service-codegen-tests/src/test/kotlin/com/test/CborServiceTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CborServiceTest {
2525
val requestBodyLimit: Long = 10L * 1024 * 1024
2626
val port: Int = ServerSocket(0).use { it.localPort }
2727

28-
val portListnerTimeout = 180L
28+
val portListnerTimeout = 60L
2929

3030
val baseUrl = "http://localhost:$port"
3131

0 commit comments

Comments
 (0)