Skip to content

Commit e4398e5

Browse files
authored
expose vars json and vars signature (#438)
* exposing secured vars (vars json and vars signature) * fix unit tests * fix for spm * added docs and mark method result as nullable
1 parent f168f1f commit e4398e5

File tree

19 files changed

+328
-26
lines changed

19 files changed

+328
-26
lines changed

Example/Leanplum-SDK.xcodeproj/project.pbxproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@
120120
B449EB2A21F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json in Resources */ = {isa = PBXBuildFile; fileRef = B449EB2921F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json */; };
121121
B449EB2B21F27B0B005C93B6 /* TiedPrioritiesDifferentDelay.json in Resources */ = {isa = PBXBuildFile; fileRef = B449EB2921F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json */; };
122122
BDCD1DC844A474BCC4BD5971 /* Pods_Leanplum_SDK_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D838E08C49B78EF6BAA262C1 /* Pods_Leanplum_SDK_Tests.framework */; };
123+
C9AC35AD266D6185008337F2 /* LPSecuredVarsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = C9AC35AC266D6185008337F2 /* LPSecuredVarsTest.m */; };
124+
C9AC35B1266D620C008337F2 /* secured_vars_response.json in Resources */ = {isa = PBXBuildFile; fileRef = C9AC35B0266D620C008337F2 /* secured_vars_response.json */; };
125+
C9AC35B2266D620C008337F2 /* secured_vars_response.json in Resources */ = {isa = PBXBuildFile; fileRef = C9AC35B0266D620C008337F2 /* secured_vars_response.json */; };
126+
C9AC35B6266D624A008337F2 /* secured_vars_no_sign_response.json in Resources */ = {isa = PBXBuildFile; fileRef = C9AC35B5266D624A008337F2 /* secured_vars_no_sign_response.json */; };
127+
C9AC35B7266D624A008337F2 /* secured_vars_no_sign_response.json in Resources */ = {isa = PBXBuildFile; fileRef = C9AC35B5266D624A008337F2 /* secured_vars_no_sign_response.json */; };
128+
C9AC35BB266D62A1008337F2 /* secured_vars_empty_response.json in Resources */ = {isa = PBXBuildFile; fileRef = C9AC35BA266D62A1008337F2 /* secured_vars_empty_response.json */; };
129+
C9AC35BC266D62A1008337F2 /* secured_vars_empty_response.json in Resources */ = {isa = PBXBuildFile; fileRef = C9AC35BA266D62A1008337F2 /* secured_vars_empty_response.json */; };
123130
C9C0C87025898CE900346291 /* LPRequestBatchTest.m in Sources */ = {isa = PBXBuildFile; fileRef = C9C0C86F25898CE900346291 /* LPRequestBatchTest.m */; };
124131
C9C0C87425898D0100346291 /* LPRequestSenderTimerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = C9C0C87325898D0100346291 /* LPRequestSenderTimerTest.m */; };
125132
E773031E24AB871E00EDF983 /* Leanplum-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = E773031D24AB871E00EDF983 /* Leanplum-Info.plist */; };
@@ -249,6 +256,10 @@
249256
B5CCCA351D74B64D005ADEE1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
250257
B5CCCA371D74B64D005ADEE1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
251258
B5CCCA391D74B64D005ADEE1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
259+
C9AC35AC266D6185008337F2 /* LPSecuredVarsTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPSecuredVarsTest.m; sourceTree = "<group>"; };
260+
C9AC35B0266D620C008337F2 /* secured_vars_response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = secured_vars_response.json; sourceTree = "<group>"; };
261+
C9AC35B5266D624A008337F2 /* secured_vars_no_sign_response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = secured_vars_no_sign_response.json; sourceTree = "<group>"; };
262+
C9AC35BA266D62A1008337F2 /* secured_vars_empty_response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = secured_vars_empty_response.json; sourceTree = "<group>"; };
252263
C9C0C86F25898CE900346291 /* LPRequestBatchTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPRequestBatchTest.m; sourceTree = "<group>"; };
253264
C9C0C87325898D0100346291 /* LPRequestSenderTimerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPRequestSenderTimerTest.m; sourceTree = "<group>"; };
254265
D838E08C49B78EF6BAA262C1 /* Pods_Leanplum_SDK_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Leanplum_SDK_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -315,6 +326,7 @@
315326
9E53F6E0247438440097955F /* LPPushNotificationsManagerTest.m */,
316327
9E53F6E22474387B0097955F /* LPPushNotificationsHandlerTest.m */,
317328
6A7815E224F6A89C004F3DC7 /* LPDeferMessageManagerTest.m */,
329+
C9AC35AC266D6185008337F2 /* LPSecuredVarsTest.m */,
318330
);
319331
path = Classes;
320332
sourceTree = "<group>";
@@ -388,6 +400,9 @@
388400
07E5C89E1F052B7800A4B092 /* track_event_response.json */,
389401
07E5C89F1F052B7800A4B092 /* variables_response.json */,
390402
9CD04D931F8EB6190033AB4A /* variables_with_newsfeed_response.json */,
403+
C9AC35B0266D620C008337F2 /* secured_vars_response.json */,
404+
C9AC35B5266D624A008337F2 /* secured_vars_no_sign_response.json */,
405+
C9AC35BA266D62A1008337F2 /* secured_vars_empty_response.json */,
391406
);
392407
path = Responses;
393408
sourceTree = "<group>";
@@ -655,6 +670,7 @@
655670
07E5C8DF1F052DC400A4B092 /* registration_response.json in Resources */,
656671
9CD04D951F8EE7E30033AB4A /* variables_with_newsfeed_response.json in Resources */,
657672
9CB691DF1F15FFFF002D83D8 /* batch_response.json in Resources */,
673+
C9AC35B1266D620C008337F2 /* secured_vars_response.json in Resources */,
658674
07E5C8EA1F052DCC00A4B092 /* MainAppIcon.png in Resources */,
659675
07E5C8E21F052DC400A4B092 /* start_variables_response.json in Resources */,
660676
07E5C8E71F052DC700A4B092 /* malformed_simple_start_response.json in Resources */,
@@ -663,6 +679,7 @@
663679
07E5C8F21F052DD000A4B092 /* regionData.json in Resources */,
664680
07E5C8F01F052DD000A4B092 /* DifferentPrioritiesWithMissingValues.json in Resources */,
665681
6003F5A9195388D20070C39A /* Images.xcassets in Resources */,
682+
C9AC35B6266D624A008337F2 /* secured_vars_no_sign_response.json in Resources */,
666683
07E5C8EB1F052DCC00A4B092 /* test.file in Resources */,
667684
E773031E24AB871E00EDF983 /* Leanplum-Info.plist in Resources */,
668685
07E5C8E81F052DC700A4B092 /* malformed_track_event_response.json in Resources */,
@@ -677,6 +694,7 @@
677694
07E5C8EF1F052DD000A4B092 /* DifferentPriorities2.json in Resources */,
678695
07E5C8E61F052DC400A4B092 /* variables_response.json in Resources */,
679696
07E5C8E11F052DC400A4B092 /* simple_start_response.json in Resources */,
697+
C9AC35BB266D62A1008337F2 /* secured_vars_empty_response.json in Resources */,
680698
B449EB2A21F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json in Resources */,
681699
07E5C8F41F052DD000A4B092 /* SingleMessage.json in Resources */,
682700
07E5C8EC1F052DCC00A4B092 /* test.pdf in Resources */,
@@ -705,10 +723,13 @@
705723
07E5C8D81F052B7800A4B092 /* SingleMessage.json in Resources */,
706724
B449EB2B21F27B0B005C93B6 /* TiedPrioritiesDifferentDelay.json in Resources */,
707725
07E5C8CB1F052B7800A4B092 /* simple_start_response.json in Resources */,
726+
C9AC35B7266D624A008337F2 /* secured_vars_no_sign_response.json in Resources */,
708727
9CD04D941F8EE7E30033AB4A /* variables_with_newsfeed_response.json in Resources */,
709728
07E5C8C01F052B7800A4B092 /* MainAppIcon.png in Resources */,
710729
07E5C8C11F052B7800A4B092 /* test.file in Resources */,
730+
C9AC35BC266D62A1008337F2 /* secured_vars_empty_response.json in Resources */,
711731
07E5C8CF1F052B7800A4B092 /* track_event_response.json in Resources */,
732+
C9AC35B2266D620C008337F2 /* secured_vars_response.json in Resources */,
712733
07E5C8D01F052B7800A4B092 /* variables_response.json in Resources */,
713734
07E5C8CD1F052B7800A4B092 /* state_response.json in Resources */,
714735
07E5C8D91F052B7800A4B092 /* TiedPriorities1.json in Resources */,
@@ -841,6 +862,7 @@
841862
A86C8D02240844C7003F5E4E /* LPConfirmMessageSnapshotTest.m in Sources */,
842863
07E5C8B11F052B7800A4B092 /* LPNetworkEngine+Category.m in Sources */,
843864
6AFFF5CB24BE0960009E68DB /* LPWebInterstitialViewControllerTest.m in Sources */,
865+
C9AC35AD266D6185008337F2 /* LPSecuredVarsTest.m in Sources */,
844866
07E5C8B61F052B7800A4B092 /* LeanplumTest.m in Sources */,
845867
9E53F6E1247438440097955F /* LPPushNotificationsManagerTest.m in Sources */,
846868
A824579A2411CB600044B1EB /* LPWebInterstitialMessageSnapshotTest.m in Sources */,

