Skip to content

Commit aa75e66

Browse files
royjitharsh62
andauthored
test(AWSCore): Adds concurrency test for CredentialProvider (#4567)
* test(AWSCore): Adds concurrency test for CredentialProvider * Fix * Add integ test * Fix test * Removed logs * Removed unwanted files --------- Co-authored-by: Harshdeep Singh <[email protected]>
1 parent 2d15e0f commit aa75e66

File tree

2 files changed

+127
-2
lines changed

2 files changed

+127
-2
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
//
2+
// Copyright 2010-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License").
5+
// You may not use this file except in compliance with the License.
6+
// A copy of the License is located at
7+
//
8+
// http://aws.amazon.com/apache2.0
9+
//
10+
// or in the "license" file accompanying this file. This file is distributed
11+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
// express or implied. See the License for the specific language governing
13+
// permissions and limitations under the License.
14+
//
15+
16+
#if !AWS_TEST_BJS_INSTEAD
17+
18+
#import <XCTest/XCTest.h>
19+
#import "AWSCore.h"
20+
#import "AWSTestUtility.h"
21+
22+
NSString *TestsIdentityPoolId = nil;
23+
24+
@interface AWSUnAuthenticatedIdentityProvider : NSObject<AWSIdentityProvider, AWSIdentityProviderManager>
25+
26+
@end
27+
28+
@implementation AWSUnAuthenticatedIdentityProvider
29+
30+
- (NSString *)identityProviderName {
31+
return nil;
32+
}
33+
34+
- (AWSTask<NSString *> *)token {
35+
return [AWSTask taskWithResult: nil];
36+
}
37+
38+
- (AWSTask<NSDictionary<NSString *, NSString *> *> *)logins {
39+
return [[self token] continueWithSuccessBlock:^id _Nullable(AWSTask<NSString *> * _Nonnull task) {
40+
return [AWSTask taskWithResult:[NSDictionary new]];
41+
}];
42+
}
43+
44+
@end
45+
46+
@interface AWSCognitoCredentialsProviderConcurrencyTests : XCTestCase
47+
48+
@property AWSRegionType region;
49+
50+
@end
51+
52+
@implementation AWSCognitoCredentialsProviderConcurrencyTests
53+
54+
#pragma mark - Set up/Tear down
55+
56+
+ (void)setUp {
57+
[super setUp];
58+
[AWSTestUtility setupSessionCredentialsProvider];
59+
AWSServiceConfiguration *configuration = [AWSServiceManager defaultServiceManager].defaultServiceConfiguration;
60+
[AWSCognitoIdentity registerCognitoIdentityWithConfiguration:configuration
61+
forKey:@"Session"];
62+
63+
NSDictionary *testConfig = [AWSTestUtility getIntegrationTestConfigurationForPackageId: @"core"];
64+
TestsIdentityPoolId = testConfig[@"identityPoolId"];
65+
66+
}
67+
68+
- (void)setUp {
69+
[super setUp];
70+
self.region = [AWSTestUtility getRegionFromTestConfiguration];
71+
}
72+
73+
- (void)tearDown {
74+
[[NSNotificationCenter defaultCenter] removeObserver:self];
75+
AWSCognitoCredentialsProvider *provider = [[AWSCognitoCredentialsProvider alloc]
76+
initWithRegionType:self.region
77+
identityPoolId:TestsIdentityPoolId];
78+
[provider clearKeychain];
79+
[super tearDown];
80+
}
81+
82+
- (void)testMultiThreadedWithEnhancedFlow {
83+
AWSCognitoCredentialsProviderHelper *identityProvider = [[AWSCognitoCredentialsProviderHelper alloc]
84+
initWithRegionType: self.region
85+
identityPoolId:TestsIdentityPoolId
86+
useEnhancedFlow:YES
87+
identityProviderManager:[AWSUnAuthenticatedIdentityProvider new]];
88+
89+
AWSCognitoCredentialsProvider *provider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:self.region
90+
identityProvider:identityProvider];
91+
92+
dispatch_queue_t processingQueue = dispatch_queue_create("com.amazon.testqueue", DISPATCH_QUEUE_CONCURRENT);
93+
94+
XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription: @"Credential succeeded"];
95+
[expectation setExpectedFulfillmentCount:100];
96+
for (int i = 0; i < 100; i++) {
97+
98+
dispatch_async (processingQueue, ^{
99+
[provider clearCredentials];
100+
[identityProvider setIdentityId:nil];
101+
[[provider credentials] continueWithBlock:^id(AWSTask *task) {
102+
XCTAssertNotNil(provider.identityId, @"Unable to get identityId");
103+
104+
AWSCredentials *credentials = task.result;
105+
XCTAssertNotNil(credentials.secretKey);
106+
XCTAssertNotNil(credentials.sessionKey);
107+
XCTAssertNotNil(credentials.expiration);
108+
[expectation fulfill];
109+
return nil;
110+
}] ;
111+
112+
});
113+
}
114+
[self waitForExpectations:[NSArray arrayWithObject:expectation] timeout:10];
115+
116+
117+
}
118+
119+
@end
120+
121+
#endif

