Skip to content

Commit

Permalink
Build works
Browse files Browse the repository at this point in the history
  • Loading branch information
lauzadis committed Sep 27, 2023
1 parent 486b7b5 commit 16060bf
Show file tree
Hide file tree
Showing 31 changed files with 107 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package aws.smithy.kotlin.runtime.auth.awscredentials

import aws.smithy.kotlin.runtime.util.Attributes
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import kotlin.test.Test
import kotlin.test.assertEquals

class CredentialsProviderChainTest {
Expand Down
3 changes: 0 additions & 3 deletions runtime/auth/aws-signing-common/api/aws-signing-common.api
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ public final class aws/smithy/kotlin/runtime/auth/awssigning/HashSpecification$U
public final class aws/smithy/kotlin/runtime/auth/awssigning/PresignerKt {
}

public final class aws/smithy/kotlin/runtime/auth/awssigning/internal/AwsChunkedUtilJVMKt {
}

public final class aws/smithy/kotlin/runtime/auth/awssigning/internal/AwsChunkedUtilKt {
public static final field AWS_CHUNKED_THRESHOLD I
public static final field CHUNK_SIZE_BYTES I
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package aws.smithy.kotlin.runtime.auth.awssigning

import aws.smithy.kotlin.runtime.InternalApi
Expand All @@ -13,15 +8,13 @@ import aws.smithy.kotlin.runtime.io.SdkSource
import aws.smithy.kotlin.runtime.io.buffer
import kotlinx.coroutines.runBlocking

// TODO - can be shared with Kotlin/Native but not JS

/**
* aws-chunked content encoding.
* This class wraps an [SdkSource]. When reads are performed on this class, it will read the wrapped data
* and return it in aws-chunked content encoding.
*
* @see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming.html">SigV4 Streaming</a>
* @param delegate the underlying [SdkSoure] which will have its data encoded in aws-chunked format
* @param delegate the underlying [SdkSource] which will have its data encoded in aws-chunked format
* @param signer the signer to use to sign chunks and (optionally) chunk trailer
* @param signingConfig the config to use for signing
* @param previousSignature the previous signature to use for signing. in most cases, this should be the seed signature
Expand Down Expand Up @@ -64,4 +57,4 @@ private fun SdkSource.asStream(): AwsChunkedReader.Stream = object : AwsChunkedR

override suspend fun read(sink: SdkBuffer, limit: Long): Long =
delegate.read(sink, limit)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@

package aws.smithy.kotlin.runtime.auth.awssigning.internal

import aws.smithy.kotlin.runtime.ClientException
import aws.smithy.kotlin.runtime.InternalApi
import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigner
import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigningConfig
import aws.smithy.kotlin.runtime.auth.awssigning.HashSpecification
import aws.smithy.kotlin.runtime.http.DeferredHeaders
import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.auth.awssigning.*
import aws.smithy.kotlin.runtime.http.*
import aws.smithy.kotlin.runtime.http.request.HttpRequestBuilder
import aws.smithy.kotlin.runtime.io.SdkBuffer

Expand Down Expand Up @@ -76,9 +73,25 @@ public fun HttpRequestBuilder.setAwsChunkedHeaders() {
* Update the HTTP body to use aws-chunked content encoding
*/
@InternalApi
public expect fun HttpRequestBuilder.setAwsChunkedBody(
signer: AwsSigner,
signingConfig: AwsSigningConfig,
signature: ByteArray,
trailingHeaders: DeferredHeaders,
)
public fun HttpRequestBuilder.setAwsChunkedBody(signer: AwsSigner, signingConfig: AwsSigningConfig, signature: ByteArray, trailingHeaders: DeferredHeaders) {
body = when (body) {
is HttpBody.ChannelContent -> AwsChunkedByteReadChannel(
checkNotNull(body.toSdkByteReadChannel()),
signer,
signingConfig,
signature,
trailingHeaders,
).toHttpBody(-1)

is HttpBody.SourceContent -> AwsChunkedSource(
(body as HttpBody.SourceContent).readFrom(),
signer,
signingConfig,
signature,
trailingHeaders,
).toHttpBody(-1)

else -> throw ClientException("HttpBody type is not supported")
}
}

This file was deleted.

4 changes: 2 additions & 2 deletions runtime/auth/aws-signing-crt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ extra["moduleName"] = "aws.smithy.kotlin.runtime.auth.awssigning.crt"

kotlin {
sourceSets {
getByName("jvmAndNativeMain") {
jvmMain {
dependencies {
api(project(":runtime:auth:aws-signing-common"))
implementation(project(":runtime:crt-util"))
}
}

getByName("jvmAndNativeTest") {
jvmTest {
dependencies {
implementation(project(":runtime:auth:aws-signing-tests"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package aws.smithy.kotlin.runtime.auth.awssigning.crt

import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigner
import aws.smithy.kotlin.runtime.auth.awssigning.tests.AwsChunkedByteReadChannelTestBase
import aws.smithy.kotlin.runtime.auth.awssigning.crt.CrtAwsSigner

class CrtAwsChunkedByteReadChannelTest : AwsChunkedByteReadChannelTestBase() {
override val signer: AwsSigner = CrtAwsSigner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package aws.smithy.kotlin.runtime.auth.awssigning.crt

import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigner
import aws.smithy.kotlin.runtime.auth.awssigning.tests.AwsChunkedSourceTestBase
import aws.smithy.kotlin.runtime.auth.awssigning.crt.CrtAwsSigner

class CrtAwsChunkedSourceTest : AwsChunkedSourceTestBase() {
override val signer: AwsSigner = CrtAwsSigner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package aws.smithy.kotlin.runtime.auth.awssigning.crt

import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigner
import aws.smithy.kotlin.runtime.auth.awssigning.tests.BasicSigningTestBase
import aws.smithy.kotlin.runtime.auth.awssigning.crt.CrtAwsSigner

class CrtBasicSigningTest : BasicSigningTestBase() {
override val signer: AwsSigner = CrtAwsSigner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package aws.smithy.kotlin.runtime.auth.awssigning.crt

import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigner
import aws.smithy.kotlin.runtime.auth.awssigning.tests.SigningSuiteTestBase
import aws.smithy.kotlin.runtime.auth.awssigning.crt.CrtAwsSigner

class CrtSigningSuiteTest : SigningSuiteTestBase() {
override val signer: AwsSigner = CrtAwsSigner
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.smithy.kotlin.runtime.auth.awssigning.tests

// FIXME Implement native tests
actual abstract class SigningSuiteTestBase : HasSigner
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import aws.smithy.kotlin.runtime.time.Instant
import aws.smithy.kotlin.runtime.util.Attributes
import aws.smithy.kotlin.runtime.util.emptyAttributes
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import kotlin.test.Test
import kotlin.test.assertEquals

class BearerTokenProviderChainTest {
private class TestTokenProvider(val token: String? = null) : BearerTokenProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package aws.smithy.kotlin.runtime.telemetry.logging

import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import kotlin.test.Test
import kotlin.test.assertEquals

class TestLoggingContext {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package aws.smithy.kotlin.runtime.telemetry.logging

internal actual val DefaultLoggerProvider: LoggerProvider = TODO("Not yet implemented")
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extra["moduleName"] = "aws.smithy.kotlin.runtime.http.engine.crt"

kotlin {
sourceSets {
getByName("jvmAndNativeMain") {
jvmMain {
dependencies {
api(project(":runtime:runtime-core"))
api(project(":runtime:protocol:http-client"))
Expand All @@ -22,7 +22,7 @@ kotlin {
}
}

getByName("jvmAndNativeTest") {
jvmTest {
dependencies {
implementation(project(":runtime:testing"))
implementation(project(":runtime:protocol:http-test"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CrtHttpEngine(public override val config: CrtHttpEngineConfig) : Ht
public operator fun invoke(block: CrtHttpEngineConfig.Builder.() -> Unit): CrtHttpEngine =
CrtHttpEngine(CrtHttpEngineConfig(block))

override val engineConstructor: (CrtHttpEngineConfig.Builder.() -> Unit) -> CrtHttpEngine = ::invoke
override val engineConstructor: (CrtHttpEngineConfig.Builder.() -> Unit) -> CrtHttpEngine = Companion::invoke
}

// FIXME - re-enable when SLF4j default is available
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package aws.smithy.kotlin.runtime.http.engine

internal actual fun newDefaultHttpEngine(block: (HttpClientEngineConfig.Builder.() -> Unit)?): CloseableHttpClientEngine
= TODO("Not yet implemented")
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package aws.smithy.kotlin.runtime.http.test.util

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import kotlin.coroutines.CoroutineContext
import kotlin.time.Duration

// FIXME add engines to test
internal actual fun engineFactories(): List<TestEngineFactory> =
listOf()

// FIXME duplicated from jvm source
internal actual fun runBlockingTest(
context: CoroutineContext,
timeout: Duration?,
block: suspend CoroutineScope.() -> Unit,
) {
runBlocking(context) {
if (timeout != null) {
withTimeout(timeout) {
block()
}
} else {
block()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ package aws.smithy.kotlin.runtime.http.engine
import aws.smithy.kotlin.runtime.ClientException
import aws.smithy.kotlin.runtime.net.Url
import aws.smithy.kotlin.runtime.util.PlatformEnvironProvider
import org.junit.jupiter.api.assertThrows
import kotlin.test.Test
import kotlin.test.assertContains
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith

data class TestPlatformEnvironmentProvider(
private val env: Map<String, String> = emptyMap(),
Expand Down Expand Up @@ -102,7 +102,7 @@ class EnvironmentProxySelectorTest {
fun testSelectFailures() {
failCases.forEachIndexed { idx, failCase ->
val testProvider = TestPlatformEnvironmentProvider(failCase.env, failCase.props)
val exception = assertThrows<ClientException>("[idx=$idx] expected ClientException") {
val exception = assertFailsWith<ClientException>("[idx=$idx] expected ClientException") {
EnvironmentProxySelector(testProvider)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class FlexibleChecksumsRequestInterceptorTest {
val req = HttpRequestBuilder().apply {
body = object : HttpBody.SourceContent() {
override val contentLength: Long = 1024 * 1024 * 128
override fun readFrom(): SdkSource = "a".repeat(contentLength.toInt()).toByteArray().source()
override fun readFrom(): SdkSource = "a".repeat(contentLength.toInt()).encodeToByteArray().source()
override val isOneShot: Boolean get() = false
}
}
Expand Down Expand Up @@ -192,7 +192,5 @@ class FlexibleChecksumsRequestInterceptorTest {
assertEquals(precalculatedChecksumValue, call.request.headers["x-amz-checksum-sha256"])
}

private fun Headers.getNumChecksumHeaders(): Long = entries().stream()
.filter { (name, _) -> name.startsWith("x-amz-checksum-") }
.count()
private fun Headers.getNumChecksumHeaders(): Int = entries().count { (name, _) -> name.startsWith("x-amz-checksum-") }
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ inline fun <reified I> newTestOperation(serialized: HttpRequestBuilder): SdkHttp

class FlexibleChecksumsResponseInterceptorTest {

private val response = "abc".repeat(1024).toByteArray()
private val response = "abc".repeat(1024).encodeToByteArray()

private val checksums: List<Pair<String, String>> = listOf(
"crc32c" to "wS3hug==",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object ResponseLengthValidationTestInput
data class ResponseLengthValidationTestOutput(val body: HttpBody)

private const val CONTENT_LENGTH_HEADER_NAME = "Content-Length"
private val RESPONSE = "a".repeat(500).toByteArray()
private val RESPONSE = "a".repeat(500).encodeToByteArray()

fun op() =
SdkHttpOperation.build {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class HttpInterceptorTest {
}

val cause = assertNotNull(ex.cause)
assertEquals(1, cause.suppressed.size)
assertIs<TestException>(cause.suppressed.last())
assertEquals(1, cause.suppressedExceptions.size)
assertIs<TestException>(cause.suppressedExceptions.last())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import aws.smithy.kotlin.runtime.telemetry.logging.loggingContext
import aws.smithy.kotlin.runtime.telemetry.trace.traceSpan
import io.kotest.matchers.string.shouldContain
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertNotNull
Expand Down

0 comments on commit 16060bf

Please sign in to comment.