Example/Tests/Classes/LPActionContextTest.m

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ - (void)setUp {
3838
messages:nil
3939
variants:nil
4040
regions:nil
41-
variantDebugInfo:nil];
41+
variantDebugInfo:nil
42+
varsJson:nil
43+
varsSignature:nil];
4244
[[LPVarCache sharedCache] registerActionDefinition:@"action" ofKind:0 withArguments:@[] andOptions:@{}];
4345
}
4446

@@ -61,7 +63,9 @@ - (void)test_setProperArgs_messageWithArgs {
6163
messages:messages
6264
variants:nil
6365
regions:nil
64-
variantDebugInfo:nil];
66+
variantDebugInfo:nil
67+
varsJson:nil
68+
varsSignature:nil];
6569

6670
// set args from the message in the cache
6771
[context setProperArgs];
@@ -84,7 +88,9 @@ - (void)test_setProperArgs_messageWithNilArgs {
8488
messages:messages
8589
variants:nil
8690
regions:nil
87-
variantDebugInfo:nil];
91+
variantDebugInfo:nil
92+
varsJson:nil
93+
varsSignature:nil];
8894

8995
// set nil args from the message in the cache
9096
[context setProperArgs];
@@ -105,7 +111,9 @@ - (void)test_setProperArgs_noMessage {
105111
messages:messages
106112
variants:nil
107113
regions:nil
108-
variantDebugInfo:nil];
114+
variantDebugInfo:nil
115+
varsJson:nil
116+
varsSignature:nil];
109117

