Skip to content

Commit

Permalink
add unit test, integration test, and fix swiftlint
Browse files Browse the repository at this point in the history
  • Loading branch information
dayaffe committed Nov 15, 2024
1 parent aa4b374 commit 3a17012
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import AWSSDKHTTPAuth
import XCTest
import AWSS3
import ClientRuntime
import AWSClientRuntime

/// Tests toggle unsigned request using S3.
class S3ToggleUnsignedTests: S3XCTestCase {
private var s3Config: S3Client.S3ClientConfiguration!
private let key = "test.txt"

override func setUp() async throws {
try await super.setUp()
s3Config = try await S3Client.S3ClientConfiguration(region: region)
s3Config.authSchemes = [SigV4AuthScheme(requestUnsignedBody: true)]
}

func testS3PresignedRequest() async throws {
let putObjectInput = PutObjectInput(
body: .noStream,
bucket: bucketName,
key: key,
metadata: ["filename": key]
)

// Upload
let s3Client = S3Client(config: s3Config)
_ = try await s3Client.putObject(input: putObjectInput)

// Get
let getObjectInput = GetObjectInput(bucket: bucketName, key: key)
let fetchedObject = try await client.getObject(input: getObjectInput)

XCTAssertNotNil(fetchedObject.metadata)
let metadata = try XCTUnwrap(fetchedObject.metadata)
XCTAssertEqual(metadata["filename"], key)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import struct Smithy.Attributes
public struct SigV4AuthScheme: AuthScheme {
public let schemeID: String = "aws.auth#sigv4"
public let signer: Signer = AWSSigV4Signer()
public var requestUnsignedBody: Bool? = nil
public var requestUnsignedBody: Bool?

public init() {}

Expand Down Expand Up @@ -75,7 +75,7 @@ public struct SigV4AuthScheme: AuthScheme {
)

// Optionally toggle unsigned body
if (self.requestUnsignedBody == true) {
if self.requestUnsignedBody == true {
updatedSigningProperties.set(key: SigningPropertyKeys.requestUnsignedBody, value: true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class SigV4AuthSchemeTests: XCTestCase {
XCTAssertTrue(try XCTUnwrap(updatedProperties.get(key: SigningPropertyKeys.shouldNormalizeURIPath)))
}

func testToggleUnsignedBody() throws {
func testRequestUnsignedBody() throws {
let customSigV4AuthScheme = SigV4AuthScheme(requestUnsignedBody: true)
let context = contextBuilder
.withBidirectionalStreamingEnabled(value: true)
Expand All @@ -295,6 +295,5 @@ class SigV4AuthSchemeTests: XCTestCase {
.build()
let updatedProperties = try customSigV4AuthScheme.customizeSigningProperties(signingProperties: Attributes(), context: context)
XCTAssertTrue(try XCTUnwrap(updatedProperties.get(key: SigningPropertyKeys.requestUnsignedBody)))
XCTAssertTrue(try XCTUnwrap(updatedProperties.get(key: SigningPropertyKeys.unsignedBody)))
}
}

0 comments on commit 3a17012

Please sign in to comment.