Skip to content

Commit

Permalink
Swift 6 fixes in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Sep 21, 2024
1 parent 8bcbe55 commit e753d3b
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 86 deletions.
16 changes: 11 additions & 5 deletions Tests/SotoTests/Services/EC2/EC2Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ class EC2Tests: XCTestCase {
print("Connecting to AWS")
}

Self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
Self.ec2 = EC2(
self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
self.ec2 = EC2(
client: EC2Tests.client,
region: .useast1,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
)
}

override class func tearDown() {
XCTAssertNoThrow(try Self.client.syncShutdown())
XCTAssertNoThrow(try self.client.syncShutdown())
}

func testDescribeImages() async throws {
Expand Down Expand Up @@ -79,8 +79,14 @@ class EC2Tests: XCTestCase {
}
}

extension AWSResponseError: Equatable {
public static func == (lhs: SotoCore.AWSResponseError, rhs: SotoCore.AWSResponseError) -> Bool {
extension AWSResponseError {
public static func == (lhs: AWSResponseError, rhs: AWSResponseError) -> Bool {
return lhs.errorCode == rhs.errorCode
}
}

#if hasFeature(RetroactiveAttribute)
extension AWSResponseError: @retroactive Equatable {}
#else
extension AWSResponseError: Equatable {}
#endif
166 changes: 85 additions & 81 deletions Tests/SotoTests/Services/S3/S3ExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -396,54 +396,56 @@ extension S3Tests {
)
let s3 = S3(client: client, region: .useast1)

defer { try? client.syncShutdown() }

let fields = [
"acl": "public-read",
"success_action_redirect": "http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html",
"x-amz-meta-uuid": "14365123651274",
"x-amz-server-side-encryption": "AES256",
]

let conditions: [S3.PostPolicyCondition] = [
.match("acl", "public-read"),
.match("success_action_redirect", "http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html"),
.match("x-amz-meta-uuid", "14365123651274"),
.match("x-amz-server-side-encryption", "AES256"),
.rule("starts-with", "$Content-Type", "image/"),
.rule("starts-with", "$x-amz-meta-tag", "")
]

let expiresIn = 36.0 * 60.0 * 60.0
var dateComponents = DateComponents()
dateComponents.year = 2015
dateComponents.month = 12
dateComponents.day = 29
dateComponents.timeZone = TimeZone(secondsFromGMT: 0)!

let date = Calendar(identifier: .gregorian).date(from: dateComponents)!

let presignedPost = try await s3.generatePresignedPost(
key: "user/user1/${filename}",
bucket: "sigv4examplebucket",
fields: fields,
conditions: conditions,
expiresIn: expiresIn,
date: date
)
try await withTeardown {
let fields = [
"acl": "public-read",
"success_action_redirect": "http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html",
"x-amz-meta-uuid": "14365123651274",
"x-amz-server-side-encryption": "AES256",
]

let conditions: [S3.PostPolicyCondition] = [
.match("acl", "public-read"),
.match("success_action_redirect", "http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html"),
.match("x-amz-meta-uuid", "14365123651274"),
.match("x-amz-server-side-encryption", "AES256"),
.rule("starts-with", "$Content-Type", "image/"),
.rule("starts-with", "$x-amz-meta-tag", "")
]

let expiresIn = 36.0 * 60.0 * 60.0
var dateComponents = DateComponents()
dateComponents.year = 2015
dateComponents.month = 12
dateComponents.day = 29
dateComponents.timeZone = TimeZone(secondsFromGMT: 0)!

let date = Calendar(identifier: .gregorian).date(from: dateComponents)!

let presignedPost = try await s3.generatePresignedPost(
key: "user/user1/${filename}",
bucket: "sigv4examplebucket",
fields: fields,
conditions: conditions,
expiresIn: expiresIn,
date: date
)

let expectedURL = "https://sigv4examplebucket.s3.us-east-1.amazonaws.com"
let expectedCredential = "AKIAIOSFODNN7EXAMPLE/20151229/us-east-1/s3/aws4_request"
let expectedAlgorithm = "AWS4-HMAC-SHA256"
let expectedDate = "20151229T000000Z"
let expectedURL = "https://sigv4examplebucket.s3.us-east-1.amazonaws.com"
let expectedCredential = "AKIAIOSFODNN7EXAMPLE/20151229/us-east-1/s3/aws4_request"
let expectedAlgorithm = "AWS4-HMAC-SHA256"
let expectedDate = "20151229T000000Z"

XCTAssertEqual(presignedPost.url, URL(string: expectedURL))
XCTAssertEqual(presignedPost.fields["x-amz-credential"], expectedCredential)
XCTAssertEqual(presignedPost.fields["x-amz-algorithm"], expectedAlgorithm)
XCTAssertEqual(presignedPost.fields["x-amz-date"], expectedDate)
XCTAssertEqual(presignedPost.url, URL(string: expectedURL))
XCTAssertEqual(presignedPost.fields["x-amz-credential"], expectedCredential)
XCTAssertEqual(presignedPost.fields["x-amz-algorithm"], expectedAlgorithm)
XCTAssertEqual(presignedPost.fields["x-amz-date"], expectedDate)

XCTAssertNotNil(presignedPost.fields["x-amz-signature"])
XCTAssertNotNil(presignedPost.fields["Policy"])
XCTAssertNotNil(presignedPost.fields["x-amz-signature"])
XCTAssertNotNil(presignedPost.fields["Policy"])
} teardown: {
try? await client.shutdown()
}
}

func testGetSignature() {
Expand Down Expand Up @@ -510,42 +512,44 @@ extension S3Tests {

let s3 = S3(client: client, region: .useast1)

defer { try? client.syncShutdown() }

let fields = [
"acl": "public-read",
"success_action_redirect": "http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html",
"x-amz-meta-uuid": "14365123651274",
"x-amz-server-side-encryption": "AES256",
]

let conditions: [S3.PostPolicyCondition] = [
.match("acl", "public-read"),
.match("success_action_redirect", "http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html"),
.match("x-amz-meta-uuid", "14365123651274"),
.match("x-amz-server-side-encryption", "AES256"),
.rule("starts-with", "$Content-Type", "image/"),
.rule("starts-with", "$x-amz-meta-tag", "")
]

let expiresIn = 36.0 * 60.0 * 60.0
var dateComponents = DateComponents()
dateComponents.year = 2015
dateComponents.month = 12
dateComponents.day = 29
dateComponents.timeZone = TimeZone(secondsFromGMT: 0)!

let date = Calendar(identifier: .gregorian).date(from: dateComponents)!

let presignedPost = try await s3.generatePresignedPost(
key: "user/user1/${filename}",
bucket: "sigv4examplebucket",
fields: fields,
conditions: conditions,
expiresIn: expiresIn,
date: date
)
try await withTeardown {
let fields = [
"acl": "public-read",
"success_action_redirect": "http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html",
"x-amz-meta-uuid": "14365123651274",
"x-amz-server-side-encryption": "AES256",
]

let conditions: [S3.PostPolicyCondition] = [
.match("acl", "public-read"),
.match("success_action_redirect", "http://sigv4examplebucket.s3.amazonaws.com/successful_upload.html"),
.match("x-amz-meta-uuid", "14365123651274"),
.match("x-amz-server-side-encryption", "AES256"),
.rule("starts-with", "$Content-Type", "image/"),
.rule("starts-with", "$x-amz-meta-tag", "")
]

let expiresIn = 36.0 * 60.0 * 60.0
var dateComponents = DateComponents()
dateComponents.year = 2015
dateComponents.month = 12
dateComponents.day = 29
dateComponents.timeZone = TimeZone(secondsFromGMT: 0)!

let date = Calendar(identifier: .gregorian).date(from: dateComponents)!

let presignedPost = try await s3.generatePresignedPost(
key: "user/user1/${filename}",
bucket: "sigv4examplebucket",
fields: fields,
conditions: conditions,
expiresIn: expiresIn,
date: date
)

XCTAssertEqual(presignedPost.fields["x-amz-security-token"], "EXAMPLESESSIONTOKEN")
XCTAssertEqual(presignedPost.fields["x-amz-security-token"], "EXAMPLESESSIONTOKEN")
} teardown: {
try? await client.shutdown()
}
}
}

0 comments on commit e753d3b

Please sign in to comment.