From bb2bc98da9af05e78f99736428d0bfec0f2b1ba8 Mon Sep 17 00:00:00 2001 From: michael starke Date: Tue, 9 Dec 2014 01:07:20 +0100 Subject: [PATCH] Adding more tests --- MacPass.xcodeproj/project.pbxproj | 4 +++ MacPassTests/KPKTestAutotype.m | 50 +++++++++++++++++++------- MacPassTests/KPKTestReference.m | 21 +++++++++++ MacPassTests/MPDatabaseSearch.m | 58 +++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 12 deletions(-) create mode 100644 MacPassTests/MPDatabaseSearch.m diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 9552c22d..f234d328 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -171,6 +171,7 @@ 4C6AEEF91A043E2B00CA2420 /* MPDocumentController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6AEEF81A043E2B00CA2420 /* MPDocumentController.m */; }; 4C6AEF031A04400E00CA2420 /* OpenPanelAccessoryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C6AEF021A04400E00CA2420 /* OpenPanelAccessoryView.xib */; }; 4C6B7C7D18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6B7C7C18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m */; }; + 4C6BC6601A36717E00BDDF3D /* MPDatabaseSearch.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6BC65F1A36717E00BDDF3D /* MPDatabaseSearch.m */; }; 4C6C72C417C01E4200768849 /* NSMutableData+KeePassKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6C72C317C01E4200768849 /* NSMutableData+KeePassKit.m */; }; 4C6D1D25178579570014C5A5 /* 48_FolderTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C6D1D24178579570014C5A5 /* 48_FolderTemplate.pdf */; }; 4C6D1D27178586CA0014C5A5 /* 99_AddFolderTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C6D1D26178586CA0014C5A5 /* 99_AddFolderTemplate.pdf */; }; @@ -687,6 +688,7 @@ 4C6AEF021A04400E00CA2420 /* OpenPanelAccessoryView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OpenPanelAccessoryView.xib; sourceTree = ""; }; 4C6B7C7B18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MPDocument+HistoryBrowsing.h"; sourceTree = ""; }; 4C6B7C7C18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MPDocument+HistoryBrowsing.m"; sourceTree = ""; }; + 4C6BC65F1A36717E00BDDF3D /* MPDatabaseSearch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDatabaseSearch.m; sourceTree = ""; }; 4C6C72C217C01E4200768849 /* NSMutableData+KeePassKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableData+KeePassKit.h"; sourceTree = ""; }; 4C6C72C317C01E4200768849 /* NSMutableData+KeePassKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMutableData+KeePassKit.m"; sourceTree = ""; }; 4C6D1D24178579570014C5A5 /* 48_FolderTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 48_FolderTemplate.pdf; sourceTree = ""; }; @@ -1449,6 +1451,7 @@ 4C45FB2C178E0BCB0010007D /* MPDatabaseLoading.m */, 4C45FB2F178E0CE20010007D /* MPDatabaseCreation.m */, 4C19E502178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m */, + 4C6BC65F1A36717E00BDDF3D /* MPDatabaseSearch.m */, 4C45FB1F178E09ED0010007D /* Supporting Files */, 4C305F3B179A19F90082334F /* KPKIconLoading.m */, 4C1842B7179B348600E2F5BC /* KPKTestLegacyLoading.m */, @@ -2321,6 +2324,7 @@ 4C19E503178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m in Sources */, 4C305F3C179A19F90082334F /* KPKIconLoading.m in Sources */, 4C1842B8179B348600E2F5BC /* KPKTestLegacyLoading.m in Sources */, + 4C6BC6601A36717E00BDDF3D /* MPDatabaseSearch.m in Sources */, 4CFC8743179DFD3E000DFC03 /* KPKTestXmlLoading.m in Sources */, 4C79E80617A9400500AC6CD2 /* KPKTestNSCoding.m in Sources */, 4C79E80917A9485600AC6CD2 /* KPKTestNSCopying.m in Sources */, diff --git a/MacPassTests/KPKTestAutotype.m b/MacPassTests/KPKTestAutotype.m index a7d86702..41ea7505 100644 --- a/MacPassTests/KPKTestAutotype.m +++ b/MacPassTests/KPKTestAutotype.m @@ -55,11 +55,34 @@ entry.password = @"Password"; /* Command 1 */ - MPAutotypeContext *context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"{TAB}{ENTER}~{tAb}{ShIfT}"]; + MPAutotypeContext *context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"{TAB}{ENTER}~{tAb}{ShIfT}{enter}"]; NSArray *commands = [MPAutotypeCommand commandsForContext:context]; - XCTAssert(nil); + XCTAssertTrue(commands.count == 5); + /* {TAB} */ + MPAutotypeKeyPress *keyPress = commands[0]; + XCTAssertEqual(keyPress.keyCode, kVK_Tab); + XCTAssertEqual(keyPress.modifierMask, 0); + + /* {ENTER} */ + keyPress = commands[1]; + XCTAssertEqual(keyPress.keyCode, kVK_Return); + XCTAssertEqual(keyPress.modifierMask, 0); + /* ~ -> Enter */ + keyPress = commands[2]; + XCTAssertEqual(keyPress.keyCode, kVK_Return); + XCTAssertEqual(keyPress.modifierMask, 0); + + /* {tAb} */ + keyPress = commands[3]; + XCTAssertEqual(keyPress.keyCode, kVK_Tab); + XCTAssertEqual(keyPress.modifierMask, 0); + + /* {ShIfT}{enter}*/ + keyPress = commands[4]; + XCTAssertEqual(keyPress.keyCode, kVK_Return); + XCTAssertEqual(keyPress.modifierMask, kCGEventFlagMaskShift); } - (void)testCaseSensitiveCustomAttributeLookup { @@ -72,9 +95,11 @@ KPKAttribute *lowerCaseAttribute = [[KPKAttribute alloc] initWithKey:@"custom" value:@"value"]; KPKAttribute *upperCaseAttribute = [[KPKAttribute alloc] initWithKey:@"CUSTOM" value:@"VALUE"]; KPKAttribute *mixedCaseAttribute = [[KPKAttribute alloc] initWithKey:@"CuStOm" value:@"VaLuE"]; + KPKAttribute *randomCase = [[KPKAttribute alloc] initWithKey:@"custoM" value:@"valuE"]; [entry addCustomAttribute:lowerCaseAttribute]; [entry addCustomAttribute:upperCaseAttribute]; [entry addCustomAttribute:mixedCaseAttribute]; + [entry addCustomAttribute:randomCase]; entry.autotype.defaultKeystrokeSequence = [[NSString alloc] initWithFormat:@"{USERNAME}{s:%@}{S:%@}{s:%@}", lowerCaseAttribute.key, mixedCaseAttribute.key, upperCaseAttribute.key]; @@ -89,7 +114,7 @@ entry.url = @"www.myurl.com"; entry.username = @"{{User{name}}}"; entry.password = @"Pass{word}"; - + /* Command 1 */ MPAutotypeContext *context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"{USERNAME}{TAB}{PASSWORD}{ENTER}"]; NSArray *commands = [MPAutotypeCommand commandsForContext:context]; @@ -103,11 +128,11 @@ /* {USERNAME} */ MPAutotypePaste *paste = commands[0]; XCTAssertTrue([paste.pasteData isEqualToString:entry.username]); - + /* {TAB} */ MPAutotypeKeyPress *keyPress = commands[1]; - XCTAssertTrue(keyPress.keyCode == kVK_Tab); // Tab is a fixed key, no mapping needed - XCTAssertTrue(keyPress.modifierMask == 0); + XCTAssertEqual(keyPress.keyCode, kVK_Tab); // Tab is a fixed key, no mapping needed + XCTAssertEqual(keyPress.modifierMask, 0); /* {PASSWORD} */ paste = commands[2]; @@ -115,7 +140,7 @@ /* {ENTER} */ keyPress = commands[3]; - XCTAssertTrue(keyPress.keyCode = kVK_Return); + XCTAssertEqual(keyPress.keyCode, kVK_Return); /* Command 2 */ context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"^T{USERNAME}%+^{TAB}Whoo{PASSWORD}{ENTER}"]; @@ -131,16 +156,16 @@ keyPress = commands[0]; /* Lower case is ok, since we only need the key, not the sequence to reproduce the string */ XCTAssertTrue([@"t" isEqualToString:[MPKeyMapper stringForKey:keyPress.keyCode]]); - XCTAssertTrue(keyPress.modifierMask == kCGEventFlagMaskCommand); - + XCTAssertEqual(keyPress.modifierMask, kCGEventFlagMaskCommand); + /* {USERNAME} */ paste = commands[1]; XCTAssertTrue([paste.pasteData isEqualToString:entry.username]); /* %+^{TAB} */ keyPress = commands[2]; - XCTAssertTrue(keyPress.keyCode == kVK_Tab); // Tab is a fixed key, no mapping needed - XCTAssertTrue(keyPress.modifierMask = kCGEventFlagMaskCommand | kCGEventFlagMaskAlphaShift | kCGEventFlagMaskAlternate); + XCTAssertEqual(keyPress.keyCode, kVK_Tab); // Tab is a fixed key, no mapping needed + XCTAssertEqual(keyPress.modifierMask, (kCGEventFlagMaskCommand | kCGEventFlagMaskShift | kCGEventFlagMaskAlternate)); /* Whoo{PASSWORD} */ paste = commands[3]; @@ -149,6 +174,7 @@ /* {ENTER} */ keyPress = commands[4]; - XCTAssertTrue(keyPress.keyCode = kVK_Return); + XCTAssertEqual(keyPress.keyCode, kVK_Return); + XCTAssertEqual(keyPress.modifierMask, 0); } @end diff --git a/MacPassTests/KPKTestReference.m b/MacPassTests/KPKTestReference.m index 6598bc7a..8d56695d 100644 --- a/MacPassTests/KPKTestReference.m +++ b/MacPassTests/KPKTestReference.m @@ -53,6 +53,27 @@ XCTAssertTrue([result isEqualToString:@"NothingTitle1-Entry2URL-Changed"], @"Replaced Strings should match"); } +- (void)testReferncePasswordByTitle { + KPKTree *tree = [[KPKTree alloc] init]; + KPKGroup *group = [[KPKGroup alloc] init]; + KPKEntry *entry1 = [[KPKEntry alloc] init]; + KPKEntry *entry2 = [[KPKEntry alloc] init]; + entry1.title = [[NSString alloc] initWithFormat:@"Title1{REF:A@i:%@}", entry2.uuid.UUIDString]; + entry2.title = [[NSString alloc] initWithFormat:@"Nothing{REF:t@I:%@}Changed", entry1.uuid.UUIDString]; + entry2.url = @"-Entry2URL-"; + + [group addEntry:entry1]; + [group addEntry:entry2]; + tree.root = group; + + NSString *result = [entry2.title resolveReferencesWithTree:tree]; + XCTAssertTrue([result isEqualToString:@"NothingTitle1-Entry2URL-Changed"], @"Replaced Strings should match"); +} + +- (void)testReferncePasswordByCustomAttribute { + +} + - (void)testWrongRefernce { XCTFail(@"Missing Test"); } diff --git a/MacPassTests/MPDatabaseSearch.m b/MacPassTests/MPDatabaseSearch.m new file mode 100644 index 00000000..270b64b2 --- /dev/null +++ b/MacPassTests/MPDatabaseSearch.m @@ -0,0 +1,58 @@ +// +// MPDatabaseSearch.m +// MacPass +// +// Created by Michael Starke on 09/12/14. +// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved. +// + +#import +#import + +#import "KPKTree.h" +#import "KPKGroup.h" +#import "KPKEntry.h" + +@interface MPDatabaseSearch : XCTestCase + +@property (strong) KPKTree *tree; +@property (weak) KPKGroup *includedGroup; +@property (weak) KPKGroup *inheritingGroup; +@property (weak) KPKGroup *excludedGroup; +@property (weak) KPKEntry *entry1; +@property (weak) KPKEntry *entry2; +@property (weak) KPKEntry *entry3; + +@end + +@implementation MPDatabaseSearch + +- (void)setUp { + [super setUp]; + self.tree = [[KPKTree alloc] init]; + self.tree.root = [[KPKGroup alloc] init]; + + self.inheritingGroup = [self.tree createGroup:self.tree.root]; + self.includedGroup = [self.tree createGroup:self.tree.root]; + self.excludedGroup = [self.tree createGroup:self.tree.root]; + self.inheritingGroup.isAutoTypeEnabled = KPKInherit; + self.includedGroup.isAutoTypeEnabled = KPKInheritYES; + self.excludedGroup.isAutoTypeEnabled = KPKInheritNO; + + self.entry1 = [self.tree createEntry:self.includedGroup]; + self.entry2 = [self.tree createEntry:self.inheritingGroup]; + self.entry3 = [self.tree createEntry:self.excludedGroup]; + self.entry1.title = @"entry1"; + self.entry2.title = @"entry2"; + self.entry3.title = @"entry3"; +} + +- (void)tearDown { + self.tree = nil; + [super tearDown]; +} + +- (void)testSearch { +} + +@end