Skip to content

Commit 0a1248e

Browse files
committed
App_id in url check
1 parent 25c811a commit 0a1248e

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OSRequests.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ + (instancetype)withUserId:(NSString *)userId appId:(NSString *)appId {
7272

7373
return request;
7474
}
75-
76-
-(BOOL)missingAppId {
77-
return false; //this request doesn't have an app ID parameter
78-
}
7975
@end
8076

8177
@implementation OSRequestSendTagsToServer

iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalRequest.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ -(NSMutableURLRequest *)urlRequest {
9191
}
9292

9393
-(BOOL)missingAppId {
94-
return self.parameters[@"app_id"] == nil || [self.parameters[@"app_id"] length] == 0;
94+
if ([self.path containsString:@"apps/"]) {
95+
NSArray *pathComponents = [self.path componentsSeparatedByString:@"/"];
96+
NSUInteger x = [pathComponents indexOfObject:@"apps"] + 1; // Find the index that follows "apps" in the path
97+
return ([pathComponents count] <= x || [[pathComponents objectAtIndex:x] length] == 0 || [[pathComponents objectAtIndex:x] isEqual: @"(null)"]);
98+
}
99+
100+
return (self.parameters[@"app_id"] == nil || [self.parameters[@"app_id"] length] == 0);
95101
}
96102

97103
-(void)attachBodyToRequest:(NSMutableURLRequest *)request withParameters:(NSDictionary *)parameters {

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserInternalImpl.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class OSUserInternalImpl: NSObject, OSUserInternal {
7575
pushSubscriptionModel = OSSubscriptionModel(type: .push, address: token, subscriptionId: subscriptionId, accepted: true, isDisabled: false, changeNotifier: OSEventProducer())
7676
print("🔥 OSUserInternalImpl has set pushSubcription for testing")
7777
return pushSubscriptionModel
78-
7978
}
8079

8180
init(identityModel: OSIdentityModel, propertiesModel: OSPropertiesModel, pushSubscriptionModel: OSSubscriptionModel) {

iOS_SDK/OneSignalSDK/UnitTests/Shadows/OneSignalClientOverrider.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,15 @@ + (void)finishExecutingRequest:(OneSignalRequest *)request onSuccess:(OSResultSu
214214

215215
NSMutableDictionary *parameters = [request.parameters mutableCopy];
216216

217-
if (!parameters[@"app_id"] && ![request.urlRequest.URL.absoluteString containsString:@"/apps/"])
218-
_XCTPrimitiveFail(currentTestInstance, @"All request should include an app_id");
217+
if ([request.urlRequest.URL.absoluteString containsString:@"apps/"]) {
218+
NSArray *pathComponents = [request.urlRequest.URL.absoluteString componentsSeparatedByString:@"/"];
219+
NSUInteger x = [pathComponents indexOfObject:@"apps"] + 1; // Find the index that follows "apps" in the path
220+
if ([pathComponents count] <= x || [[pathComponents objectAtIndex:x] length] == 0 || [[pathComponents objectAtIndex:x] isEqual: @"(null)"]) {
221+
_XCTPrimitiveFail(currentTestInstance, @"All request must include an app_id");
222+
}
223+
} else if (!parameters[@"app_id"]) {
224+
_XCTPrimitiveFail(currentTestInstance, @"All request must include an app_id");
225+
}
219226

220227
[self didCompleteRequest:request];
221228

0 commit comments

Comments
 (0)