AWSiOSSDKv2.xcodeproj/project.pbxproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@
615615
B44FBC4823F4B27D008EA8D2 /* AWSSignatureNullabilityTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B44FBC4723F4B27D008EA8D2 /* AWSSignatureNullabilityTests.m */; };
616616
B47FAF4322C577CE00014548 /* AWSS3TransferUtilityUnitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B47FAF4222C577CE00014548 /* AWSS3TransferUtilityUnitTests.m */; };
617617
B482E84722EEA9F20075A0A3 /* AWSS3TestHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = B482E84622EEA9F20075A0A3 /* AWSS3TestHelper.m */; };
618+
B499A9C529A462A100CC7F2C /* AWSCognitoCredentialsProviderConcurrencyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B499A9C429A462A100CC7F2C /* AWSCognitoCredentialsProviderConcurrencyTests.m */; };
618619
B4A4E01222B420C500379396 /* AWSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE0D416D1C6A66E5006B91B5 /* AWSCore.framework */; };
619620
B4A4E01B22B4212A00379396 /* AWSSageMakerRuntimeService.h in Headers */ = {isa = PBXBuildFile; fileRef = B4A4E01422B4212900379396 /* AWSSageMakerRuntimeService.h */; settings = {ATTRIBUTES = (Public, ); }; };
620621
B4A4E01C22B4212B00379396 /* AWSSageMakerRuntimeResources.h in Headers */ = {isa = PBXBuildFile; fileRef = B4A4E01522B4212900379396 /* AWSSageMakerRuntimeResources.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -3153,6 +3154,7 @@
31533154
B482E84522EEA9F10075A0A3 /* AWSS3TestHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AWSS3TestHelper.h; sourceTree = "<group>"; };
31543155
B482E84622EEA9F20075A0A3 /* AWSS3TestHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AWSS3TestHelper.m; sourceTree = "<group>"; };
31553156
B4932E1D283D4AB100993CBC /* AWSIoTKeyChainTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AWSIoTKeyChainTypes.h; sourceTree = "<group>"; };
3157+
B499A9C429A462A100CC7F2C /* AWSCognitoCredentialsProviderConcurrencyTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AWSCognitoCredentialsProviderConcurrencyTests.m; sourceTree = "<group>"; };
31563158
B4A4DFF522B4201300379396 /* AWSSageMakerRuntime.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AWSSageMakerRuntime.framework; sourceTree = BUILT_PRODUCTS_DIR; };
31573159
B4A4DFF822B4201400379396 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
31583160
B4A4E01422B4212900379396 /* AWSSageMakerRuntimeService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AWSSageMakerRuntimeService.h; sourceTree = "<group>"; };
@@ -6328,14 +6330,15 @@
63286330
isa = PBXGroup;
63296331
children = (
63306332
CEB8EF221C6A69A00098B15B /* AWSClockSkewTests.m */,
6331-
FA3EFBC324634C3400CA23B9 /* AWSStaticCredentialsTests.m */,
6333+
B499A9C429A462A100CC7F2C /* AWSCognitoCredentialsProviderConcurrencyTests.m */,
63326334
CEB8EF231C6A69A00098B15B /* AWSCognitoCredentialsProviderTests.m */,
63336335
CEB8EF241C6A69A00098B15B /* AWSCognitoIdentityServiceTests.m */,
63346336
CEB8EF251C6A69A00098B15B /* AWSCredentialsProviderTests.m */,
63356337
CEB8EF281C6A69A00098B15B /* AWSNetworkingTests.m */,
63366338
CEB8EF291C6A69A00098B15B /* AWSSerializationTests.m */,
6337-
CEB8EF2B1C6A69A00098B15B /* AWSSignatureTests.m */,
63386339
B44FBC4723F4B27D008EA8D2 /* AWSSignatureNullabilityTests.m */,
6340+
CEB8EF2B1C6A69A00098B15B /* AWSSignatureTests.m */,
6341+
FA3EFBC324634C3400CA23B9 /* AWSStaticCredentialsTests.m */,
63396342
CEB8EF2C1C6A69A00098B15B /* AWSSTSTests.m */,
63406343
CEB8EF2D1C6A69A00098B15B /* AWSTestUtility.h */,
63416344
CEB8EF2E1C6A69A00098B15B /* AWSTestUtility.m */,
@@ -12680,6 +12683,7 @@
1268012683
CEB8EF3C1C6A69A00098B15B /* AWSUtilityTests.m in Sources */,
1268112684
CEB8EF321C6A69A00098B15B /* AWSCognitoIdentityServiceTests.m in Sources */,
1268212685
B44FBC4823F4B27D008EA8D2 /* AWSSignatureNullabilityTests.m in Sources */,
12686+
B499A9C529A462A100CC7F2C /* AWSCognitoCredentialsProviderConcurrencyTests.m in Sources */,
1268312687
CEB8EF361C6A69A00098B15B /* AWSNetworkingTests.m in Sources */,
1268412688
CEB8EF391C6A69A00098B15B /* AWSSignatureTests.m in Sources */,
1268512689
CEB8EF3B1C6A69A00098B15B /* AWSTestUtility.m in Sources */,

0 commit comments

Comments
 (0)