diff --git a/Tests/SotoCoreTests/Credential/ConfigFileCredentialProviderTests.swift b/Tests/SotoCoreTests/Credential/ConfigFileCredentialProviderTests.swift index 580692ec5..ef60862fe 100644 --- a/Tests/SotoCoreTests/Credential/ConfigFileCredentialProviderTests.swift +++ b/Tests/SotoCoreTests/Credential/ConfigFileCredentialProviderTests.swift @@ -200,6 +200,35 @@ class ConfigFileCredentialProviderTests: XCTestCase { XCTAssertEqual(credential?.secretAccessKey, "AWSSECRETACCESSKEY") } + func testAWSProfileConfigFile() { + let credentials = """ + [test-profile] + aws_access_key_id = TESTPROFILE-AWSACCESSKEYID + aws_secret_access_key = TESTPROFILE-AWSSECRETACCESSKEY + """ + Environment.set("test-profile", for: "AWS_PROFILE") + defer { Environment.unset(name: "AWS_PROFILE") } + + let filename = "credentials" + let filenameURL = URL(fileURLWithPath: filename) + XCTAssertNoThrow(try Data(credentials.utf8).write(to: filenameURL)) + defer { XCTAssertNoThrow(try FileManager.default.removeItem(at: filenameURL)) } + + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) + let eventLoop = eventLoopGroup.next() + defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) } + let httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoop)) + defer { XCTAssertNoThrow(try httpClient.syncShutdown()) } + let factory = CredentialProviderFactory.configFile(credentialsFilePath: filenameURL.path) + + let provider = factory.createProvider(context: .init(httpClient: httpClient, eventLoop: eventLoop, logger: TestEnvironment.logger)) + + var credential: Credential? + XCTAssertNoThrow(credential = try provider.getCredential(on: eventLoop, logger: TestEnvironment.logger).wait()) + XCTAssertEqual(credential?.accessKeyId, "TESTPROFILE-AWSACCESSKEYID") + XCTAssertEqual(credential?.secretAccessKey, "TESTPROFILE-AWSSECRETACCESSKEY") + } + func testConfigFileNotAvailable() { let filename = "credentials_not_existing" let filenameURL = URL(fileURLWithPath: filename)