From bf236a65b01707e7bf1e2f97a25723d0f7244ce6 Mon Sep 17 00:00:00 2001 From: Akash Malhotra Date: Wed, 11 Sep 2024 10:02:25 +0530 Subject: [PATCH 01/14] added provisions to enable custom handshake url via plists --- CleverTapSDK/CTConstants.h | 2 ++ CleverTapSDK/CTConstants.m | 1 + CleverTapSDK/CTDomainFactory.m | 5 +++++ CleverTapSDK/CTPlistInfo.h | 1 + CleverTapSDK/CTPlistInfo.m | 2 ++ CleverTapSDK/CTRequestFactory.m | 10 +++++++++- CleverTapSDK/CleverTap.m | 1 + CleverTapSDK/CleverTapInstanceConfig.h | 3 +++ CleverTapSDK/CleverTapInstanceConfig.m | 12 ++++++++++++ 9 files changed, 36 insertions(+), 1 deletion(-) diff --git a/CleverTapSDK/CTConstants.h b/CleverTapSDK/CTConstants.h index f5563c25..4cb2f2ec 100644 --- a/CleverTapSDK/CTConstants.h +++ b/CleverTapSDK/CTConstants.h @@ -3,6 +3,7 @@ extern NSString *const kCTApiDomain; extern NSString *const kCTNotifViewedApiDomain; extern NSString *const kHANDSHAKE_URL; +extern NSString *const kHANDSHAKE_DOMAIN_HEADER; extern NSString *const kLastSessionPing; extern NSString *const kLastSessionTime; @@ -31,6 +32,7 @@ extern NSString *const kSessionId; #define CLTAP_USE_CUSTOM_CLEVERTAP_ID_LABEL @"CleverTapUseCustomId" #define CLTAP_DISABLE_IDFV_LABEL @"CleverTapDisableIDFV" #define CLTAP_ENABLE_FILE_PROTECTION @"CleverTapEnableFileProtection" +#define CLTAP_HANDSHAKE_DOMAIN @"CleverTapHandshakeDomain" #define CLTAP_BETA_LABEL @"CleverTapBeta" #define CLTAP_SESSION_LENGTH_MINS 20 #define CLTAP_SESSION_LAST_VC_TRAIL @"last_session_vc_trail" diff --git a/CleverTapSDK/CTConstants.m b/CleverTapSDK/CTConstants.m index 4a61e130..0a7162b7 100644 --- a/CleverTapSDK/CTConstants.m +++ b/CleverTapSDK/CTConstants.m @@ -3,6 +3,7 @@ NSString *const kCTApiDomain = @"clevertap-prod.com"; NSString *const kCTNotifViewedApiDomain = @"spiky.clevertap-prod.com"; NSString *const kHANDSHAKE_URL = @"https://clevertap-prod.com/hello"; +NSString *const kHANDSHAKE_DOMAIN_HEADER =@"X-CleverTap-Handshake-Domain"; NSString *const kLastSessionPing = @"last_session_ping"; NSString *const kLastSessionTime = @"lastSessionTime"; diff --git a/CleverTapSDK/CTDomainFactory.m b/CleverTapSDK/CTDomainFactory.m index 64a3615f..e22e3b01 100644 --- a/CleverTapSDK/CTDomainFactory.m +++ b/CleverTapSDK/CTDomainFactory.m @@ -75,6 +75,11 @@ - (NSString *)loadRedirectDomain { return self.explictEndpointDomain; } } + +// if (self.config.handshakeDomain) { +// return nil; +// } + NSString *domain = nil; if (self.config.isDefaultInstance) { domain = [CTPreferences getStringForKey:[CTPreferences storageKeyWithSuffix:REDIRECT_DOMAIN_KEY config: self.config] withResetValue:[CTPreferences getStringForKey:REDIRECT_DOMAIN_KEY withResetValue:nil]]; diff --git a/CleverTapSDK/CTPlistInfo.h b/CleverTapSDK/CTPlistInfo.h index ffa177a6..3c2b322e 100644 --- a/CleverTapSDK/CTPlistInfo.h +++ b/CleverTapSDK/CTPlistInfo.h @@ -14,6 +14,7 @@ @property (nonatomic, assign, readonly) BOOL beta; @property (nonatomic, assign, readonly) BOOL disableIDFV; @property (nonatomic, assign) BOOL enableFileProtection; +@property (nonatomic, strong, readonly, nullable) NSString *handshakeDomain; @property (nonatomic, readonly) CleverTapEncryptionLevel encryptionLevel; + (instancetype _Nullable)sharedInstance; diff --git a/CleverTapSDK/CTPlistInfo.m b/CleverTapSDK/CTPlistInfo.m index c660c08d..5c67dfa2 100644 --- a/CleverTapSDK/CTPlistInfo.m +++ b/CleverTapSDK/CTPlistInfo.m @@ -94,6 +94,8 @@ - (instancetype)init { NSString *enableFileProtection = [CTPlistInfo getMetaDataForAttribute:CLTAP_ENABLE_FILE_PROTECTION]; _enableFileProtection = (enableFileProtection && [enableFileProtection isEqualToString:@"1"]); + _handshakeDomain = [CTPlistInfo getMetaDataForAttribute:CLTAP_HANDSHAKE_DOMAIN]; + NSString *encryptionLevel = [CTPlistInfo getMetaDataForAttribute:CLTAP_ENCRYPTION_LEVEL]; [self setEncryption:encryptionLevel]; } diff --git a/CleverTapSDK/CTRequestFactory.m b/CleverTapSDK/CTRequestFactory.m index 9edc1c49..251fe57e 100644 --- a/CleverTapSDK/CTRequestFactory.m +++ b/CleverTapSDK/CTRequestFactory.m @@ -12,7 +12,15 @@ @implementation CTRequestFactory + (CTRequest *_Nonnull)helloRequestWithConfig:(CleverTapInstanceConfig *_Nonnull)config { - return [[CTRequest alloc] initWithHttpMethod:@"GET" config:config params:nil url:kHANDSHAKE_URL]; + NSString *helloUrl = kHANDSHAKE_URL; + if (config.handshakeDomain) { + helloUrl = [NSString stringWithFormat:@"https://%@/hello",config.handshakeDomain]; + } + CTRequest *request = [[CTRequest alloc] initWithHttpMethod:@"GET" config:config params:nil url:helloUrl]; + if (config.handshakeDomain) { + [request.urlRequest setValue:config.handshakeDomain forHTTPHeaderField:kHANDSHAKE_DOMAIN_HEADER]; + } + return request; } + (CTRequest *_Nonnull)eventRequestWithConfig:(CleverTapInstanceConfig *_Nonnull)config params:(id _Nullable)params url:(NSString *_Nonnull)url { diff --git a/CleverTapSDK/CleverTap.m b/CleverTapSDK/CleverTap.m index 041e2a3f..51ea2335 100644 --- a/CleverTapSDK/CleverTap.m +++ b/CleverTapSDK/CleverTap.m @@ -403,6 +403,7 @@ + (nullable instancetype)_sharedInstanceWithCleverTapID:(NSString *)cleverTapID _defaultInstanceConfig.enablePersonalization = [CleverTap isPersonalizationEnabled]; _defaultInstanceConfig.logLevel = [self getDebugLevel]; _defaultInstanceConfig.enableFileProtection = _plistInfo.enableFileProtection; + _defaultInstanceConfig.handshakeDomain = _plistInfo.handshakeDomain; NSString *regionLog = (!_plistInfo.accountRegion || _plistInfo.accountRegion.length < 1) ? @"default" : _plistInfo.accountRegion; NSString *proxyDomainLog = (!_plistInfo.proxyDomain || _plistInfo.proxyDomain.length < 1) ? @"" : _plistInfo.proxyDomain; NSString *spikyProxyDomainLog = (!_plistInfo.spikyProxyDomain || _plistInfo.spikyProxyDomain.length < 1) ? @"" : _plistInfo.spikyProxyDomain; diff --git a/CleverTapSDK/CleverTapInstanceConfig.h b/CleverTapSDK/CleverTapInstanceConfig.h index 1f78cbe8..d517e4c5 100644 --- a/CleverTapSDK/CleverTapInstanceConfig.h +++ b/CleverTapSDK/CleverTapInstanceConfig.h @@ -16,6 +16,8 @@ @property (nonatomic, assign) BOOL useCustomCleverTapId; @property (nonatomic, assign) BOOL disableIDFV; @property (nonatomic, assign) BOOL enableFileProtection; +@property (nonatomic, strong, readonly, nullable) NSString *handshakeDomain; + @property (nonatomic, assign) CleverTapLogLevel logLevel; @property (nonatomic, strong, nullable) NSArray *identityKeys; @property (nonatomic, assign) CleverTapEncryptionLevel encryptionLevel; @@ -56,4 +58,5 @@ */ - (void)setEncryptionLevel:(CleverTapEncryptionLevel)encryptionLevel; - (void)setEnableFileProtection:(BOOL)enableFileProtection; +- (void)setHandshakeDomain:(NSString * _Nonnull)handshakeDomain; @end diff --git a/CleverTapSDK/CleverTapInstanceConfig.m b/CleverTapSDK/CleverTapInstanceConfig.m index 8a3144b5..4bd9c770 100644 --- a/CleverTapSDK/CleverTapInstanceConfig.m +++ b/CleverTapSDK/CleverTapInstanceConfig.m @@ -29,6 +29,7 @@ - (void)encodeWithCoder:(NSCoder *)coder [coder encodeInt: _encryptionLevel forKey:@"encryptionLevel"]; [coder encodeObject: _aesCrypt forKey:@"aesCrypt"]; [coder encodeBool:_enableFileProtection forKey:@"enableFileProtection"]; + [coder encodeObject:_handshakeDomain forKey:@"handshakeDomain"]; } - (nullable instancetype)initWithCoder:(nonnull NSCoder *)coder { @@ -54,6 +55,7 @@ - (nullable instancetype)initWithCoder:(nonnull NSCoder *)coder { _encryptionLevel = [coder decodeIntForKey:@"encryptionLevel"]; _aesCrypt = [coder decodeObjectForKey:@"aesCrypt"]; _enableFileProtection = [coder decodeBoolForKey:@"enableFileProtection"]; + _handshakeDomain = [coder decodeObjectForKey:@"handshakeDomain"]; } return self; } @@ -186,6 +188,7 @@ - (instancetype)copyWithZone:(NSZone*)zone { copy.encryptionLevel = self.encryptionLevel; copy.aesCrypt = self.aesCrypt; copy.enableFileProtection = self.enableFileProtection; + copy.handshakeDomain = self.handshakeDomain; return copy; } @@ -209,6 +212,7 @@ - (void) setupPlistData:(BOOL)isDefault { _beta = plist.beta; _encryptionLevel = isDefault ? plist.encryptionLevel : CleverTapEncryptionNone; _enableFileProtection = isDefault ? plist.enableFileProtection : NO; + _handshakeDomain = isDefault ? plist.handshakeDomain : nil; if (isDefault) { _aesCrypt = [[CTAES alloc] initWithAccountID:_accountId encryptionLevel:_encryptionLevel isDefaultInstance:isDefault]; } @@ -241,4 +245,12 @@ - (void)setEnableFileProtection:(BOOL)enableFileProtection { CleverTapLogStaticInfo("CleverTap enable file protection for default instance can't be updated from setEnableFileProtection method"); } } + +- (void)setHandshakeDomain:(NSString *)handshakeDomain { + if (!_isDefaultInstance) { + _handshakeDomain = handshakeDomain; + } else { + CleverTapLogStaticInfo("CleverTap handshake domain for default instance can't be updated from setHandshakeDomain method"); + } +} @end From 12396042e9fe8d81fd6954e263b99c70df18f830 Mon Sep 17 00:00:00 2001 From: Akash Malhotra Date: Wed, 11 Sep 2024 10:13:35 +0530 Subject: [PATCH 02/14] remove commented code --- CleverTapSDK/CTDomainFactory.m | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CleverTapSDK/CTDomainFactory.m b/CleverTapSDK/CTDomainFactory.m index e22e3b01..59f3c72f 100644 --- a/CleverTapSDK/CTDomainFactory.m +++ b/CleverTapSDK/CTDomainFactory.m @@ -76,10 +76,6 @@ - (NSString *)loadRedirectDomain { } } -// if (self.config.handshakeDomain) { -// return nil; -// } - NSString *domain = nil; if (self.config.isDefaultInstance) { domain = [CTPreferences getStringForKey:[CTPreferences storageKeyWithSuffix:REDIRECT_DOMAIN_KEY config: self.config] withResetValue:[CTPreferences getStringForKey:REDIRECT_DOMAIN_KEY withResetValue:nil]]; From c8f526fbc4cb5166f7e53d5ff2c95e2cad20ca5a Mon Sep 17 00:00:00 2001 From: Akash Malhotra Date: Wed, 11 Sep 2024 12:04:24 +0530 Subject: [PATCH 03/14] handled a use case where an existing app with cached domain would introduce the newer custom domain tag --- CleverTapSDK/CTDomainFactory.m | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/CleverTapSDK/CTDomainFactory.m b/CleverTapSDK/CTDomainFactory.m index 59f3c72f..0c8b8ea8 100644 --- a/CleverTapSDK/CTDomainFactory.m +++ b/CleverTapSDK/CTDomainFactory.m @@ -11,7 +11,7 @@ #import "CTConstants.h" #import "CleverTapInstanceConfigPrivate.h" - +NSString *const CUSTOM_DOMAIN_KEY = @"CLTAP_CUSTOM_DOMAIN_KEY"; NSString *const REDIRECT_DOMAIN_KEY = @"CLTAP_REDIRECT_DOMAIN_KEY"; NSString *const REDIRECT_NOTIF_VIEWED_DOMAIN_KEY = @"CLTAP_REDIRECT_NOTIF_VIEWED_DOMAIN_KEY"; @@ -76,6 +76,16 @@ - (NSString *)loadRedirectDomain { } } + if (self.config.handshakeDomain) { + NSString *customDomain = nil; + if (self.config.isDefaultInstance) { + customDomain = [CTPreferences getStringForKey:[CTPreferences storageKeyWithSuffix:CUSTOM_DOMAIN_KEY config: self.config] withResetValue:[CTPreferences getStringForKey:CUSTOM_DOMAIN_KEY withResetValue:nil]]; + } else { + customDomain = [CTPreferences getStringForKey:[CTPreferences storageKeyWithSuffix:CUSTOM_DOMAIN_KEY config: self.config] withResetValue:nil]; + } + return customDomain; + } + NSString *domain = nil; if (self.config.isDefaultInstance) { domain = [CTPreferences getStringForKey:[CTPreferences storageKeyWithSuffix:REDIRECT_DOMAIN_KEY config: self.config] withResetValue:[CTPreferences getStringForKey:REDIRECT_DOMAIN_KEY withResetValue:nil]]; @@ -113,13 +123,23 @@ - (NSString *)loadRedirectNotifViewedDomain { - (void)persistRedirectDomain { if (self.redirectDomain != nil) { - [CTPreferences putString:self.redirectDomain forKey:[CTPreferences storageKeyWithSuffix:REDIRECT_DOMAIN_KEY config: self.config]]; + if (self.config.handshakeDomain) { + [CTPreferences putString:self.redirectDomain forKey:[CTPreferences storageKeyWithSuffix:CUSTOM_DOMAIN_KEY config: self.config]]; + } + else { + [CTPreferences putString:self.redirectDomain forKey:[CTPreferences storageKeyWithSuffix:REDIRECT_DOMAIN_KEY config: self.config]]; + } #if CLEVERTAP_SSL_PINNING [self.urlSessionDelegate pinSSLCerts:self.sslCertNames forDomains:@[kCTApiDomain, self.redirectDomain]]; #endif } else { - [CTPreferences removeObjectForKey:REDIRECT_DOMAIN_KEY]; - [CTPreferences removeObjectForKey:[CTPreferences storageKeyWithSuffix:REDIRECT_DOMAIN_KEY config: self.config]]; + if (self.config.handshakeDomain) { + [CTPreferences removeObjectForKey:[CTPreferences storageKeyWithSuffix:CUSTOM_DOMAIN_KEY config: self.config]]; + } + else { + [CTPreferences removeObjectForKey:REDIRECT_DOMAIN_KEY]; + [CTPreferences removeObjectForKey:[CTPreferences storageKeyWithSuffix:REDIRECT_DOMAIN_KEY config: self.config]]; + } } } From d4e367e4817e31e69b13bb4163a6c8df3fb5ffb2 Mon Sep 17 00:00:00 2001 From: Akash Malhotra Date: Wed, 11 Sep 2024 17:21:14 +0530 Subject: [PATCH 04/14] updated versions and changelog --- CHANGELOG.md | 5 +++++ CleverTapSDK/CleverTapBuildInfo.h | 2 +- sdk-version.txt | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3d96eb1..edde3c1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Change Log All notable changes to this project will be documented in this file. +### [Version 7.0.2](https://github.com/CleverTap/clevertap-ios-sdk/releases/tag/7.0.2) (September 16, 2024) + +#### Added +- Adds support for custom handshake domains. + ### [Version 7.0.1](https://github.com/CleverTap/clevertap-ios-sdk/releases/tag/7.0.1) (August 22, 2024) #### Fixed diff --git a/CleverTapSDK/CleverTapBuildInfo.h b/CleverTapSDK/CleverTapBuildInfo.h index ff6f62bb..2c056645 100644 --- a/CleverTapSDK/CleverTapBuildInfo.h +++ b/CleverTapSDK/CleverTapBuildInfo.h @@ -1 +1 @@ -#define WR_SDK_REVISION @"70001" +#define WR_SDK_REVISION @"70002" diff --git a/sdk-version.txt b/sdk-version.txt index 73a86b19..2f963cd6 100644 --- a/sdk-version.txt +++ b/sdk-version.txt @@ -1 +1 @@ -7.0.1 \ No newline at end of file +7.0.2 \ No newline at end of file From 326d4843075444dfce21da4653d6e20bcc244c08 Mon Sep 17 00:00:00 2001 From: Akash Malhotra Date: Thu, 12 Sep 2024 01:07:26 +0530 Subject: [PATCH 05/14] added unit tests --- CleverTapSDK.xcodeproj/project.pbxproj | 10 +++++ CleverTapSDK/CTConstants.h | 5 +++ CleverTapSDK/CTConstants.m | 4 ++ CleverTapSDK/CTDomainFactory.m | 4 -- CleverTapSDKTests/CTDomainFactory+Tests.h | 14 ++++++ CleverTapSDKTests/CTDomainFactory+Tests.m | 13 ++++++ CleverTapSDKTests/CTDomainFactoryTests.m | 52 +++++++++++++++++++++++ 7 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 CleverTapSDKTests/CTDomainFactory+Tests.h create mode 100644 CleverTapSDKTests/CTDomainFactory+Tests.m create mode 100644 CleverTapSDKTests/CTDomainFactoryTests.m diff --git a/CleverTapSDK.xcodeproj/project.pbxproj b/CleverTapSDK.xcodeproj/project.pbxproj index 75193683..eb58c3a3 100644 --- a/CleverTapSDK.xcodeproj/project.pbxproj +++ b/CleverTapSDK.xcodeproj/project.pbxproj @@ -252,6 +252,8 @@ 4E872969277CDF9000A7A618 /* inapp_alert.json in Resources */ = {isa = PBXBuildFile; fileRef = 4E1F1561277090D6009387AE /* inapp_alert.json */; }; 4E87296E277CE8EB00A7A618 /* StubHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E87296D277CE8EB00A7A618 /* StubHelper.m */; }; 4E872973277CEE6700A7A618 /* TestConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E872972277CEE6700A7A618 /* TestConstants.m */; }; + 4E87397B2C92223C00FDFDFD /* CTDomainFactoryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E8739772C921D9000FDFDFD /* CTDomainFactoryTests.m */; }; + 4E87397E2C9223B300FDFDFD /* CTDomainFactory+Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E87397D2C9223B300FDFDFD /* CTDomainFactory+Tests.m */; }; 4E8B81662AD2ADAE00714BB4 /* CTSwizzleManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E8B81642AD2ADAE00714BB4 /* CTSwizzleManager.m */; }; 4E8B81672AD2ADAE00714BB4 /* CTSwizzleManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E8B81642AD2ADAE00714BB4 /* CTSwizzleManager.m */; }; 4E8B81682AD2ADAE00714BB4 /* CTSwizzleManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 4E8B81652AD2ADAE00714BB4 /* CTSwizzleManager.h */; }; @@ -819,6 +821,9 @@ 4E87296D277CE8EB00A7A618 /* StubHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = StubHelper.m; sourceTree = ""; }; 4E872971277CEE6700A7A618 /* TestConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestConstants.h; sourceTree = ""; }; 4E872972277CEE6700A7A618 /* TestConstants.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TestConstants.m; sourceTree = ""; }; + 4E8739772C921D9000FDFDFD /* CTDomainFactoryTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTDomainFactoryTests.m; sourceTree = ""; }; + 4E87397C2C9223B300FDFDFD /* CTDomainFactory+Tests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CTDomainFactory+Tests.h"; sourceTree = ""; }; + 4E87397D2C9223B300FDFDFD /* CTDomainFactory+Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "CTDomainFactory+Tests.m"; sourceTree = ""; }; 4E8B81642AD2ADAE00714BB4 /* CTSwizzleManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTSwizzleManager.m; sourceTree = ""; }; 4E8B81652AD2ADAE00714BB4 /* CTSwizzleManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTSwizzleManager.h; sourceTree = ""; }; 4E8B816A2AD2B2FD00714BB4 /* CleverTapInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CleverTapInternal.h; sourceTree = ""; }; @@ -1600,6 +1605,9 @@ 6BD851C82B45CD1800FA5298 /* CTMultiDelegateManager+Tests.h */, 0B5564552C25946C00B87284 /* CTUserInfoMigratorTest.m */, 0B995A492C36AEDC00AF6006 /* CTLocalDataStoreTests.m */, + 4E8739772C921D9000FDFDFD /* CTDomainFactoryTests.m */, + 4E87397C2C9223B300FDFDFD /* CTDomainFactory+Tests.h */, + 4E87397D2C9223B300FDFDFD /* CTDomainFactory+Tests.m */, ); path = CleverTapSDKTests; sourceTree = ""; @@ -2500,6 +2508,7 @@ 32394C2529FA272600956058 /* CTValidatorTest.m in Sources */, 6BB778CE2BEE48C300A41628 /* CTCustomTemplateInAppDataTest.m in Sources */, 6BA3B2E82B07E207004E834B /* CTTriggersMatcher+Tests.m in Sources */, + 4E87397E2C9223B300FDFDFD /* CTDomainFactory+Tests.m in Sources */, 6BBF05CE2C58E3FB0047E3D9 /* NSURLSessionMock.m in Sources */, 6B32A0A52B9A0F17009ADC57 /* CTCustomTemplateTest.m in Sources */, 4E1F155B276B662C009387AE /* EventDetail.m in Sources */, @@ -2539,6 +2548,7 @@ 0B995A4A2C36AEDC00AF6006 /* CTLocalDataStoreTests.m in Sources */, 6A4427C52AA6515A0098866F /* CTTriggersMatcherTest.m in Sources */, 6B32A0B02B9DC374009ADC57 /* CTTemplateArgumentTest.m in Sources */, + 4E87397B2C92223C00FDFDFD /* CTDomainFactoryTests.m in Sources */, 0B5564562C25946C00B87284 /* CTUserInfoMigratorTest.m in Sources */, 4E2CF1442AC56D8F00441E8B /* CTEncryptionTests.m in Sources */, 32394C2729FA278C00956058 /* CTUriHelperTest.m in Sources */, diff --git a/CleverTapSDK/CTConstants.h b/CleverTapSDK/CTConstants.h index 4cb2f2ec..12a1912d 100644 --- a/CleverTapSDK/CTConstants.h +++ b/CleverTapSDK/CTConstants.h @@ -5,6 +5,11 @@ extern NSString *const kCTNotifViewedApiDomain; extern NSString *const kHANDSHAKE_URL; extern NSString *const kHANDSHAKE_DOMAIN_HEADER; + +extern NSString *const CUSTOM_DOMAIN_KEY; +extern NSString *const REDIRECT_DOMAIN_KEY; +extern NSString *const REDIRECT_NOTIF_VIEWED_DOMAIN_KEY; + extern NSString *const kLastSessionPing; extern NSString *const kLastSessionTime; extern NSString *const kSessionId; diff --git a/CleverTapSDK/CTConstants.m b/CleverTapSDK/CTConstants.m index 0a7162b7..7923a16e 100644 --- a/CleverTapSDK/CTConstants.m +++ b/CleverTapSDK/CTConstants.m @@ -5,6 +5,10 @@ NSString *const kHANDSHAKE_URL = @"https://clevertap-prod.com/hello"; NSString *const kHANDSHAKE_DOMAIN_HEADER =@"X-CleverTap-Handshake-Domain"; +NSString *const CUSTOM_DOMAIN_KEY = @"CLTAP_CUSTOM_DOMAIN_KEY"; +NSString *const REDIRECT_DOMAIN_KEY = @"CLTAP_REDIRECT_DOMAIN_KEY"; +NSString *const REDIRECT_NOTIF_VIEWED_DOMAIN_KEY = @"CLTAP_REDIRECT_NOTIF_VIEWED_DOMAIN_KEY"; + NSString *const kLastSessionPing = @"last_session_ping"; NSString *const kLastSessionTime = @"lastSessionTime"; NSString *const kSessionId = @"sessionId"; diff --git a/CleverTapSDK/CTDomainFactory.m b/CleverTapSDK/CTDomainFactory.m index 0c8b8ea8..5ada3bec 100644 --- a/CleverTapSDK/CTDomainFactory.m +++ b/CleverTapSDK/CTDomainFactory.m @@ -11,10 +11,6 @@ #import "CTConstants.h" #import "CleverTapInstanceConfigPrivate.h" -NSString *const CUSTOM_DOMAIN_KEY = @"CLTAP_CUSTOM_DOMAIN_KEY"; -NSString *const REDIRECT_DOMAIN_KEY = @"CLTAP_REDIRECT_DOMAIN_KEY"; -NSString *const REDIRECT_NOTIF_VIEWED_DOMAIN_KEY = @"CLTAP_REDIRECT_NOTIF_VIEWED_DOMAIN_KEY"; - @interface CTDomainFactory () @property (nonatomic, strong) CleverTapInstanceConfig *config; diff --git a/CleverTapSDKTests/CTDomainFactory+Tests.h b/CleverTapSDKTests/CTDomainFactory+Tests.h new file mode 100644 index 00000000..4d828936 --- /dev/null +++ b/CleverTapSDKTests/CTDomainFactory+Tests.h @@ -0,0 +1,14 @@ +// +// CTDomainFactory+Tests.h +// CleverTapSDKTests +// +// Created by Akash Malhotra on 12/09/24. +// Copyright © 2024 CleverTap. All rights reserved. +// + +#import "CleverTapInstanceConfig.h" +#import "CTDomainFactory.h" + +@interface CTDomainFactory (Tests) +- (NSString *)loadRedirectDomain; +@end diff --git a/CleverTapSDKTests/CTDomainFactory+Tests.m b/CleverTapSDKTests/CTDomainFactory+Tests.m new file mode 100644 index 00000000..c2991fa5 --- /dev/null +++ b/CleverTapSDKTests/CTDomainFactory+Tests.m @@ -0,0 +1,13 @@ +// +// CTDomainFactory+Tests.m +// CleverTapSDKTests +// +// Created by Akash Malhotra on 12/09/24. +// Copyright © 2024 CleverTap. All rights reserved. +// + +#import "CTDomainFactory+Tests.h" + +@implementation CTDomainFactory (Tests) + +@end diff --git a/CleverTapSDKTests/CTDomainFactoryTests.m b/CleverTapSDKTests/CTDomainFactoryTests.m new file mode 100644 index 00000000..9ed47df6 --- /dev/null +++ b/CleverTapSDKTests/CTDomainFactoryTests.m @@ -0,0 +1,52 @@ +// +// CTDomainFactoryTests.m +// CleverTapSDKTests +// +// Created by Akash Malhotra on 12/09/24. +// Copyright © 2024 CleverTap. All rights reserved. +// +#import +#import +#import "CleverTapInstanceConfig.h" +#import "CTDomainFactory.h" +#import "CTDomainFactory+Tests.h" +#import "CTConstants.h" +#import "CTPreferences.h" + +@interface CTDomainFactoryTests: XCTestCase +@property (nonatomic, strong) NSString *region; +@property (nonatomic, strong) CleverTapInstanceConfig *config; +@property (nonatomic, strong) CTDomainFactory *domainFactory; +@end + +@implementation CTDomainFactoryTests + +- (void)setUp { + [super setUp]; + self.region = @"testRegion"; + self.config = [[CleverTapInstanceConfig alloc] initWithAccountId:@"testAccount" accountToken:@"testToken" accountRegion:self.region]; + self.domainFactory = [[CTDomainFactory alloc]initWithConfig:self.config]; +} + +- (void)tearDown { + [self.domainFactory clearRedirectDomain]; + self.domainFactory = nil; + self.region = nil; + [super tearDown]; +} + +- (void)testLoadRedirectDomainRegion { + NSString *domain = [self.domainFactory loadRedirectDomain]; + NSString *result = [NSString stringWithFormat:@"%@.%@", self.region, kCTApiDomain].lowercaseString; + XCTAssertEqualObjects(domain, result); +} + +- (void)testLoadRedirectDomainCached { + [self.domainFactory persistRedirectDomain]; + + NSString *domain = [CTPreferences getStringForKey:[CTPreferences storageKeyWithSuffix:REDIRECT_DOMAIN_KEY config: self.config] withResetValue:nil]; + NSString *result = [NSString stringWithFormat:@"%@.%@", self.region, kCTApiDomain].lowercaseString; + XCTAssertEqualObjects(domain, result); +} + +@end From 88bedd28b6260a3592b90ebe099e913a8318d5de Mon Sep 17 00:00:00 2001 From: Akash Malhotra Date: Thu, 12 Sep 2024 12:14:07 +0530 Subject: [PATCH 06/14] added more unit tests --- CleverTapSDKTests/CTDomainFactoryTests.m | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/CleverTapSDKTests/CTDomainFactoryTests.m b/CleverTapSDKTests/CTDomainFactoryTests.m index 9ed47df6..4fcdabb6 100644 --- a/CleverTapSDKTests/CTDomainFactoryTests.m +++ b/CleverTapSDKTests/CTDomainFactoryTests.m @@ -43,10 +43,28 @@ - (void)testLoadRedirectDomainRegion { - (void)testLoadRedirectDomainCached { [self.domainFactory persistRedirectDomain]; - NSString *domain = [CTPreferences getStringForKey:[CTPreferences storageKeyWithSuffix:REDIRECT_DOMAIN_KEY config: self.config] withResetValue:nil]; - NSString *result = [NSString stringWithFormat:@"%@.%@", self.region, kCTApiDomain].lowercaseString; + NSString *result = [self.domainFactory loadRedirectDomain]; XCTAssertEqualObjects(domain, result); } +- (void)testLoadRedirectDomainCustomHandShake { + CleverTapInstanceConfig *config = [[CleverTapInstanceConfig alloc] initWithAccountId:@"testAccount" accountToken:@"testToken"]; + config.handshakeDomain = @"testCustomDomain"; + CTDomainFactory *domainFactory = [[CTDomainFactory alloc]initWithConfig:config]; + domainFactory.redirectDomain = config.handshakeDomain; + [domainFactory persistRedirectDomain]; + + NSString *domain = [domainFactory loadRedirectDomain];; + XCTAssertEqualObjects(domain, config.handshakeDomain); +} + +- (void)testLoadRedirectDomainProxy { + CleverTapInstanceConfig *config = [[CleverTapInstanceConfig alloc] initWithAccountId:@"testAccount" accountToken:@"testToken" proxyDomain:@"testProxydomain"]; + CTDomainFactory *domainFactory = [[CTDomainFactory alloc]initWithConfig:config]; + + NSString *domain = [domainFactory loadRedirectDomain]; + XCTAssertEqualObjects(domain, config.proxyDomain.lowercaseString); +} + @end From 4517a7b1a764feeff02730f574049a0786b1b929 Mon Sep 17 00:00:00 2001 From: Akash Malhotra Date: Thu, 12 Sep 2024 15:38:47 +0530 Subject: [PATCH 07/14] ctrequest unit tests --- CleverTapSDK/CTConstants.h | 3 ++- CleverTapSDK/CTConstants.m | 2 ++ CleverTapSDK/CTRequest.m | 3 --- CleverTapSDKTests/CTRequestFactoryTests.m | 9 +++++++++ 4 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 CleverTapSDKTests/CTRequestFactoryTests.m diff --git a/CleverTapSDK/CTConstants.h b/CleverTapSDK/CTConstants.h index 12a1912d..d9b79d40 100644 --- a/CleverTapSDK/CTConstants.h +++ b/CleverTapSDK/CTConstants.h @@ -4,7 +4,8 @@ extern NSString *const kCTApiDomain; extern NSString *const kCTNotifViewedApiDomain; extern NSString *const kHANDSHAKE_URL; extern NSString *const kHANDSHAKE_DOMAIN_HEADER; - +extern NSString *const ACCOUNT_ID_HEADER; +extern NSString *const ACCOUNT_TOKEN_HEADER; extern NSString *const CUSTOM_DOMAIN_KEY; extern NSString *const REDIRECT_DOMAIN_KEY; diff --git a/CleverTapSDK/CTConstants.m b/CleverTapSDK/CTConstants.m index 7923a16e..323f69fb 100644 --- a/CleverTapSDK/CTConstants.m +++ b/CleverTapSDK/CTConstants.m @@ -4,6 +4,8 @@ NSString *const kCTNotifViewedApiDomain = @"spiky.clevertap-prod.com"; NSString *const kHANDSHAKE_URL = @"https://clevertap-prod.com/hello"; NSString *const kHANDSHAKE_DOMAIN_HEADER =@"X-CleverTap-Handshake-Domain"; +NSString *const ACCOUNT_ID_HEADER = @"X-CleverTap-Account-Id"; +NSString *const ACCOUNT_TOKEN_HEADER = @"X-CleverTap-Token"; NSString *const CUSTOM_DOMAIN_KEY = @"CLTAP_CUSTOM_DOMAIN_KEY"; NSString *const REDIRECT_DOMAIN_KEY = @"CLTAP_REDIRECT_DOMAIN_KEY"; diff --git a/CleverTapSDK/CTRequest.m b/CleverTapSDK/CTRequest.m index b8734910..e3aed06a 100644 --- a/CleverTapSDK/CTRequest.m +++ b/CleverTapSDK/CTRequest.m @@ -10,9 +10,6 @@ #import "CTConstants.h" #import "CTUtils.h" -NSString *const ACCOUNT_ID_HEADER = @"X-CleverTap-Account-Id"; -NSString *const ACCOUNT_TOKEN_HEADER = @"X-CleverTap-Token"; - @interface CTRequest() @property (nonatomic, strong, nullable) id params; diff --git a/CleverTapSDKTests/CTRequestFactoryTests.m b/CleverTapSDKTests/CTRequestFactoryTests.m new file mode 100644 index 00000000..16a84ecc --- /dev/null +++ b/CleverTapSDKTests/CTRequestFactoryTests.m @@ -0,0 +1,9 @@ +// +// CTRequestFactoryTests.m +// CleverTapSDKTests +// +// Created by Akash Malhotra on 12/09/24. +// Copyright © 2024 CleverTap. All rights reserved. +// + +#import From 362041e86bcc3621e784504b0d9b16b85d159f2c Mon Sep 17 00:00:00 2001 From: Akash Malhotra Date: Wed, 25 Sep 2024 13:02:17 +0530 Subject: [PATCH 08/14] removed custom domain key value in preferences --- CleverTapSDK/CTDomainFactory.m | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/CleverTapSDK/CTDomainFactory.m b/CleverTapSDK/CTDomainFactory.m index 5ada3bec..b18c0b99 100644 --- a/CleverTapSDK/CTDomainFactory.m +++ b/CleverTapSDK/CTDomainFactory.m @@ -72,16 +72,6 @@ - (NSString *)loadRedirectDomain { } } - if (self.config.handshakeDomain) { - NSString *customDomain = nil; - if (self.config.isDefaultInstance) { - customDomain = [CTPreferences getStringForKey:[CTPreferences storageKeyWithSuffix:CUSTOM_DOMAIN_KEY config: self.config] withResetValue:[CTPreferences getStringForKey:CUSTOM_DOMAIN_KEY withResetValue:nil]]; - } else { - customDomain = [CTPreferences getStringForKey:[CTPreferences storageKeyWithSuffix:CUSTOM_DOMAIN_KEY config: self.config] withResetValue:nil]; - } - return customDomain; - } - NSString *domain = nil; if (self.config.isDefaultInstance) { domain = [CTPreferences getStringForKey:[CTPreferences storageKeyWithSuffix:REDIRECT_DOMAIN_KEY config: self.config] withResetValue:[CTPreferences getStringForKey:REDIRECT_DOMAIN_KEY withResetValue:nil]]; @@ -119,23 +109,13 @@ - (NSString *)loadRedirectNotifViewedDomain { - (void)persistRedirectDomain { if (self.redirectDomain != nil) { - if (self.config.handshakeDomain) { - [CTPreferences putString:self.redirectDomain forKey:[CTPreferences storageKeyWithSuffix:CUSTOM_DOMAIN_KEY config: self.config]]; - } - else { - [CTPreferences putString:self.redirectDomain forKey:[CTPreferences storageKeyWithSuffix:REDIRECT_DOMAIN_KEY config: self.config]]; - } + [CTPreferences putString:self.redirectDomain forKey:[CTPreferences storageKeyWithSuffix:REDIRECT_DOMAIN_KEY config: self.config]]; #if CLEVERTAP_SSL_PINNING [self.urlSessionDelegate pinSSLCerts:self.sslCertNames forDomains:@[kCTApiDomain, self.redirectDomain]]; #endif } else { - if (self.config.handshakeDomain) { - [CTPreferences removeObjectForKey:[CTPreferences storageKeyWithSuffix:CUSTOM_DOMAIN_KEY config: self.config]]; - } - else { - [CTPreferences removeObjectForKey:REDIRECT_DOMAIN_KEY]; - [CTPreferences removeObjectForKey:[CTPreferences storageKeyWithSuffix:REDIRECT_DOMAIN_KEY config: self.config]]; - } + [CTPreferences removeObjectForKey:REDIRECT_DOMAIN_KEY]; + [CTPreferences removeObjectForKey:[CTPreferences storageKeyWithSuffix:REDIRECT_DOMAIN_KEY config: self.config]]; } } From 523213c81c03ae4cd451baf081db97a2000d8617 Mon Sep 17 00:00:00 2001 From: Akash Malhotra Date: Wed, 25 Sep 2024 13:10:03 +0530 Subject: [PATCH 09/14] removed custom domain constants --- CleverTapSDK/CTConstants.h | 1 - CleverTapSDK/CTConstants.m | 1 - 2 files changed, 2 deletions(-) diff --git a/CleverTapSDK/CTConstants.h b/CleverTapSDK/CTConstants.h index d9b79d40..e544d2bd 100644 --- a/CleverTapSDK/CTConstants.h +++ b/CleverTapSDK/CTConstants.h @@ -7,7 +7,6 @@ extern NSString *const kHANDSHAKE_DOMAIN_HEADER; extern NSString *const ACCOUNT_ID_HEADER; extern NSString *const ACCOUNT_TOKEN_HEADER; -extern NSString *const CUSTOM_DOMAIN_KEY; extern NSString *const REDIRECT_DOMAIN_KEY; extern NSString *const REDIRECT_NOTIF_VIEWED_DOMAIN_KEY; diff --git a/CleverTapSDK/CTConstants.m b/CleverTapSDK/CTConstants.m index 323f69fb..b7f5ef46 100644 --- a/CleverTapSDK/CTConstants.m +++ b/CleverTapSDK/CTConstants.m @@ -7,7 +7,6 @@ NSString *const ACCOUNT_ID_HEADER = @"X-CleverTap-Account-Id"; NSString *const ACCOUNT_TOKEN_HEADER = @"X-CleverTap-Token"; -NSString *const CUSTOM_DOMAIN_KEY = @"CLTAP_CUSTOM_DOMAIN_KEY"; NSString *const REDIRECT_DOMAIN_KEY = @"CLTAP_REDIRECT_DOMAIN_KEY"; NSString *const REDIRECT_NOTIF_VIEWED_DOMAIN_KEY = @"CLTAP_REDIRECT_NOTIF_VIEWED_DOMAIN_KEY"; From e371d227f1c23bcf4805047cb11512e33a7f5426 Mon Sep 17 00:00:00 2001 From: Akash Malhotra Date: Wed, 9 Oct 2024 17:14:15 +0530 Subject: [PATCH 10/14] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edde3c1d..c343c4d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Change Log All notable changes to this project will be documented in this file. -### [Version 7.0.2](https://github.com/CleverTap/clevertap-ios-sdk/releases/tag/7.0.2) (September 16, 2024) +### [Version 7.0.2](https://github.com/CleverTap/clevertap-ios-sdk/releases/tag/7.0.2) (October 09, 2024) #### Added - Adds support for custom handshake domains. From 94061c70f16d80cd5030297f9355da0deac239af Mon Sep 17 00:00:00 2001 From: Akash Malhotra Date: Wed, 9 Oct 2024 17:20:37 +0530 Subject: [PATCH 11/14] removed a stray file --- CleverTapSDKTests/CTRequestFactoryTests.m | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 CleverTapSDKTests/CTRequestFactoryTests.m diff --git a/CleverTapSDKTests/CTRequestFactoryTests.m b/CleverTapSDKTests/CTRequestFactoryTests.m deleted file mode 100644 index 16a84ecc..00000000 --- a/CleverTapSDKTests/CTRequestFactoryTests.m +++ /dev/null @@ -1,9 +0,0 @@ -// -// CTRequestFactoryTests.m -// CleverTapSDKTests -// -// Created by Akash Malhotra on 12/09/24. -// Copyright © 2024 CleverTap. All rights reserved. -// - -#import From 344f047b6b60fd325abca8d02fbc6168f465a353 Mon Sep 17 00:00:00 2001 From: Akash Malhotra Date: Wed, 9 Oct 2024 20:55:57 +0530 Subject: [PATCH 12/14] fixed domain property specifier --- CleverTapSDK/CleverTapInstanceConfig.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CleverTapSDK/CleverTapInstanceConfig.h b/CleverTapSDK/CleverTapInstanceConfig.h index d517e4c5..c351f444 100644 --- a/CleverTapSDK/CleverTapInstanceConfig.h +++ b/CleverTapSDK/CleverTapInstanceConfig.h @@ -16,7 +16,7 @@ @property (nonatomic, assign) BOOL useCustomCleverTapId; @property (nonatomic, assign) BOOL disableIDFV; @property (nonatomic, assign) BOOL enableFileProtection; -@property (nonatomic, strong, readonly, nullable) NSString *handshakeDomain; +@property (nonatomic, strong, nullable) NSString *handshakeDomain; @property (nonatomic, assign) CleverTapLogLevel logLevel; @property (nonatomic, strong, nullable) NSArray *identityKeys; From cd49f2a07117980a8a1bc602064a0e35b21d0206 Mon Sep 17 00:00:00 2001 From: Akash Malhotra Date: Thu, 10 Oct 2024 10:09:01 +0530 Subject: [PATCH 13/14] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c343c4d9..9454e70b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Change Log All notable changes to this project will be documented in this file. -### [Version 7.0.2](https://github.com/CleverTap/clevertap-ios-sdk/releases/tag/7.0.2) (October 09, 2024) +### [Version 7.0.2](https://github.com/CleverTap/clevertap-ios-sdk/releases/tag/7.0.2) (October 10, 2024) #### Added - Adds support for custom handshake domains. From ab8e4f658dab76af30ed63397861ada2d78c0de3 Mon Sep 17 00:00:00 2001 From: Akash Malhotra Date: Thu, 10 Oct 2024 10:11:31 +0530 Subject: [PATCH 14/14] removed a stray file --- CleverTapSDKTests/CTDomainFactory+Tests.m | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 CleverTapSDKTests/CTDomainFactory+Tests.m diff --git a/CleverTapSDKTests/CTDomainFactory+Tests.m b/CleverTapSDKTests/CTDomainFactory+Tests.m deleted file mode 100644 index c2991fa5..00000000 --- a/CleverTapSDKTests/CTDomainFactory+Tests.m +++ /dev/null @@ -1,13 +0,0 @@ -// -// CTDomainFactory+Tests.m -// CleverTapSDKTests -// -// Created by Akash Malhotra on 12/09/24. -// Copyright © 2024 CleverTap. All rights reserved. -// - -#import "CTDomainFactory+Tests.h" - -@implementation CTDomainFactory (Tests) - -@end