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

feat: test-suite #651

Merged
merged 60 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
81a5043
chore: Require Swift 5.7, fix deprecation warnings (#600)
jbelkins Oct 11, 2023
b759e19
feat: support initial-response in RPC based event streams (#597)
dayaffe Oct 12, 2023
e7f1d28
chore: Updates version to 0.32.0
aws-sdk-swift-automation Oct 12, 2023
f6c8bc8
chore: Add newline to README.md (#602)
jbelkins Oct 13, 2023
62ad3a2
feat: add limited support in smithy-swift for visionOS (#606)
dayaffe Oct 20, 2023
818a5c7
feat: add support for requiresLength trait and Transfer-Encoding: Chu…
dayaffe Oct 23, 2023
e0b4f25
chore: Update to aws-crt-swift 0.15.0 (#607)
jbelkins Oct 24, 2023
31d7652
fix: content-length middleware should not error on event streams (#608)
dayaffe Oct 25, 2023
4d965ac
chore: Updates version to 0.33.0
aws-sdk-swift-automation Oct 25, 2023
53fbde2
chore: Improved downstream task (#568)
jbelkins Oct 25, 2023
ef962dd
chore: Convert idempotency token middleware from closure to reusable …
jbelkins Oct 30, 2023
a35c983
fix: Update aws-crt-swift dependency to 0.17.0 (#612)
sichanyoo Oct 31, 2023
6037a81
chore: Updates version to 0.34.0
aws-sdk-swift-automation Oct 31, 2023
96b95c1
fix: Endpoint url should be nil if host or scheme is missing (#614)
dayaffe Oct 31, 2023
a03eedc
fix: Pool HTTP connections based on scheme, host, and port (#615)
jbelkins Nov 2, 2023
c19f585
add default log level to initialize method (#616)
CyprienRicque Nov 6, 2023
c2ab0a5
feat: add utility method for converting SdkHttpRequest to URLRequest.…
sichanyoo Nov 6, 2023
ab999a9
chore: Updates version to 0.35.0
aws-sdk-swift-automation Nov 7, 2023
1d9c963
Add customizations to auth resolve process.
Oct 4, 2023
a54a9de
Add signEvent API to Signer protocol, and rename sign to signRequest.
Nov 14, 2023
4f346f8
Add mock auth scheme resolver, mock auth schemes, mock identity, mock…
Nov 14, 2023
856ae3c
Add unit tests for AuthSchemeMiddleware and SignerMiddleware.
Nov 14, 2023
de25f6e
Update MockSigner to conform to modified Signer API with signEvent.
Nov 14, 2023
10a9a3e
Rename directory containing mocks for auth tests from AuthTest to Aut…
Nov 14, 2023
8d05731
fix: Add a header to operation doc comments (#621)
jbelkins Nov 22, 2023
2658d06
remove unnecessary TODOs (#622)
dayaffe Nov 27, 2023
b1a0cf4
fix: Codegen issues re: recursion, Swift keywords in unions (#623)
jbelkins Nov 28, 2023
34aecef
feat!: Replace the XML encoder with a custom Smithy implementation (#…
jbelkins Nov 29, 2023
af13f00
feat!: Use closures for processing HTTP response (#624)
jbelkins Nov 30, 2023
794b36b
feat: add custom trait PaginationTruncationMember (#625)
dayaffe Dec 1, 2023
2550e03
allow isTruncated to be optional bool (#626)
dayaffe Dec 4, 2023
ca28bf2
chore: Updates version to 0.36.0
aws-sdk-swift-automation Dec 5, 2023
39638f3
chore: Run tvOS old & new in CI (#628)
jbelkins Dec 6, 2023
562a8cc
fix: Fix Package.swift warning on Mac (#629)
jbelkins Dec 7, 2023
460e51c
chore: refactor HttpBody and ByteStream to be a single class ByteStre…
dayaffe Dec 7, 2023
d51e9a6
chore: remove sync read in unused data extension (#630)
dayaffe Dec 12, 2023
3254b1f
update smithy to 1.42.0 (#631)
dayaffe Dec 13, 2023
77b100f
chore: Updates version to 0.37.0
aws-sdk-swift-automation Dec 20, 2023
d222378
chore: Update to aws-crt-swift 0.20.0 (#633)
dayaffe Dec 22, 2023
f11e2e8
fix: add back from method with fileHandle (#635)
dayaffe Dec 22, 2023
f9046ac
fix!: Add no-op behavior for initialize methods of logging system. (#…
sichanyoo Jan 9, 2024
922d066
feat!: URLSession-based HTTP Client (#636)
jbelkins Jan 9, 2024
29f734a
bump up CRT version to 0.22.0 (#639)
dayaffe Jan 11, 2024
4ccc50e
chore: Update version to 0.38.0 (#641)
jbelkins Jan 11, 2024
98018ec
chore: Empty commit (#643)
jbelkins Jan 11, 2024
4332319
feat: add wrapper for checksums + unit tests (#642)
dayaffe Jan 12, 2024
af30f38
Merge old test suite branch to new test suite branch.
Jan 16, 2024
2632677
Update to reflect midleware generics change.
Jan 16, 2024
dcf4f82
Delete unnessary line from test case.
Jan 16, 2024
d033143
Add CloudFront KeyValueStore as one of the services that use rules ba…
Jan 17, 2024
9a25887
feat: Use the Foundation HTTP client by default on Mac (#646)
jbelkins Jan 18, 2024
a89f313
chore: Updates version to 0.39.0
aws-sdk-swift-automation Jan 18, 2024
e812418
Fix auth scheme middleware to save the selected auth scheme to middle…
Jan 24, 2024
6aabf23
chore: Change MyURLQueryItem to SDKURLQueryItem (#652)
sichanyoo Jan 26, 2024
ea1b674
feat!: Provide HTTP request components by closure instead of protocol…
jbelkins Jan 26, 2024
a084a20
fix: Don't retry modeled errors by default (#653)
jbelkins Jan 26, 2024
3322748
Merge main into feat/test-suite.
Jan 26, 2024
8fb7ab4
Merge branch 'feat/sra-identity-and-auth' into feat/test-suite
Feb 6, 2024
4b3c4b2
Address Josh's PR comments.
Feb 7, 2024
f48d844
Merge updated CRT version from main into feat/test-suite.
Feb 8, 2024
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 @@ -100,8 +100,7 @@ public struct AuthSchemeMiddleware<OperationStackOutput: HttpResponseBinding,
}

// Set the selected auth scheme in context for subsequent middleware access, then pass to next middleware in chain
return try await next.handle(
context: context.toBuilder().withSelectedAuthScheme(value: selectedAuthScheme).build(), input: input
)
context.attributes.set(key: AttributeKeys.selectedAuthScheme, value: selectedAuthScheme)
return try await next.handle(context: context, input: input)
jbelkins marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public struct ContentMD5Middleware<OperationStackOutput>: Middleware {

switch input.body {
case .data(let data):
guard let data = data else {
guard let data else {
return try await next.handle(context: context, input: input)
}
let md5Hash = try data.computeMD5()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import ClientRuntime

public struct MockAuthSchemeResolverParameters: ClientRuntime.AuthSchemeResolverParameters {
public let operation: String
}

public protocol MockAuthSchemeResolver: ClientRuntime.AuthSchemeResolver {
// Intentionally empty.
// This is the parent protocol that all auth scheme resolver implementations of
// the service Mock must conform to.
}

public struct DefaultMockAuthSchemeResolver: MockAuthSchemeResolver {
public init () {}

public func resolveAuthScheme(params: ClientRuntime.AuthSchemeResolverParameters) throws -> [AuthOption] {
var validAuthOptions = Array<AuthOption>()
guard let serviceParams = params as? MockAuthSchemeResolverParameters else {
throw ClientError.authError("Service specific auth scheme parameters type must be passed to auth scheme resolver.")
}
switch serviceParams.operation {
case "authA":
validAuthOptions.append(AuthOption(schemeID: "MockAuthSchemeA"))
case "authAB":
validAuthOptions.append(AuthOption(schemeID: "MockAuthSchemeA"))
validAuthOptions.append(AuthOption(schemeID: "MockAuthSchemeB"))
case "authABC":
validAuthOptions.append(AuthOption(schemeID: "MockAuthSchemeA"))
validAuthOptions.append(AuthOption(schemeID: "MockAuthSchemeB"))
validAuthOptions.append(AuthOption(schemeID: "MockAuthSchemeC"))
case "authABCNoAuth":
validAuthOptions.append(AuthOption(schemeID: "MockAuthSchemeA"))
validAuthOptions.append(AuthOption(schemeID: "MockAuthSchemeB"))
validAuthOptions.append(AuthOption(schemeID: "MockAuthSchemeC"))
validAuthOptions.append(AuthOption(schemeID: "smithy.api#noAuth"))
default:
validAuthOptions.append(AuthOption(schemeID: "fillerAuth"))
}
return validAuthOptions
}

public func constructParameters(context: HttpContext) throws -> ClientRuntime.AuthSchemeResolverParameters {
guard let opName = context.getOperation() else {
throw ClientError.dataNotFound("Operation name not configured in middleware context for auth scheme resolver params construction.")
}
return MockAuthSchemeResolverParameters(operation: opName)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import ClientRuntime

public struct MockAuthSchemeA: ClientRuntime.AuthScheme {
public let schemeID: String = "MockAuthSchemeA"
public let signer: ClientRuntime.Signer = MockSigner()
public let idKind: ClientRuntime.IdentityKind = .aws

public init() {}

public func customizeSigningProperties(signingProperties: ClientRuntime.Attributes, context: ClientRuntime.HttpContext) -> ClientRuntime.Attributes {
return signingProperties
}
}

public struct MockAuthSchemeB: ClientRuntime.AuthScheme {
public let schemeID: String = "MockAuthSchemeB"
public let signer: ClientRuntime.Signer = MockSigner()
public let idKind: ClientRuntime.IdentityKind = .aws

public init() {}

public func customizeSigningProperties(signingProperties: ClientRuntime.Attributes, context: ClientRuntime.HttpContext) -> ClientRuntime.Attributes {
return signingProperties
}
}

public struct MockAuthSchemeC: ClientRuntime.AuthScheme {
public let schemeID: String = "MockAuthSchemeC"
public let signer: ClientRuntime.Signer = MockSigner()
public let idKind: ClientRuntime.IdentityKind = .aws

public init() {}

public func customizeSigningProperties(signingProperties: ClientRuntime.Attributes, context: ClientRuntime.HttpContext) -> ClientRuntime.Attributes {
return signingProperties
}
}

public struct MockNoAuth: ClientRuntime.AuthScheme {
public let schemeID: String = "smithy.api#noAuth"
public let signer: ClientRuntime.Signer = MockSigner()
public let idKind: ClientRuntime.IdentityKind = .aws

public init() {}

public func customizeSigningProperties(signingProperties: ClientRuntime.Attributes, context: ClientRuntime.HttpContext) -> ClientRuntime.Attributes {
return signingProperties
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import ClientRuntime

public struct MockIdentity: Identity {
public init() {}
public var expiration: ClientRuntime.Date? = nil
}

public struct MockIdentityResolver: IdentityResolver {
public typealias IdentityT = MockIdentity
public init() {}
public func getIdentity(identityProperties: ClientRuntime.Attributes?) async throws -> MockIdentity {
return MockIdentity()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import ClientRuntime
import Foundation

public struct MockSigner: ClientRuntime.Signer {
public init() {}

public func signRequest<IdentityT: Identity>(
requestBuilder: ClientRuntime.SdkHttpRequestBuilder,
identity: IdentityT,
signingProperties: ClientRuntime.Attributes
) async throws -> ClientRuntime.SdkHttpRequestBuilder {
requestBuilder.withHeader(name: "Mock-Authorization", value: "Mock-Signed")
return requestBuilder
}

public func signEvent(
payload: Data,
previousSignature: String,
signingProperties: Attributes
) async throws -> SigningResult<EventStream.Message> {
return SigningResult(output: EventStream.Message(), signature: "")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import XCTest
import SmithyTestUtil
@testable import ClientRuntime

class AuthSchemeMiddlewareTests: XCTestCase {
private var contextBuilder: HttpContextBuilder!
private var operationStack: OperationStack<MockInput, MockOutput>!

override func setUp() async throws {
try await super.setUp()
contextBuilder = HttpContextBuilder()
.withAuthSchemeResolver(value: DefaultMockAuthSchemeResolver())
.withAuthScheme(value: MockNoAuth())
.withIdentityResolver(value: MockIdentityResolver(), type: .aws)
operationStack = OperationStack<MockInput, MockOutput>(id: "auth scheme middleware test stack")
}

// Test exception cases
func testNoAuthSchemeResolverConfigured() async throws {
contextBuilder.attributes.remove(key: AttributeKeys.authSchemeResolver)
contextBuilder.withOperation(value: "fillerOp")
do {
try await AssertSelectedAuthSchemeMatches(builtContext: contextBuilder.build(), expectedAuthScheme: "")
} catch ClientError.authError(let message) {
let expected = "No auth scheme resolver has been configured on the service."
XCTAssertEqual(message, expected)
} catch {
XCTFail("Unexpected error thrown: \(error.localizedDescription)")
}
}

func testNoIdentityResolverConfigured() async throws {
contextBuilder.attributes.remove(key: AttributeKeys.identityResolvers)
contextBuilder.withOperation(value: "fillerOp")
do {
try await AssertSelectedAuthSchemeMatches(builtContext: contextBuilder.build(), expectedAuthScheme: "")
} catch ClientError.authError(let message) {
let expected = "No identity resolver has been configured on the service."
XCTAssertEqual(message, expected)
} catch {
XCTFail("Unexpected error thrown: \(error.localizedDescription)")
}
}

func testNoAuthSchemeCouldBeLoaded() async throws {
contextBuilder.withOperation(value: "fillerOp")
do {
try await AssertSelectedAuthSchemeMatches(builtContext: contextBuilder.build(), expectedAuthScheme: "")
} catch ClientError.authError(let message) {
let expected = "Could not resolve auth scheme for the operation call. Log: Auth scheme fillerAuth was not enabled for this request."
XCTAssertEqual(message, expected)
} catch {
XCTFail("Unexpected error thrown: \(error.localizedDescription)")
}
}

// Test success cases
func testOnlyAuthSchemeA() async throws {
let context = contextBuilder
.withOperation(value: "authA")
.withAuthScheme(value: MockAuthSchemeA())
.build()
try await AssertSelectedAuthSchemeMatches(builtContext: context, expectedAuthScheme: "MockAuthSchemeA")
}

func testAuthOrderABSelectA() async throws {
let context = contextBuilder
.withOperation(value: "authAB")
.withAuthScheme(value: MockAuthSchemeA())
.withAuthScheme(value: MockAuthSchemeB())
.build()
try await AssertSelectedAuthSchemeMatches(builtContext: context, expectedAuthScheme: "MockAuthSchemeA")
}

func testAuthOrderABSelectB() async throws {
let context = contextBuilder
.withOperation(value: "authAB")
.withAuthScheme(value: MockAuthSchemeB())
.build()
try await AssertSelectedAuthSchemeMatches(builtContext: context, expectedAuthScheme: "MockAuthSchemeB")
}

func testAuthOrderABCSelectA() async throws {
let context = contextBuilder
.withOperation(value: "authABC")
.withAuthScheme(value: MockAuthSchemeA())
.withAuthScheme(value: MockAuthSchemeB())
.withAuthScheme(value: MockAuthSchemeC())
.build()
try await AssertSelectedAuthSchemeMatches(builtContext: context, expectedAuthScheme: "MockAuthSchemeA")
}

func testAuthOrderABCSelectB() async throws {
let context = contextBuilder
.withOperation(value: "authABC")
.withAuthScheme(value: MockAuthSchemeB())
.withAuthScheme(value: MockAuthSchemeC())
.build()
try await AssertSelectedAuthSchemeMatches(builtContext: context, expectedAuthScheme: "MockAuthSchemeB")
}

func testAuthOrderABCSelectC() async throws {
let context = contextBuilder
.withOperation(value: "authABC")
.withAuthScheme(value: MockAuthSchemeC())
.build()
try await AssertSelectedAuthSchemeMatches(builtContext: context, expectedAuthScheme: "MockAuthSchemeC")
}

func testAuthOderABCNoAuthSelectNoAuth() async throws {
let context = contextBuilder
.withOperation(value: "authABCNoAuth")
.build()
try await AssertSelectedAuthSchemeMatches(builtContext: context, expectedAuthScheme: "smithy.api#noAuth")
}

private func AssertSelectedAuthSchemeMatches(builtContext: HttpContext, expectedAuthScheme: String) async throws {
operationStack.buildStep.intercept(position: .before, middleware: AuthSchemeMiddleware<MockOutput, MockMiddlewareError>())

let mockHandler = MockHandler(handleCallback: { (context, input) in
let selectedAuthScheme = context.getSelectedAuthScheme()
XCTAssertEqual(expectedAuthScheme, selectedAuthScheme?.schemeID)
let httpResponse = HttpResponse(body: .noStream, statusCode: HttpStatusCode.ok)
let mockOutput = try! MockOutput(httpResponse: httpResponse, decoder: nil)
let output = OperationOutput<MockOutput>(httpResponse: httpResponse, output: mockOutput)
return output
})

_ = try await operationStack.handleMiddleware(context: builtContext, input: MockInput(), next: mockHandler)
}
}
Loading
Loading