Permalink
Browse files

Sample email tests

  • Loading branch information...
1 parent 7eebb13 commit 3a767ecda4969e4ae4fc8e4c0749e13e4aeedd25 @Romes-- Romes-- committed Jan 25, 2014
@@ -0,0 +1,7 @@
+# ExportedSymbols.exp
+# HTMLPurifier
+#
+# Created by Roman Priebe on 25.01.14.
+# Copyright (c) 2014 Mynigma. All rights reserved.
+
+_HTMLPurifier
@@ -153,7 +153,7 @@ - (void)actuallyReadPlist
NSURL* configPlistPath = [BUNDLE URLForResource:@"config" withExtension:@"plist"];
if(!configPlistPath)
{
- NSLog(@"Error opening config plist file!");
+ NSLog(@"Error opening config plist file! Bundle: %@", BUNDLE);
return;
}
@@ -18,7 +18,7 @@ - (id)init
{
self = [super init];
if (self) {
- [strategies addObject:[HTMLPurifier_Strategy_RemoveForeignElements new]];
+ //[strategies addObject:[HTMLPurifier_Strategy_RemoveForeignElements new]];
[strategies addObject:[HTMLPurifier_Strategy_MakeWellFormed new]];
//[strategies addObject:[HTMLPurifier_Strategy_FixNesting new]];
[strategies addObject:[HTMLPurifier_Strategy_ValidateAttributes new]];
@@ -0,0 +1,9 @@
+//
+// Prefix header
+//
+// The contents of this file are implicitly included at the beginning of every source file.
+//
+
+#ifdef __OBJC__
+ #import <Cocoa/Cocoa.h>
+#endif
@@ -0,0 +1,13 @@
+//
+// HTMLPurifierObjC.h
+// HTMLPurifierObjC
+//
+// Created by Roman Priebe on 25.01.14.
+// Copyright (c) 2014 Mynigma. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface HTMLPurifierObjC : NSObject
+
+@end
@@ -0,0 +1,13 @@
+//
+// HTMLPurifierObjC.m
+// HTMLPurifierObjC
+//
+// Created by Roman Priebe on 25.01.14.
+// Copyright (c) 2014 Mynigma. All rights reserved.
+//
+
+#import "HTMLPurifierObjC.h"
+
+@implementation HTMLPurifierObjC
+
+@end
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>Mynigma.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>BNDL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+</dict>
+</plist>
@@ -0,0 +1,34 @@
+//
+// HTMLPurifierObjCTests.m
+// HTMLPurifierObjCTests
+//
+// Created by Roman Priebe on 25.01.14.
+// Copyright (c) 2014 Mynigma. All rights reserved.
+//
+
+#import <XCTest/XCTest.h>
+
+@interface HTMLPurifierObjCTests : XCTestCase
+
+@end
+
+@implementation HTMLPurifierObjCTests
+
+- (void)setUp
+{
+ [super setUp];
+ // Put setup code here. This method is called before the invocation of each test method in the class.
+}
+
+- (void)tearDown
+{
+ // Put teardown code here. This method is called after the invocation of each test method in the class.
+ [super tearDown];
+}
+
+- (void)testExample
+{
+ XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
+}
+
+@end
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
@@ -9,6 +9,9 @@
#import <XCTest/XCTest.h>
#import "HTMLPurifier.h"
#import "HTMLPurifier_Harness.h"
+#import "HTMLPurifier_Config.h"
+
+
#define BUNDLE (NSClassFromString(@"HTMLPurifierTests")!=nil)?[NSBundle bundleForClass:[NSClassFromString(@"HTMLPurifierTests") class]]:[NSBundle mainBundle]
@@ -35,7 +38,7 @@ - (void)tearDown
}
-- (void)testFromPlist
+- (void)testXSSAttacks
{
NSURL* configPlistPath = [BUNDLE URLForResource:@"xssSmoketests" withExtension:@"plist"];
if(!configPlistPath)
@@ -53,11 +56,54 @@ - (void)testFromPlist
NSString* before = plistDict[key][0];
NSString* after = [purifier purify:before];
NSString* expect = plistDict[key][1];
+ XCTAssertNotNil(before, @"%@", key);
XCTAssertEqualObjects(after, expect, @"%@", key);
}
else
XCTFail(@"Too few items in dictionary for key %@", key);
}
}
+- (void)testEmailSamples
+{
+ [[super config] setString:@"Output.Newline" object:@""];
+
+ NSURL* configPlistPath = [BUNDLE URLForResource:@"test_Emails" withExtension:@"plist"];
+ if(!configPlistPath)
+ {
+ NSLog(@"Error opening config plist file!");
+ return;
+ }
+
+ NSDictionary* plistDict = [NSDictionary dictionaryWithContentsOfURL:configPlistPath];
+
+ for(NSString* key in plistDict)
+ {
+ if([plistDict[key] count]>1)
+ {
+ NSString* before = plistDict[key][0];
+
+ NSData* beforeData = [[NSData alloc] initWithBase64EncodedString:before options:0];
+
+ NSString* beforeString = [[NSString alloc] initWithData:beforeData encoding:NSUTF8StringEncoding];
+
+ NSString* expect = plistDict[key][1];
+
+ NSData* expectData = [[NSData alloc] initWithBase64EncodedString:expect options:0];
+
+ NSString* expectString = [[NSString alloc] initWithData:expectData encoding:NSUTF8StringEncoding];
+
+
+ XCTAssertNotNil(beforeString, @"%@", key);
+
+ NSString* afterString = [purifier purify:beforeString];
+
+ XCTAssertEqualObjects(afterString, expectString, @"%@", key);
+ }
+ else
+ XCTFail(@"Too few items in dictionary for key %@", key);
+ }
+}
+
+
@end
Oops, something went wrong.

0 comments on commit 3a767ec

Please sign in to comment.