Skip to content

Commit

Permalink
Integration test updates (#2502)
Browse files Browse the repository at this point in the history
* Change credentials provider to session based
* New integration test configuration file
* Change tests that have no external resources to use session-based credential provider
* Disabled certain tests from AWSCoreTests that need static credentials. We will test these in a separate process
* Removed hardcoded endpoint from APIGateway test

Co-authored-by: Tim Schmelter <schmelte@amazon.com>
  • Loading branch information
phani-srikar and palpatim committed Apr 30, 2020
1 parent 10b93fd commit 41ef33a
Show file tree
Hide file tree
Showing 49 changed files with 392 additions and 259 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ AWS*.framework

# Stuff that can't be committed #
######################
testconfiguration.json
credentials.json
Pods
Podfile.lock
Expand Down
5 changes: 3 additions & 2 deletions AWSAPIGatewayTests/AWSAPIGatewayInvokeTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class TestAPIGatewayInvoke: XCTestCase {

override func setUp() {
super.setUp()
AWSTestUtility.setupCognitoCredentialsProvider()
client = AWSLambdaMicroserviceClient.default()
AWSTestUtility.setupSessionCredentialsProvider()
let testConfig = AWSTestUtility.getIntegrationTestConfiguration(forPackageId: "apigateway")
client = AWSLambdaMicroserviceClient.defaultClient(testConfig!["endpointURL"] as! String)

headerParameters = [
"Content-Type": "application/json",
Expand Down
2 changes: 1 addition & 1 deletion AWSAPIGatewayTests/AWSLambdaMicroserviceClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ NS_ASSUME_NONNULL_BEGIN
@return The default service client.
*/
+ (instancetype)defaultClient;
+ (instancetype)defaultClient: (NSString *)endpointURL;

/**
Creates a service client with the given service configuration and registers it for the key.
Expand Down
20 changes: 9 additions & 11 deletions AWSAPIGatewayTests/AWSLambdaMicroserviceClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ @implementation AWSLambdaMicroserviceClient

static AWSSynchronizedMutableDictionary *_serviceClients = nil;

+ (instancetype)defaultClient {
+ (instancetype)defaultClient:(NSString *)endpointURL {
AWSServiceConfiguration *serviceConfiguration = nil;
AWSServiceInfo *serviceInfo = [[AWSInfo defaultAWSInfo] defaultServiceInfo:AWSInfoClientKey];
if (serviceInfo) {
Expand All @@ -76,6 +76,14 @@ + (instancetype)defaultClient {
serviceConfiguration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUnknown
credentialsProvider:nil];
}

if ([endpointURL hasSuffix:@"/"]) {
endpointURL = [endpointURL substringToIndex:[endpointURL length] - 1];
}
serviceConfiguration.endpoint = [[AWSEndpoint alloc] initWithRegion:serviceConfiguration.regionType
service:AWSServiceAPIGateway
URL:[NSURL URLWithString:endpointURL]];


static AWSLambdaMicroserviceClient *_defaultClient = nil;
static dispatch_once_t onceToken;
Expand Down Expand Up @@ -129,18 +137,8 @@ - (instancetype)init {
- (instancetype)initWithConfiguration:(AWSServiceConfiguration *)configuration {
if (self = [super init]) {
_configuration = [configuration copy];

NSString *URLString = @"https://mykov6r7rh.execute-api.us-east-1.amazonaws.com/prod";
if ([URLString hasSuffix:@"/"]) {
URLString = [URLString substringToIndex:[URLString length] - 1];
}
_configuration.endpoint = [[AWSEndpoint alloc] initWithRegion:_configuration.regionType
service:AWSServiceAPIGateway
URL:[NSURL URLWithString:URLString]];

AWSSignatureV4Signer *signer = [[AWSSignatureV4Signer alloc] initWithCredentialsProvider:_configuration.credentialsProvider
endpoint:_configuration.endpoint];

_configuration.baseURL = _configuration.endpoint.URL;
_configuration.requestInterceptors = @[[AWSNetworkingRequestInterceptor new], signer];
}
Expand Down
12 changes: 12 additions & 0 deletions AWSAuthSDK/AWSAuthSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@
17DED2A61F32A4E400397F88 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1786CA4D1F2BEDB8003421FF /* Images.xcassets */; };
17F4F75021F6B0750068B553 /* AWSCognitoAuth+Extensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F4F74E21F6B0750068B553 /* AWSCognitoAuth+Extensions.h */; settings = {ATTRIBUTES = (Public, ); }; };
17F4F75121F6B0750068B553 /* AWSCognitoAuth+Extensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 17F4F74F21F6B0750068B553 /* AWSCognitoAuth+Extensions.m */; };
43B25DB22457D7B600C40F76 /* testconfiguration.json in Resources */ = {isa = PBXBuildFile; fileRef = 43B25D3E2457D7B600C40F76 /* testconfiguration.json */; };
43B25DB32457D7EC00C40F76 /* testconfiguration.json in Resources */ = {isa = PBXBuildFile; fileRef = 43B25D3E2457D7B600C40F76 /* testconfiguration.json */; };
43B25DB42457D7EE00C40F76 /* testconfiguration.json in Resources */ = {isa = PBXBuildFile; fileRef = 43B25D3E2457D7B600C40F76 /* testconfiguration.json */; };
43B25DB52457D7F000C40F76 /* testconfiguration.json in Resources */ = {isa = PBXBuildFile; fileRef = 43B25D3E2457D7B600C40F76 /* testconfiguration.json */; };
43B25DB62457D7F100C40F76 /* testconfiguration.json in Resources */ = {isa = PBXBuildFile; fileRef = 43B25D3E2457D7B600C40F76 /* testconfiguration.json */; };
6BB7BFAF23E5E8FB0026E789 /* AWSMobileClient-Mixed-Swift.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BB7BF2E23E5E8FB0026E789 /* AWSMobileClient-Mixed-Swift.h */; };
B4031B79230F044A009EB524 /* AWSMobileClientUserDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4031B78230F044A009EB524 /* AWSMobileClientUserDetails.swift */; };
B4031BE623105727009EB524 /* AWSMobileClientSignInTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4031BE523105727009EB524 /* AWSMobileClientSignInTests.swift */; };
Expand Down Expand Up @@ -1370,6 +1375,7 @@
17D61FA6216BBC59009B2B9C /* AWSMobileClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AWSMobileClient.swift; sourceTree = "<group>"; };
17F4F74E21F6B0750068B553 /* AWSCognitoAuth+Extensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AWSCognitoAuth+Extensions.h"; sourceTree = "<group>"; };
17F4F74F21F6B0750068B553 /* AWSCognitoAuth+Extensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AWSCognitoAuth+Extensions.m"; sourceTree = "<group>"; };
43B25D3E2457D7B600C40F76 /* testconfiguration.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = testconfiguration.json; path = ../../../AWSCoreTests/Resources/testconfiguration.json; sourceTree = "<group>"; };
6BB7BF2E23E5E8FB0026E789 /* AWSMobileClient-Mixed-Swift.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AWSMobileClient-Mixed-Swift.h"; sourceTree = "<group>"; };
B4031B78230F044A009EB524 /* AWSMobileClientUserDetails.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AWSMobileClientUserDetails.swift; sourceTree = "<group>"; };
B4031BE523105727009EB524 /* AWSMobileClientSignInTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AWSMobileClientSignInTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1754,6 +1760,7 @@
isa = PBXGroup;
children = (
177B8AD521DFF12A0051068F /* awsconfiguration.json */,
43B25D3E2457D7B600C40F76 /* testconfiguration.json */,
17CD4B5521826BA100953483 /* credentials-mc.json */,
17CD4AA8218241AD00953483 /* Info.plist */,
B4C8E49F23073D7B0064C158 /* AWSMobileClientTestBase.swift */,
Expand Down Expand Up @@ -3308,6 +3315,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
43B25DB42457D7EE00C40F76 /* testconfiguration.json in Resources */,
1773B1D922029DAE00356909 /* credentials-mc.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -3325,6 +3333,7 @@
buildActionMask = 2147483647;
files = (
B412F5DA23341E9600F1AC69 /* awsconfiguration.json in Resources */,
43B25DB22457D7B600C40F76 /* testconfiguration.json in Resources */,
17CD4B5621826BA100953483 /* credentials-mc.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -3337,6 +3346,7 @@
17CD4B2D218244EC00953483 /* LaunchScreen.storyboard in Resources */,
17CD4B2A218244EC00953483 /* Assets.xcassets in Resources */,
17CD4B28218244EA00953483 /* Main.storyboard in Resources */,
43B25DB52457D7F000C40F76 /* testconfiguration.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -3345,6 +3355,7 @@
buildActionMask = 2147483647;
files = (
B412F5ED233477BF00F1AC69 /* credentials-mc.json in Resources */,
43B25DB32457D7EC00C40F76 /* testconfiguration.json in Resources */,
B412F5EC2334755B00F1AC69 /* awsconfiguration.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -3354,6 +3365,7 @@
buildActionMask = 2147483647;
files = (
B412F65623347FBD00F1AC69 /* Main.storyboard in Resources */,
43B25DB62457D7F100C40F76 /* testconfiguration.json in Resources */,
B412F65423347FBD00F1AC69 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
27 changes: 16 additions & 11 deletions AWSAuthSDK/Tests/AWSMobileClientTests/AWSMobileClientTestBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ class AWSMobileClientTestBase: XCTestCase {
let sharedPassword: String = "Abc123@@!!"

override class func setUp() {
let credentialsJson = loadCredentialsFromFile()
userPoolId = (credentialsJson["mc-userpool_id"] as! String)
sharedEmail = (credentialsJson["mc-email"] as! String)
identityPoolId = (credentialsJson["mc-pool_id_dev_auth"] as! String)
let testConfigurationJSON = loadTestConfigurationFromFile()
let credentialsTestConfiguration = testConfigurationJSON["Credentials"] as! [String: Any]
let allPackagesTestConfiguration = testConfigurationJSON["Packages"] as! [String: Any]
let mobileClientTesConfiguration = allPackagesTestConfiguration["mobileclient"] as! [String: Any]

let credentialsProvider = AWSStaticCredentialsProvider(accessKey: credentialsJson["accessKey"] as! String,
secretKey: credentialsJson["secretKey"] as! String)
userPoolId = (mobileClientTesConfiguration["mc-userpool_id"] as! String)
sharedEmail = (mobileClientTesConfiguration["mc-email"] as! String)
identityPoolId = (mobileClientTesConfiguration["mc-pool_id_dev_auth"] as! String)

let region = (credentialsJson["mc-region"] as! String).aws_regionTypeValue()
let credentialsProvider = AWSBasicSessionCredentialsProvider(accessKey: credentialsTestConfiguration["accessKey"] as! String,
secretKey: credentialsTestConfiguration["secretKey"] as! String,
sessionToken: credentialsTestConfiguration["sessionToken"] as! String)

let region = (credentialsTestConfiguration["region"] as! String).aws_regionTypeValue()
let configuration = AWSServiceConfiguration(region: region, credentialsProvider: credentialsProvider)!

AWSCognitoIdentityProvider.register(with: configuration, forKey: "TEST")
Expand All @@ -49,11 +54,11 @@ class AWSMobileClientTestBase: XCTestCase {

//MARK: Helper methods

static func loadCredentialsFromFile() -> [String: Any] {
let filePath = Bundle(for: AWSMobileClientTestBase.self).path(forResource: "credentials-mc", ofType: "json")!
static func loadTestConfigurationFromFile() -> [String: Any] {
let filePath = Bundle(for: AWSMobileClientTestBase.self).path(forResource: "testconfiguration", ofType: "json")!
let fileData = try! NSData(contentsOfFile: filePath) as Data
let credentialsJson = try! JSONSerialization.jsonObject(with: fileData, options: .mutableContainers) as! [String: Any]
return credentialsJson
let testConfigurationJSON = try! JSONSerialization.jsonObject(with: fileData, options: .mutableContainers) as! [String: Any]
return testConfigurationJSON
}

static func initializeMobileClient() {
Expand Down
2 changes: 1 addition & 1 deletion AWSAutoScalingTests/AWSAutoScalingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ @implementation AWSAutoScalingTests

+ (void)setUp {
[super setUp];
[AWSTestUtility setupCognitoCredentialsProvider];
[AWSTestUtility setupSessionCredentialsProvider];
}

- (void)setUp {
Expand Down
2 changes: 1 addition & 1 deletion AWSCloudWatchTests/AWSCloudWatchTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ @implementation AWSCloudWatchTests

+ (void)setUp {
[super setUp];
[AWSTestUtility setupCognitoCredentialsProvider];
[AWSTestUtility setupSessionCredentialsProvider];
}

- (void)setUp {
Expand Down
17 changes: 5 additions & 12 deletions AWSCognitoIdentityProviderTests/AWSCognitoIdentityProviderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <libkern/OSAtomic.h>

@interface AWSCognitoIdentityProviderTests : XCTestCase<AWSCognitoIdentityInteractiveAuthenticationDelegate, AWSCognitoIdentityPasswordAuthentication>

@property AWSRegionType region;
@end

@implementation AWSCognitoIdentityProviderTests
Expand Down Expand Up @@ -65,17 +65,9 @@ -(void) didCompletePasswordAuthenticationStepWithError:(NSError* _Nullable) erro

#pragma mark test suite setup
+ (AWSTask *) initializeTests {

NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"credentials"
ofType:@"json"];
NSDictionary *credentialsJson = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:filePath]
options:NSJSONReadingMutableContainers
error:nil];

AWSStaticCredentialsProvider *credentialsProvider = [[AWSStaticCredentialsProvider alloc] initWithAccessKey:credentialsJson[@"accessKey"]
secretKey:credentialsJson[@"secretKey"]];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1
credentialsProvider:credentialsProvider];
[AWSTestUtility setupSessionCredentialsProvider];
AWSServiceConfiguration *configuration = [AWSServiceManager defaultServiceManager].defaultServiceConfiguration;
[AWSCognitoIdentityProvider registerCognitoIdentityProviderWithConfiguration:configuration forKey:CIP_POOL_KEY];
AWSCognitoIdentityProvider *cip = [AWSCognitoIdentityProvider CognitoIdentityProviderForKey:CIP_POOL_KEY];

Expand Down Expand Up @@ -154,6 +146,7 @@ - (void) shutDownTests {
- (void)setUp {
// Put setup code here. This method is called before the invocation of each test method in the class.
[super setUp];
self.region = [AWSTestUtility getRegionFromTestConfiguration];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[[[AWSCognitoIdentityProviderTests initializeTests] continueWithBlock:^id _Nullable(AWSTask * _Nonnull task) {
Expand All @@ -162,7 +155,7 @@ - (void)setUp {
}
return nil;
}] waitUntilFinished];
AWSServiceConfiguration *serviceConfiguration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil];
AWSServiceConfiguration *serviceConfiguration = [[AWSServiceConfiguration alloc] initWithRegion:self.region credentialsProvider:nil];
AWSCognitoIdentityUserPoolConfiguration *iDPConfiguration = [[AWSCognitoIdentityUserPoolConfiguration alloc] initWithClientId:clientId
clientSecret:clientSecret
poolId:poolId
Expand Down
4 changes: 2 additions & 2 deletions AWSCognitoTests/AWSCognitoClientTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ -(AWSTask *)swizzled_updateRecords:(AWSCognitoSyncUpdateRecordsRequest *)request

@implementation AWSCognitoClientTest
+ (void)setUp {
AWSCognitoCredentialsProvider *provider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
AWSCognitoCredentialsProvider *provider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:[CognitoTestUtils region]
identityPoolId:[CognitoTestUtils identityPoolId]];

AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:provider];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:[CognitoTestUtils region] credentialsProvider:provider];

[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
}
Expand Down
14 changes: 5 additions & 9 deletions AWSCognitoTests/AWSCognitoSyncServiceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import <AWSCore/AWSCore.h>
#import "AWSCognito.h"
#import "CognitoTestUtils.h"
#import "AWSTestUtility.h"

@interface AWSCognitoSyncTests : XCTestCase

Expand All @@ -28,14 +29,14 @@ @interface AWSCognitoSyncTests : XCTestCase
@implementation AWSCognitoSyncTests

+ (void)setUp {
AWSCognitoCredentialsProvider *provider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
AWSCognitoCredentialsProvider *provider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:[CognitoTestUtils region]
identityPoolId:[CognitoTestUtils identityPoolId]
unauthRoleArn:[CognitoTestUtils unauthRoleArn]
authRoleArn:[CognitoTestUtils authRoleArn]
identityProviderManager:nil];
[[provider getIdentityId] waitUntilFinished];
_identityId = provider.identityId;
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:[CognitoTestUtils region]
credentialsProvider:provider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;

Expand All @@ -58,13 +59,8 @@ - (void)testListRecords {
}

- (void)testInvalidDatasetNameFails {
NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"credentials" ofType:@"json"];
NSDictionary *credentialsJson = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:filePath]
options:NSJSONReadingMutableContainers
error:nil];
AWSStaticCredentialsProvider *provider = [[AWSStaticCredentialsProvider alloc] initWithAccessKey:credentialsJson[@"accessKey"]
secretKey:credentialsJson[@"secretKey"]];
AWSServiceConfiguration * configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:provider];
[AWSTestUtility setupSessionCredentialsProvider];
AWSServiceConfiguration *configuration = [AWSServiceManager defaultServiceManager].defaultServiceConfiguration;
[AWSCognitoSync registerCognitoSyncWithConfiguration:configuration forKey:@"testExampleFailed"];
AWSCognitoSync *client = [AWSCognitoSync CognitoSyncForKey:@"testExampleFailed"];

Expand Down
2 changes: 2 additions & 0 deletions AWSCognitoTests/CognitoTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <AWSCore/AWSCore.h>

@interface CognitoTestUtils : NSObject

Expand All @@ -23,5 +24,6 @@
+ (NSString *) authRoleArn;
+ (NSString *) identityPoolId;
+ (NSString *) facebookToken;
+ (AWSRegionType) region;

@end
Loading

0 comments on commit 41ef33a

Please sign in to comment.