Skip to content

Commit

Permalink
fix(awsmobileclient): Makes fetch aws credentials serial with the res…
Browse files Browse the repository at this point in the history
…t of the calls (#4202)
  • Loading branch information
royjit authored Jul 7, 2022
1 parent 0fbe3b6 commit eec5a59
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ extension AWSMobileClient {
self.saveLoginsMapInKeychain()
self.setLoginProviderMetadataAndSaveInKeychain(provider: provider)
self.internalCredentialsProvider?.clearCredentials()
self.internalCredentialsProvider?.credentials(withCancellationToken:self.credentialsFetchCancellationSource)
self.getAWSCredentials { _, _ in
// We discard the result here, this call is to refresh the underlying credentials
// after signIn.
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ class AWSMobileClientCredentialsTest: AWSMobileClientTestBase {
}

func testMultipleGetCredentials() {
AWSDDLog.sharedInstance.logLevel = .verbose
AWSDDLog.add(AWSDDTTYLogger.sharedInstance)
let username = "testUser" + UUID().uuidString
let credentialFetchBeforeSignIn = expectation(description: "Request to getAWSCredentials before signIn")
Expand Down Expand Up @@ -267,6 +266,36 @@ class AWSMobileClientCredentialsTest: AWSMobileClientTestBase {
})
wait(for: [credentialFetchAfterSignIn2, credentialFetchBeforeSignIn, credentialFetchAfterSignOut], timeout: 15)
}


func testMultipleConcurrentGetCredentials() {
AWSDDLog.add(AWSDDTTYLogger.sharedInstance)
let username = "testUser" + UUID().uuidString
let credentialFetchAfterSignIn = expectation(description: "Request to getAWSCredentials after signIn")
let credentialFetchAfterSignOut = expectation(description: "Request to getAWSCredentials after signOut")

signUpAndVerifyUser(username: username)
signIn(username: username)
credentialFetchAfterSignIn.expectedFulfillmentCount = 100
for _ in 1...100 {
DispatchQueue.global().async {
AWSMobileClient.default().getAWSCredentials({ (awscredentials, error) in
XCTAssertNil(error)
XCTAssertNotNil(awscredentials, "Credentials should not return nil.")
credentialFetchAfterSignIn.fulfill()
})
}}

wait(for: [credentialFetchAfterSignIn], timeout: 25)

AWSMobileClient.default().signOut()
AWSMobileClient.default().getAWSCredentials({ (awscredentials, error) in
XCTAssertNil(error)
XCTAssertNotNil(awscredentials, "Credentials should not return nil.")
credentialFetchAfterSignOut.fulfill()
})
wait(for: [credentialFetchAfterSignOut], timeout: 15)
}

/// Test AWS credentials fetched for different user are different
///
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### Bug Fixes

- **AWSMobileClient**
- Fixes concurrent execution of fetch AWS Credentials just after signIn

### Misc. Updates

- Model updates for the following services
Expand Down

0 comments on commit eec5a59

Please sign in to comment.