Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 769A6D7B0 for ; Wed, 7 Nov 2012 16:33:43 +0000 (UTC) Received: (qmail 42434 invoked by uid 500); 7 Nov 2012 16:33:43 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 42251 invoked by uid 500); 7 Nov 2012 16:33:38 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 42224 invoked by uid 500); 7 Nov 2012 16:33:37 -0000 Delivered-To: apmail-incubator-callback-commits@incubator.apache.org Received: (qmail 42213 invoked by uid 99); 7 Nov 2012 16:33:37 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Nov 2012 16:33:37 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 67F5D451E1; Wed, 7 Nov 2012 16:33:37 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agrieve@apache.org To: callback-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [2/2] ios commit: Making whitelist rejection string configurable Message-Id: <20121107163337.67F5D451E1@tyr.zones.apache.org> Date: Wed, 7 Nov 2012 16:33:37 +0000 (UTC) Making whitelist rejection string configurable Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/69c1375a Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/69c1375a Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/69c1375a Branch: refs/heads/master Commit: 69c1375a7e2788770e3a28cada26465591e367f1 Parents: dac34c4 Author: Kevin Hawkins Authored: Tue Oct 30 10:00:36 2012 -0700 Committer: Andrew Grieve Committed: Wed Nov 7 11:21:27 2012 -0500 ---------------------------------------------------------------------- CordovaLib/Classes/CDVWhitelist.h | 3 +++ CordovaLib/Classes/CDVWhitelist.m | 7 +++++-- CordovaLibTests/CDVWhitelistTests.m | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/69c1375a/CordovaLib/Classes/CDVWhitelist.h ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVWhitelist.h b/CordovaLib/Classes/CDVWhitelist.h index 0eb28f9..b848342 100644 --- a/CordovaLib/Classes/CDVWhitelist.h +++ b/CordovaLib/Classes/CDVWhitelist.h @@ -19,11 +19,14 @@ #import +extern NSString * const kCDVDefaultWhitelistRejectionString; + @interface CDVWhitelist : NSObject @property (nonatomic, readonly, strong) NSArray* whitelist; @property (nonatomic, readonly, strong) NSArray* expandedWhitelist; @property (nonatomic, readonly, assign) BOOL allowAll; +@property (nonatomic, copy) NSString *whitelistRejectionFormatString; - (id)initWithArray:(NSArray*)array; - (BOOL)URLIsAllowed:(NSURL*)url; http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/69c1375a/CordovaLib/Classes/CDVWhitelist.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVWhitelist.m b/CordovaLib/Classes/CDVWhitelist.m index ad2a0c6..1bf0f56 100644 --- a/CordovaLib/Classes/CDVWhitelist.m +++ b/CordovaLib/Classes/CDVWhitelist.m @@ -19,6 +19,8 @@ #import "CDVWhitelist.h" +NSString * const kCDVDefaultWhitelistRejectionString = @"ERROR whitelist rejection: url='%@'"; + @interface CDVWhitelist () @property (nonatomic, readwrite, strong) NSArray* whitelist; @@ -31,7 +33,7 @@ @implementation CDVWhitelist -@synthesize whitelist, expandedWhitelist, allowAll; +@synthesize whitelist, expandedWhitelist, allowAll, whitelistRejectionFormatString; - (id)initWithArray:(NSArray*)array { @@ -40,6 +42,7 @@ self.whitelist = array; self.expandedWhitelist = nil; self.allowAll = NO; + self.whitelistRejectionFormatString = kCDVDefaultWhitelistRejectionString; [self processWhitelist]; } @@ -183,7 +186,7 @@ - (NSString*)errorStringForURL:(NSURL*)url { - return [NSString stringWithFormat:@"ERROR whitelist rejection: url='%@'", [url absoluteString]]; + return [NSString stringWithFormat:self.whitelistRejectionFormatString, [url absoluteString]]; } @end http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/69c1375a/CordovaLibTests/CDVWhitelistTests.m ---------------------------------------------------------------------- diff --git a/CordovaLibTests/CDVWhitelistTests.m b/CordovaLibTests/CDVWhitelistTests.m index cd5cca3..2e26779 100644 --- a/CordovaLibTests/CDVWhitelistTests.m +++ b/CordovaLibTests/CDVWhitelistTests.m @@ -245,4 +245,20 @@ STAssertFalse([whitelist URLIsAllowed:[NSURL URLWithString:@"http://google.com"]], nil); } +- (void)testWhitelistRejectionString +{ + NSArray *allowedHosts = [NSArray arrayWithObject:@"http://www.yahoo.com/"]; // Doesn't matter in this test. + CDVWhitelist *whitelist = [[CDVWhitelist alloc] initWithArray:allowedHosts]; + + NSURL *testUrl = [NSURL URLWithString:@"http://www/google.com"]; + NSString *errorString = [whitelist errorStringForURL:testUrl]; + NSString *expectedErrorString = [NSString stringWithFormat:kCDVDefaultWhitelistRejectionString, [testUrl absoluteString]]; + STAssertTrue([expectedErrorString isEqualToString:errorString], @"Default error string has an unexpected value."); + + whitelist.whitelistRejectionFormatString = @"Hey, '%@' is, like, bogus man!"; + errorString = [whitelist errorStringForURL:testUrl]; + expectedErrorString = [NSString stringWithFormat:whitelist.whitelistRejectionFormatString, [testUrl absoluteString]]; + STAssertTrue([expectedErrorString isEqualToString:errorString], @"Customized whitelist rejection string has unexpected value."); +} + @end