Skip to content

Commit

Permalink
Added testAWSProfileConfigFile (#387)
Browse files Browse the repository at this point in the history
* Added testAWSProfileConfigFile
* Update ConfigFileCredentialProviderTests.swift
  • Loading branch information
adam-fowler authored Oct 12, 2020
1 parent 1287ab0 commit cb0b477
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cb0b477

Please sign in to comment.