Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding activity_id #1159

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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