110118
// no message in cache, args should not be set
111119
[context setProperArgs];
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#import <XCTest/XCTest.h>
2+
#import <OCMock/OCMock.h>
3+
#import <OHHTTPStubs/HTTPStubs.h>
4+
#import <OHHTTPStubs/HTTPStubsPathHelpers.h>
5+
#import "LeanplumHelper.h"
6+
#import "Leanplum+Extensions.h"
7+
8+
@interface LPSecuredVarsTest : XCTestCase
9+
10+
@end
11+
12+
@implementation LPSecuredVarsTest
13+
14+
- (void)setUp {
15+
// Put setup code here. This method is called before the invocation of each test method in the class.
16+
}
17+
18+
- (void)tearDown
19+
{
20+
[super tearDown];
21+
[LeanplumHelper clean_up];
22+
}
23+
24+
- (void)testVarsAndSignature {
25+
// This stub have to be removed when start command is successfully executed.
26+
id<HTTPStubsDescriptor> startStub = [HTTPStubs stubRequestsPassingTest:
27+
^BOOL(NSURLRequest * _Nonnull request) {
28+
return [request.URL.host isEqualToString:API_HOST];
29+
} withStubResponse:^HTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
30+
NSString *response_file = OHPathForFile(@"secured_vars_response.json", self.class);
31+
return [HTTPStubsResponse responseWithFileAtPath:response_file statusCode:200
32+
headers:@{@"Content-Type":@"application/json"}];
33+
}];
34+
35+
[Leanplum startWithResponseHandler:^(BOOL success) {
36+
[HTTPStubs removeStub:startStub];
37+
LPSecuredVars *securedVars = [[LPVarCache sharedCache] securedVars];
38+
39+
XCTAssertTrue([[securedVars varsJson] containsString:@"intVariable"]);
40+
XCTAssertTrue([[securedVars varsJson] containsString:@"stringVariable"]);
41+
42+
XCTAssertTrue([[securedVars varsSignature] containsString:@"sign_of_vars"]);
43+
}];
44+
}
45+
46+
- (void)testVarsNoSignature {
47+
// This stub have to be removed when start command is successfully executed.
48+
id<HTTPStubsDescriptor> startStub = [HTTPStubs stubRequestsPassingTest:
49+
^BOOL(NSURLRequest * _Nonnull request) {
50+
return [request.URL.host isEqualToString:API_HOST];
51+
} withStubResponse:^HTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
52+
NSString *response_file = OHPathForFile(@"secured_vars_no_sign_response.json", self.class);
53+
return [HTTPStubsResponse responseWithFileAtPath:response_file statusCode:200
54+
headers:@{@"Content-Type":@"application/json"}];
55+
}];
56+
57+
[Leanplum startWithResponseHandler:^(BOOL success) {
58+
[HTTPStubs removeStub:startStub];
59+
60+
LPSecuredVars *securedVars = [[LPVarCache sharedCache] securedVars];
61+
62+
XCTAssertNil(securedVars);
63+
}];
64+
}
65+
66+
- (void)testEmptyVarsNoSignature {
67+
// This stub have to be removed when start command is successfully executed.
68+
id<HTTPStubsDescriptor> startStub = [HTTPStubs stubRequestsPassingTest:
69+
^BOOL(NSURLRequest * _Nonnull request) {
70+
return [request.URL.host isEqualToString:API_HOST];
71+
} withStubResponse:^HTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
72+
NSString *response_file = OHPathForFile(@"secured_vars_empty_response.json", self.class);
73+
return [HTTPStubsResponse responseWithFileAtPath:response_file statusCode:200
74+
headers:@{@"Content-Type":@"application/json"}];
75+
}];
76+
77+
[Leanplum startWithResponseHandler:^(BOOL success) {
78+
[HTTPStubs removeStub:startStub];
79+
80+
LPSecuredVars *securedVars = [[LPVarCache sharedCache] securedVars];
81+
82+
XCTAssertNil(securedVars);
83+
}];
84+
}
85+
86+
@end

