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

chore: Add unauthenticated API integration test #1703

Merged
merged 6 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
3 changes: 3 additions & 0 deletions IntegrationTests/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func addIntegrationTestTarget(_ name: String) {
additionalDependencies = ["AWSCloudFront"]
case "AWSSTS":
additionalDependencies = ["AWSIAM", "AWSCognitoIdentity"]
case "AWSCognitoIdentity":
additionalDependencies = ["AWSSTS"]
default:
break
}
Expand Down Expand Up @@ -145,6 +147,7 @@ let servicesWithIntegrationTests: [String] = [
"AWSSQS",
"AWSSTS",
"AWSTranscribeStreaming",
"AWSCognitoIdentity",
]

func addIntegrationTests() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import XCTest
import AWSSTS
import AWSCognitoIdentity
import AWSClientRuntime

/// Tests unauthenciated API using AWSCognitoIdentity::getId
class UnauthenticatedAPITests: XCTestCase {
private let region = "us-east-1"
private var stsClient: STSClient!
private var cognitoIdentityClient: CognitoIdentityClient!

private var accountID: String!
private var identityPoolID: String!
private let identityPoolName = "idpool" + UUID().uuidString.split(separator: "-").first!.lowercased()

override func setUp() async throws {
// Set up clients
stsClient = try STSClient(region: region)
cognitoIdentityClient = try CognitoIdentityClient(region: region)

// Create identity pool & save its ID
identityPoolID = try await cognitoIdentityClient.createIdentityPool(input: CreateIdentityPoolInput(
allowUnauthenticatedIdentities: true,
identityPoolName: identityPoolName
)).identityPoolId

// Get and save account ID that has the identity pool
accountID = try await stsClient.getCallerIdentity(input: GetCallerIdentityInput()).account
}

override func tearDown() async throws {
// Delete identity pool
_ = try await cognitoIdentityClient.deleteIdentityPool(input: DeleteIdentityPoolInput(
identityPoolId: identityPoolID
))
}

func testUnauthenticatedAPI() async throws {
let id = try await cognitoIdentityClient.getId(
input: GetIdInput(accountId: accountID, identityPoolId: identityPoolID)
).identityId ?? ""
// Assert that successful response was returned with a nonempty ID.
XCTAssertTrue(id.count > 0)
}
}
Loading