Skip to content

Commit

Permalink
Merge pull request #1159 from OneSignal/activity_id-encoded
Browse files Browse the repository at this point in the history
encoding activity_id
  • Loading branch information
fhboswell authored Nov 21, 2022
2 parents ddc14cc + a401093 commit 88218bc
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
11 changes: 9 additions & 2 deletions iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OSRequests.m
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,10 @@ + (instancetype)withUserId:(NSString * _Nonnull)userId
params[@"device_type"] = @0;
request.parameters = params;
request.method = POST;
request.path = [NSString stringWithFormat:@"apps/%@/live_activities/%@/token", appId, activityId];

NSString *urlSafeActivityId = [activityId stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLUserAllowedCharacterSet]];

request.path = [NSString stringWithFormat:@"apps/%@/live_activities/%@/token", appId, urlSafeActivityId];
return request;
}
@end
Expand All @@ -516,7 +519,11 @@ + (instancetype)withUserId:(NSString * _Nonnull)userId
activityId:(NSString * _Nonnull)activityId {
let request = [OSRequestLiveActivityExit new];
request.method = DELETE;
request.path = [NSString stringWithFormat:@"apps/%@/live_activities/%@/token/%@", appId, activityId, userId];

NSString *urlSafeActivityId = [activityId stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLUserAllowedCharacterSet]];

request.path = [NSString stringWithFormat:@"apps/%@/live_activities/%@/token/%@", appId, urlSafeActivityId, userId];

return request;
}
@end
55 changes: 55 additions & 0 deletions iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -3532,6 +3532,61 @@ - (void)testExitLiveActivity {
XCTAssertEqualObjects(OneSignalClientOverrider.lastUrl, testExitLiveActivityCorrectURL);

}

- (void)testExitLiveActivityURLUnsafeSpace {

NSString *testAppId = @"b2f7f966-d8cc-11e4-bed1-df8f05be55ba";
NSString *testLiveActivityURLUnsafe = @"onesignal 01012022";
NSString *testLiveActivityURLSafe = @"onesignal%2001012022";
NSString *testUserId = @"1234";

[UnitTestCommonMethods initOneSignal_andThreadWait];

[OneSignal exitLiveActivity:testLiveActivityURLUnsafe
withSuccess:nil
withFailure:nil];

[UnitTestCommonMethods runBackgroundThreads];

//check to make sure the OSRequestExitLiveActivity HTTP call was made, and was formatted correctly
XCTAssertTrue([NSStringFromClass([OSRequestLiveActivityExit class]) isEqualToString:OneSignalClientOverrider.lastHTTPRequestType]);

let testExitLiveActivityCorrectURL = [NSString stringWithFormat:@"https://api.onesignal.com/apps/%@/live_activities/%@/token/%@",
testAppId,
testLiveActivityURLSafe,
testUserId];

XCTAssertEqualObjects(OneSignalClientOverrider.lastUrl, testExitLiveActivityCorrectURL);

}

- (void)testExitLiveActivityURLUnsafeSlash {

NSString *testAppId = @"b2f7f966-d8cc-11e4-bed1-df8f05be55ba";
NSString *testLiveActivityURLUnsafe = @"onesignal/01012022";
NSString *testLiveActivityURLSafe = @"onesignal%2F01012022";
NSString *testUserId = @"1234";

[UnitTestCommonMethods initOneSignal_andThreadWait];

[OneSignal exitLiveActivity:testLiveActivityURLUnsafe
withSuccess:nil
withFailure:nil];

[UnitTestCommonMethods runBackgroundThreads];

//check to make sure the OSRequestExitLiveActivity HTTP call was made, and was formatted correctly
XCTAssertTrue([NSStringFromClass([OSRequestLiveActivityExit class]) isEqualToString:OneSignalClientOverrider.lastHTTPRequestType]);

let testExitLiveActivityCorrectURL = [NSString stringWithFormat:@"https://api.onesignal.com/apps/%@/live_activities/%@/token/%@",
testAppId,
testLiveActivityURLSafe,
testUserId];

XCTAssertEqualObjects(OneSignalClientOverrider.lastUrl, testExitLiveActivityCorrectURL);

}

- (void)testExitLiveActivityEarly {

NSString *testAppId = @"b2f7f966-d8cc-11e4-bed1-df8f05be55ba";
Expand Down

0 comments on commit 88218bc

Please sign in to comment.