You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/11/07 17:33:37 UTC
[2/2] ios commit: Making whitelist rejection string configurable
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 <kh...@salesforce.com>
Authored: Tue Oct 30 10:00:36 2012 -0700
Committer: Andrew Grieve <ag...@chromium.org>
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 <Foundation/Foundation.h>
+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