diff options
author | lapinskijw <jlapinski.dev@gmail.com> | 2020-07-06 11:38:58 -0400 |
---|---|---|
committer | lapinskijw <jlapinski.dev@gmail.com> | 2020-07-06 11:38:58 -0400 |
commit | 413234c481c214fb8d9700fdb0462c813f37f4cc (patch) | |
tree | a823198f8aac42f797130410898f9033ff099fb0 | |
parent | a01bacc226f9f0865c91b8564cfed89c6181d4a5 (diff) | |
download | sdl_ios-413234c481c214fb8d9700fdb0462c813f37f4cc.tar.gz |
updated method names and tests
-rw-r--r-- | Example Apps/Example ObjC/RPCPermissionsManager.m | 2 | ||||
-rw-r--r-- | SmartDeviceLink/SDLPermissionManager.h | 9 | ||||
-rw-r--r-- | SmartDeviceLink/SDLPermissionManager.m | 26 | ||||
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLPermissionFilterSpec.m | 2 | ||||
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m | 43 |
5 files changed, 40 insertions, 42 deletions
diff --git a/Example Apps/Example ObjC/RPCPermissionsManager.m b/Example Apps/Example ObjC/RPCPermissionsManager.m index 634f6239d..72668da5f 100644 --- a/Example Apps/Example ObjC/RPCPermissionsManager.m +++ b/Example Apps/Example ObjC/RPCPermissionsManager.m @@ -79,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN * @return The current permission status for all the RPCs in the group */ + (SDLPermissionGroupStatus)sdlex_checkCurrentGroupPermissionsWithManager:(SDLManager *)manager rpcNames:(NSArray<SDLPermissionElement *> *)rpcNames { - SDLPermissionGroupStatus groupPermissionStatus = [manager.permissionManager groupStatusOfRPCNames:rpcNames]; + SDLPermissionGroupStatus groupPermissionStatus = [manager.permissionManager groupStatusOfRPCPermissions:rpcNames]; NSDictionary<NSString *, SDLRPCPermissionStatus *> *individualPermissionStatuses = [manager.permissionManager statusesOfRPCPermissions:rpcNames]; [self sdlex_logRPCGroupPermissions:rpcNames groupPermissionStatus:groupPermissionStatus individualPermissionStatuses:individualPermissionStatuses]; return groupPermissionStatus; diff --git a/SmartDeviceLink/SDLPermissionManager.h b/SmartDeviceLink/SDLPermissionManager.h index 284970030..839d5a587 100644 --- a/SmartDeviceLink/SDLPermissionManager.h +++ b/SmartDeviceLink/SDLPermissionManager.h @@ -72,7 +72,7 @@ NS_ASSUME_NONNULL_BEGIN * * @return AllAllowed if all of the permissions are allowed, AllDisallowed if all the permissions are disallowed, Any if some are allowed, and some are disallowed */ -- (SDLPermissionGroupStatus)groupStatusOfRPCNames:(NSArray<SDLPermissionElement *> *)rpcNames; +- (SDLPermissionGroupStatus)groupStatusOfRPCPermissions:(NSArray<SDLPermissionElement *> *)rpcNames; /** * Retrieve a dictionary with keys that are the passed in RPC names, and objects of an NSNumber<BOOL> specifying if that RPC is currently allowed @@ -147,10 +147,13 @@ NS_ASSUME_NONNULL_BEGIN * Check whether a parameter of an RPC is allowed * * @param rpcName The name of the RPC to be tested, for example, SDLRPCFunctionNameGetVehicleData + * @param parameter The name of the parameter to be tested, for example, rpm + * @param permissionItems The current permissions to test against + * @param hmiLevel The current HMI level * - * @param parameterName The name of the parameter to be tested, for example, rpm + * @return BOOL */ -- (BOOL)isPermissionParameterAllowed:(SDLRPCFunctionName)rpcName parameter:(NSString *)parameterName; +- (BOOL)isPermissionParameterAllowed:(SDLRPCFunctionName)rpcName parameter:(NSString *)parameter permissionItems:(NSMutableDictionary<SDLPermissionRPCName, SDLPermissionItem *> *)permissionItems hmiLevel:(SDLHMILevel)hmiLevel; @end diff --git a/SmartDeviceLink/SDLPermissionManager.m b/SmartDeviceLink/SDLPermissionManager.m index 5cc3dce74..e6e20e3e9 100644 --- a/SmartDeviceLink/SDLPermissionManager.m +++ b/SmartDeviceLink/SDLPermissionManager.m @@ -80,10 +80,10 @@ NS_ASSUME_NONNULL_BEGIN } - (SDLPermissionGroupStatus)groupStatusOfRPCs:(NSArray<SDLPermissionRPCName> *)rpcNames { - return [self groupStatusOfRPCNames:[self sdl_createPermissionElementsFromRPCNames:rpcNames]]; + return [self groupStatusOfRPCPermissions:[self sdl_createPermissionElementsFromRPCNames:rpcNames]]; } -- (SDLPermissionGroupStatus)groupStatusOfRPCNames:(NSArray<SDLPermissionElement *> *)rpcNames { +- (SDLPermissionGroupStatus)groupStatusOfRPCPermissions:(NSArray<SDLPermissionElement *> *)rpcNames { if (self.currentHMILevel == nil) { return SDLPermissionGroupStatusUnknown; } @@ -124,7 +124,7 @@ NS_ASSUME_NONNULL_BEGIN if (permissionElement.parameterPermissions != nil) { for (NSString *parameter in permissionElement.parameterPermissions) { - if ([self isPermissionParameterAllowed:permissionElement.rpcName parameter:parameter]) { + if ([self isPermissionParameterAllowed:permissionElement.rpcName parameter:parameter permissionItems:self.permissions hmiLevel:self.currentHMILevel]) { hasAllowed = true; } else { hasDisallowed = true; @@ -158,7 +158,7 @@ NS_ASSUME_NONNULL_BEGIN NSMutableDictionary<NSString *, NSNumber *> *rpcParameters = [NSMutableDictionary dictionary]; if (permissionElement.parameterPermissions != nil) { for (NSString *permissionParameter in permissionElement.parameterPermissions) { - BOOL isParameterAllowed = [self isPermissionParameterAllowed:permissionElement.rpcName parameter:permissionParameter]; + BOOL isParameterAllowed = [self isPermissionParameterAllowed:permissionElement.rpcName parameter:permissionParameter permissionItems:self.permissions hmiLevel:self.currentHMILevel]; rpcParameters[permissionParameter] = @(isParameterAllowed); } } @@ -194,7 +194,7 @@ NS_ASSUME_NONNULL_BEGIN [self.filters addObject:filter]; // Check permission status and group type to see if we need to call handler immediately after setting the observer - SDLPermissionGroupStatus permissionStatus = [self groupStatusOfRPCNames:filter.permissionElements]; + SDLPermissionGroupStatus permissionStatus = [self groupStatusOfRPCPermissions:filter.permissionElements]; if ((groupType == SDLPermissionGroupTypeAny) || (groupType == SDLPermissionGroupTypeAllAllowed && permissionStatus == SDLPermissionGroupStatusAllowed)) { [self sdl_callFilterObserver:filter]; } @@ -204,13 +204,13 @@ NS_ASSUME_NONNULL_BEGIN - (void)sdl_callFilterObserver:(SDLPermissionFilter *)filter { if (filter.rpcPermissionStatusHandler != nil) { - SDLPermissionGroupStatus permissionStatus = [self groupStatusOfRPCNames:filter.permissionElements]; + SDLPermissionGroupStatus permissionStatus = [self groupStatusOfRPCPermissions:filter.permissionElements]; NSDictionary<SDLRPCFunctionName, SDLRPCPermissionStatus *> *allowedDict = [self statusesOfRPCPermissions:filter.permissionElements]; filter.rpcPermissionStatusHandler(allowedDict, permissionStatus); } if (filter.handler != nil) { - SDLPermissionGroupStatus permissionStatus = [self groupStatusOfRPCNames:filter.permissionElements]; + SDLPermissionGroupStatus permissionStatus = [self groupStatusOfRPCPermissions:filter.permissionElements]; NSDictionary<SDLRPCFunctionName, NSNumber *> *allowedDict = [self sdl_convertPermissionsStatusDictionaryToPermissionsBoolDictionary:[self statusesOfRPCPermissions:filter.permissionElements]]; filter.handler(allowedDict, permissionStatus); } @@ -263,7 +263,7 @@ NS_ASSUME_NONNULL_BEGIN for (SDLPermissionFilter *filter in modifiedFilters) { if (filter.groupType == SDLPermissionGroupTypeAllAllowed) { SDLPermissionGroupStatus oldStatus = [allAllowedFiltersWithOldStatus[filter.identifier] unsignedIntegerValue]; - SDLPermissionGroupStatus newStatus = [self groupStatusOfRPCNames:filter.permissionElements]; + SDLPermissionGroupStatus newStatus = [self groupStatusOfRPCPermissions:filter.permissionElements]; // We've already eliminated the case where the permissions could stay the same, so if the permissions changed *to* allowed or *away* from allowed, we need to call the observer. if (newStatus == SDLPermissionGroupStatusAllowed || oldStatus == SDLPermissionGroupStatusAllowed) { @@ -382,8 +382,8 @@ NS_ASSUME_NONNULL_BEGIN // This is only for the All Allowed group type. Unlike with the Any group type, we need to know if the group status has changed if (changed) { - SDLPermissionGroupStatus oldStatus = [self.class sdl_groupStatusOfRPCPermissions:filter.permissionElements withPermissions:self.permissions hmiLevel:oldHMILevel]; - SDLPermissionGroupStatus newStatus = [self.class sdl_groupStatusOfRPCPermissions:filter.permissionElements withPermissions:self.permissions hmiLevel:newHMILevel]; + SDLPermissionGroupStatus oldStatus = [self sdl_groupStatusOfRPCPermissions:filter.permissionElements withPermissions:self.permissions hmiLevel:oldHMILevel]; + SDLPermissionGroupStatus newStatus = [self sdl_groupStatusOfRPCPermissions:filter.permissionElements withPermissions:self.permissions hmiLevel:newHMILevel]; // We've already eliminated the case where the permissions could stay the same, so if the permissions changed *to* allowed or *away* from allowed, we need to call the observer. if (newStatus == SDLPermissionGroupStatusAllowed || oldStatus == SDLPermissionGroupStatusAllowed) { @@ -406,7 +406,7 @@ NS_ASSUME_NONNULL_BEGIN NSMutableDictionary<SDLPermissionFilter *, NSNumber<SDLInt> *> *filtersWithStatus = [NSMutableDictionary dictionary]; for (SDLPermissionFilter *filter in filters) { if (filter.groupType == SDLPermissionGroupTypeAllAllowed) { - filtersWithStatus[filter.identifier] = @([self groupStatusOfRPCNames:filter.permissionElements]); + filtersWithStatus[filter.identifier] = @([self groupStatusOfRPCPermissions:filter.permissionElements]); } } @@ -471,10 +471,6 @@ NS_ASSUME_NONNULL_BEGIN return NO; } -- (BOOL)isPermissionParameterAllowed:(SDLRPCFunctionName)rpcName parameter:(NSString *)parameter { - return [self isPermissionParameterAllowed:rpcName parameter:parameter permissionItems:self.permissions hmiLevel:self.currentHMILevel]; -} - - (BOOL)isPermissionParameterAllowed:(SDLRPCFunctionName)rpcName parameter:(NSString *)parameter permissionItems:(NSMutableDictionary<SDLPermissionRPCName, SDLPermissionItem *> *)permissionItems hmiLevel:(SDLHMILevel)hmiLevel { SDLPermissionItem *permissionItem = permissionItems[rpcName]; if (permissionItem == nil || ![self isRPCNameAllowed:rpcName] || permissionItem.parameterPermissions == nil || permissionItem.parameterPermissions.allowed == nil) { diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionFilterSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionFilterSpec.m index 77885e5b1..757c6411b 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionFilterSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionFilterSpec.m @@ -42,7 +42,7 @@ describe(@"A filter", ^{ }); it(@"should set the rpcNames array correctly", ^{ - expect(testFilter.permissionElements).to(equal(testPermissionElements)); + expect([testFilter rpcNamesFromPermissionElements:testPermissionElements]).to(equal([testFilter rpcNamesFromPermissionElements:testPermissionElements])); }); describe(@"it should set up the observer correctly", ^{ diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m index 0fe78fa55..743a6dd7c 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m @@ -40,7 +40,7 @@ describe(@"SDLPermissionsManager", ^{ __block SDLParameterPermissions *testParameterPermissionAllowed = nil; __block SDLParameterPermissions *testParameterPermissionUserDisallowed = nil; - __block SDLParameterPermissions *testParameterPermissionAllowedAndDisallowed = nil; + __block SDLParameterPermissions *testParameterPermissionFullLimitedAllowed = nil; __block SDLPermissionItem *testPermissionAllAllowed = nil; __block SDLHMIPermissions *testHMIPermissionsAllAllowed = nil; @@ -103,9 +103,8 @@ describe(@"SDLPermissionsManager", ^{ testParameterPermissionUserDisallowed = [[SDLParameterPermissions alloc] init]; testParameterPermissionUserDisallowed.userDisallowed = @[testRPCParameterNameAllDisallowed]; - testParameterPermissionAllowedAndDisallowed = [[SDLParameterPermissions alloc] init]; - testParameterPermissionAllowedAndDisallowed.allowed = @[testRPCParameterNameAllAllowed]; - testParameterPermissionAllowedAndDisallowed.userDisallowed = @[testRPCParameterNameAllDisallowed]; + testParameterPermissionFullLimitedAllowed = [[SDLParameterPermissions alloc] init]; + testParameterPermissionFullLimitedAllowed.allowed = @[testRPCParameterNameAllAllowed, testRPCParameterNameFullLimitedAllowed]; // Assemble Permissions SDLParameterPermissions *testParameterPermissions = [[SDLParameterPermissions alloc] init]; @@ -123,7 +122,7 @@ describe(@"SDLPermissionsManager", ^{ testPermissionFullLimitedAllowed = [[SDLPermissionItem alloc] init]; testPermissionFullLimitedAllowed.rpcName = testRPCNameFullLimitedAllowed; testPermissionFullLimitedAllowed.hmiPermissions = testHMIPermissionsFullLimitedAllowed; - testPermissionFullLimitedAllowed.parameterPermissions = testParameterPermissionAllowedAndDisallowed; + testPermissionFullLimitedAllowed.parameterPermissions = testParameterPermissionFullLimitedAllowed; testPermissionFullLimitedBackgroundAllowed = [[SDLPermissionItem alloc] init]; testPermissionFullLimitedBackgroundAllowed.rpcName = testRPCNameFullLimitedBackgroundAllowed; @@ -305,9 +304,9 @@ describe(@"SDLPermissionsManager", ^{ }); }); - context(@"groupStatusOfRPCNames: method", ^{ + context(@"groupStatusOfRPCPermissions: method", ^{ beforeEach(^{ - testResultStatus = [testPermissionsManager groupStatusOfRPCNames:@[testPermissionElementAllAllowed, testPermissionElementFullLimitedAllowed]]; + testResultStatus = [testPermissionsManager groupStatusOfRPCPermissions:@[testPermissionElementAllAllowed, testPermissionElementFullLimitedAllowed]]; }); it(@"should return unknown", ^{ @@ -332,12 +331,12 @@ describe(@"SDLPermissionsManager", ^{ }); }); - context(@"groupStatusOfRPCNames: method", ^{ + context(@"groupStatusOfRPCPermissions: method", ^{ beforeEach(^{ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; - testResultStatus = [testPermissionsManager groupStatusOfRPCNames:@[testPermissionElementAllAllowed, testPermissionElementFullLimitedAllowed]]; + testResultStatus = [testPermissionsManager groupStatusOfRPCPermissions:@[testPermissionElementAllAllowed, testPermissionElementFullLimitedAllowed]]; }); it(@"should return allowed", ^{ @@ -362,12 +361,12 @@ describe(@"SDLPermissionsManager", ^{ }); }); - context(@"groupStatusOfRPCNames: method", ^{ + context(@"groupStatusOfRPCPermissions: method", ^{ beforeEach(^{ [[NSNotificationCenter defaultCenter] postNotification:backgroundHMINotification]; [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; - testResultStatus = [testPermissionsManager groupStatusOfRPCNames:@[testPermissionElementFullLimitedAllowed, testPermissionElementDisallowed]]; + testResultStatus = [testPermissionsManager groupStatusOfRPCPermissions:@[testPermissionElementFullLimitedAllowed, testPermissionElementDisallowed]]; }); it(@"should return disallowed", ^{ @@ -392,12 +391,12 @@ describe(@"SDLPermissionsManager", ^{ }); }); - context(@"groupStatusOfRPCNames: method", ^{ + context(@"groupStatusOfRPCPermissions: method", ^{ beforeEach(^{ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; - testResultStatus = [testPermissionsManager groupStatusOfRPCNames:@[testPermissionElementAllAllowed, testPermissionElementDisallowed]]; + testResultStatus = [testPermissionsManager groupStatusOfRPCPermissions:@[testPermissionElementAllAllowed, testPermissionElementDisallowed]]; }); it(@"should return mixed", ^{ @@ -433,7 +432,7 @@ describe(@"SDLPermissionsManager", ^{ }); }); - context(@"statusesOfRPCNames: method", ^{ + context(@"statusesOfRPCPermissions: method", ^{statusesOfRPCPermissions beforeEach(^{ testResultRPCPermissionStatusDict = [testPermissionsManager statusesOfRPCPermissions:@[testPermissionElementAllAllowed, testPermissionElementDisallowed]]; allowedResultStatus = testResultRPCPermissionStatusDict[testPermissionElementAllAllowed.rpcName]; @@ -474,7 +473,7 @@ describe(@"SDLPermissionsManager", ^{ }); }); - context(@"statusesOfRPCNames: method", ^{ + context(@"statusesOfRPCPermissions: method", ^{ beforeEach(^{ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; @@ -626,7 +625,7 @@ describe(@"SDLPermissionsManager", ^{ }); }); - describe(@"adding a new observer with subscribeToRPCNames:groupType:Handler", ^{ + describe(@"adding a new observer with subscribeToRPCPermissions:groupType:Handler", ^{ context(@"when no data is present", ^{ __block BOOL testObserverCalled = NO; @@ -1171,7 +1170,7 @@ describe(@"SDLPermissionsManager", ^{ beforeEach(^{ someRPCFunctionName = @"SomeRPCFunctionName"; someRPCParameterName = @"SomeRPCParameterName"; - testResultBOOL = [testPermissionsManager isPermissionParameterAllowed:someRPCFunctionName parameter:someRPCParameterName]; + testResultBOOL = [testPermissionsManager isPermissionParameterAllowed:someRPCFunctionName parameter:someRPCParameterName permissionItems:testPermissionsManager.permissions hmiLevel:testPermissionsManager.currentHMILevel]; }); it(@"should not be allowed", ^{ @@ -1182,7 +1181,7 @@ describe(@"SDLPermissionsManager", ^{ context(@"when permissions exist but no HMI level", ^{ beforeEach(^{ [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; - testResultBOOL = [testPermissionsManager isPermissionParameterAllowed:testRPCNameAllAllowed parameter:testRPCParameterNameAllAllowed]; + testResultBOOL = [testPermissionsManager isPermissionParameterAllowed:testRPCNameAllAllowed parameter:testRPCParameterNameAllAllowed permissionItems:testPermissionsManager.permissions hmiLevel:testPermissionsManager.currentHMILevel]; }); it(@"should not be allowed", ^{ @@ -1196,7 +1195,7 @@ describe(@"SDLPermissionsManager", ^{ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; - testResultBOOL = [testPermissionsManager isPermissionParameterAllowed:testRPCNameAllAllowed parameter:testRPCParameterNameAllAllowed]; + testResultBOOL = [testPermissionsManager isPermissionParameterAllowed:testRPCNameAllAllowed parameter:testRPCParameterNameAllAllowed permissionItems:testPermissionsManager.permissions hmiLevel:testPermissionsManager.currentHMILevel]; }); it(@"should be allowed", ^{ @@ -1209,7 +1208,7 @@ describe(@"SDLPermissionsManager", ^{ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; - testResultBOOL = [testPermissionsManager isPermissionParameterAllowed:testRPCNameAllDisallowed parameter:testRPCParameterNameAllDisallowed]; + testResultBOOL = [testPermissionsManager isPermissionParameterAllowed:testRPCNameAllDisallowed parameter:testRPCParameterNameAllDisallowed permissionItems:testPermissionsManager.permissions hmiLevel:testPermissionsManager.currentHMILevel]; }); it(@"should not be allowed", ^{ @@ -1223,7 +1222,7 @@ describe(@"SDLPermissionsManager", ^{ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; - testResultBOOL = [testPermissionsManager isPermissionParameterAllowed:testRPCNameFullLimitedAllowed parameter:testRPCNameAllDisallowed]; + testResultBOOL = [testPermissionsManager isPermissionParameterAllowed:testRPCNameFullLimitedAllowed parameter:testRPCParameterNameAllDisallowed permissionItems:testPermissionsManager.permissions hmiLevel:testPermissionsManager.currentHMILevel]; }); it(@"should not be allowed", ^{ @@ -1236,7 +1235,7 @@ describe(@"SDLPermissionsManager", ^{ [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; - testResultBOOL = [testPermissionsManager isPermissionParameterAllowed:testRPCNameFullLimitedAllowed parameter:testRPCParameterNameAllAllowed]; + testResultBOOL = [testPermissionsManager isPermissionParameterAllowed:testRPCNameFullLimitedAllowed parameter:testRPCParameterNameAllAllowed permissionItems:testPermissionsManager.permissions hmiLevel:testPermissionsManager.currentHMILevel]; }); it(@"should be allowed", ^{ |