Example/Tests/Classes/LeanplumTest.m

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,12 @@ - (void) test_failed_start_triggers
904904

905905
NSDictionary *messages = startResponse[LP_KEY_MESSAGES];
906906
[[LPVarCache sharedCache] applyVariableDiffs:nil
907-
messages:messages
908-
variants:nil
909-
regions:nil
910-
variantDebugInfo:nil];
907+
messages:messages
908+
variants:nil
909+
regions:nil
910+
variantDebugInfo:nil
911+
varsJson:nil
912+
varsSignature:nil];
911913

912914
[HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest * _Nonnull request) {
913915
return [request.URL.host isEqualToString:API_HOST];
@@ -1461,7 +1463,7 @@ - (void)test_variables
14611463
@"myArray": @{
14621464
@"[2]": @33
14631465
}
1464-
} messages:nil variants:nil regions:nil variantDebugInfo:nil];
1466+
} messages:nil variants:nil regions:nil variantDebugInfo:nil varsJson:nil varsSignature:nil];
14651467

14661468

14671469
XCTestExpectation *request_expectation =
@@ -1788,7 +1790,9 @@ - (void)test_metadata
17881790
messages:messages
17891791
variants:variants
17901792
regions:nil
1791-
variantDebugInfo:nil];
1793+
variantDebugInfo:nil
1794+
varsJson:nil
1795+
varsSignature:nil];
17921796

17931797
XCTAssertEqualObjects(variants, [Leanplum variants]);
17941798
XCTAssertEqualObjects(messages, [Leanplum messageMetadata]);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"response": [
3+
{
4+
"regions": {},
5+
"fileAttributes": {},
6+
"success": true,
7+
"messages": {},
8+
"vars": {},
9+
"variants": [],
10+
"token": "juKUmiXERlO4kmTfEL6xEsfUMpg9WUlFrHOvp6H2w4Q"
11+
}
12+
]
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"response": [
3+
{
4+
"regions": {},
5+
"fileAttributes": {},
6+
"success": true,
7+
"messages": {},
8+
"vars": {
9+
"intVariable": 100,
10+
"stringVariable": "test_string"
11+
},
12+
"variants": [],
13+
"token": "juKUmiXERlO4kmTfEL6xEsfUMpg9WUlFrHOvp6H2w4Q"
14+
}
15+
]
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"response": [
3+
{
4+
"regions": {},
5+
"fileAttributes": {},
6+
"success": true,
7+
"messages": {},
8+
"vars": {
9+
"intVariable": 100,
10+
"stringVariable": "test_string"
11+
},
12+
"varsSignature": "sign_of_vars",
13+
"variants": [],
14+
"token": "juKUmiXERlO4kmTfEL6xEsfUMpg9WUlFrHOvp6H2w4Q"
15+
}
16+
]
17+
}

0 commit comments

Comments
 (0)