Adding more tests

This commit is contained in:
michael starke
2014-12-09 01:07:20 +01:00
parent 78447e4a6d
commit bb2bc98da9
4 changed files with 121 additions and 12 deletions

View File

@@ -171,6 +171,7 @@
4C6AEEF91A043E2B00CA2420 /* MPDocumentController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6AEEF81A043E2B00CA2420 /* MPDocumentController.m */; }; 4C6AEEF91A043E2B00CA2420 /* MPDocumentController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6AEEF81A043E2B00CA2420 /* MPDocumentController.m */; };
4C6AEF031A04400E00CA2420 /* OpenPanelAccessoryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C6AEF021A04400E00CA2420 /* OpenPanelAccessoryView.xib */; }; 4C6AEF031A04400E00CA2420 /* OpenPanelAccessoryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C6AEF021A04400E00CA2420 /* OpenPanelAccessoryView.xib */; };
4C6B7C7D18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6B7C7C18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m */; }; 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 */; }; 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 */; }; 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 */; }; 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 = "<group>"; }; 4C6AEF021A04400E00CA2420 /* OpenPanelAccessoryView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OpenPanelAccessoryView.xib; sourceTree = "<group>"; };
4C6B7C7B18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MPDocument+HistoryBrowsing.h"; sourceTree = "<group>"; }; 4C6B7C7B18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MPDocument+HistoryBrowsing.h"; sourceTree = "<group>"; };
4C6B7C7C18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MPDocument+HistoryBrowsing.m"; sourceTree = "<group>"; }; 4C6B7C7C18BE7EB0001D5D77 /* MPDocument+HistoryBrowsing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MPDocument+HistoryBrowsing.m"; sourceTree = "<group>"; };
4C6BC65F1A36717E00BDDF3D /* MPDatabaseSearch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDatabaseSearch.m; sourceTree = "<group>"; };
4C6C72C217C01E4200768849 /* NSMutableData+KeePassKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableData+KeePassKit.h"; sourceTree = "<group>"; }; 4C6C72C217C01E4200768849 /* NSMutableData+KeePassKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableData+KeePassKit.h"; sourceTree = "<group>"; };
4C6C72C317C01E4200768849 /* NSMutableData+KeePassKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMutableData+KeePassKit.m"; sourceTree = "<group>"; }; 4C6C72C317C01E4200768849 /* NSMutableData+KeePassKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMutableData+KeePassKit.m"; sourceTree = "<group>"; };
4C6D1D24178579570014C5A5 /* 48_FolderTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 48_FolderTemplate.pdf; sourceTree = "<group>"; }; 4C6D1D24178579570014C5A5 /* 48_FolderTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 48_FolderTemplate.pdf; sourceTree = "<group>"; };
@@ -1449,6 +1451,7 @@
4C45FB2C178E0BCB0010007D /* MPDatabaseLoading.m */, 4C45FB2C178E0BCB0010007D /* MPDatabaseLoading.m */,
4C45FB2F178E0CE20010007D /* MPDatabaseCreation.m */, 4C45FB2F178E0CE20010007D /* MPDatabaseCreation.m */,
4C19E502178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m */, 4C19E502178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m */,
4C6BC65F1A36717E00BDDF3D /* MPDatabaseSearch.m */,
4C45FB1F178E09ED0010007D /* Supporting Files */, 4C45FB1F178E09ED0010007D /* Supporting Files */,
4C305F3B179A19F90082334F /* KPKIconLoading.m */, 4C305F3B179A19F90082334F /* KPKIconLoading.m */,
4C1842B7179B348600E2F5BC /* KPKTestLegacyLoading.m */, 4C1842B7179B348600E2F5BC /* KPKTestLegacyLoading.m */,
@@ -2321,6 +2324,7 @@
4C19E503178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m in Sources */, 4C19E503178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m in Sources */,
4C305F3C179A19F90082334F /* KPKIconLoading.m in Sources */, 4C305F3C179A19F90082334F /* KPKIconLoading.m in Sources */,
4C1842B8179B348600E2F5BC /* KPKTestLegacyLoading.m in Sources */, 4C1842B8179B348600E2F5BC /* KPKTestLegacyLoading.m in Sources */,
4C6BC6601A36717E00BDDF3D /* MPDatabaseSearch.m in Sources */,
4CFC8743179DFD3E000DFC03 /* KPKTestXmlLoading.m in Sources */, 4CFC8743179DFD3E000DFC03 /* KPKTestXmlLoading.m in Sources */,
4C79E80617A9400500AC6CD2 /* KPKTestNSCoding.m in Sources */, 4C79E80617A9400500AC6CD2 /* KPKTestNSCoding.m in Sources */,
4C79E80917A9485600AC6CD2 /* KPKTestNSCopying.m in Sources */, 4C79E80917A9485600AC6CD2 /* KPKTestNSCopying.m in Sources */,

View File

@@ -55,11 +55,34 @@
entry.password = @"Password"; entry.password = @"Password";
/* Command 1 */ /* 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]; 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 { - (void)testCaseSensitiveCustomAttributeLookup {
@@ -72,9 +95,11 @@
KPKAttribute *lowerCaseAttribute = [[KPKAttribute alloc] initWithKey:@"custom" value:@"value"]; KPKAttribute *lowerCaseAttribute = [[KPKAttribute alloc] initWithKey:@"custom" value:@"value"];
KPKAttribute *upperCaseAttribute = [[KPKAttribute alloc] initWithKey:@"CUSTOM" value:@"VALUE"]; KPKAttribute *upperCaseAttribute = [[KPKAttribute alloc] initWithKey:@"CUSTOM" value:@"VALUE"];
KPKAttribute *mixedCaseAttribute = [[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:lowerCaseAttribute];
[entry addCustomAttribute:upperCaseAttribute]; [entry addCustomAttribute:upperCaseAttribute];
[entry addCustomAttribute:mixedCaseAttribute]; [entry addCustomAttribute:mixedCaseAttribute];
[entry addCustomAttribute:randomCase];
entry.autotype.defaultKeystrokeSequence = [[NSString alloc] initWithFormat:@"{USERNAME}{s:%@}{S:%@}{s:%@}", lowerCaseAttribute.key, mixedCaseAttribute.key, upperCaseAttribute.key]; 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.url = @"www.myurl.com";
entry.username = @"{{User{name}}}"; entry.username = @"{{User{name}}}";
entry.password = @"Pass{word}"; entry.password = @"Pass{word}";
/* Command 1 */ /* Command 1 */
MPAutotypeContext *context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"{USERNAME}{TAB}{PASSWORD}{ENTER}"]; MPAutotypeContext *context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"{USERNAME}{TAB}{PASSWORD}{ENTER}"];
NSArray *commands = [MPAutotypeCommand commandsForContext:context]; NSArray *commands = [MPAutotypeCommand commandsForContext:context];
@@ -103,11 +128,11 @@
/* {USERNAME} */ /* {USERNAME} */
MPAutotypePaste *paste = commands[0]; MPAutotypePaste *paste = commands[0];
XCTAssertTrue([paste.pasteData isEqualToString:entry.username]); XCTAssertTrue([paste.pasteData isEqualToString:entry.username]);
/* {TAB} */ /* {TAB} */
MPAutotypeKeyPress *keyPress = commands[1]; MPAutotypeKeyPress *keyPress = commands[1];
XCTAssertTrue(keyPress.keyCode == kVK_Tab); // Tab is a fixed key, no mapping needed XCTAssertEqual(keyPress.keyCode, kVK_Tab); // Tab is a fixed key, no mapping needed
XCTAssertTrue(keyPress.modifierMask == 0); XCTAssertEqual(keyPress.modifierMask, 0);
/* {PASSWORD} */ /* {PASSWORD} */
paste = commands[2]; paste = commands[2];
@@ -115,7 +140,7 @@
/* {ENTER} */ /* {ENTER} */
keyPress = commands[3]; keyPress = commands[3];
XCTAssertTrue(keyPress.keyCode = kVK_Return); XCTAssertEqual(keyPress.keyCode, kVK_Return);
/* Command 2 */ /* Command 2 */
context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"^T{USERNAME}%+^{TAB}Whoo{PASSWORD}{ENTER}"]; context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"^T{USERNAME}%+^{TAB}Whoo{PASSWORD}{ENTER}"];
@@ -131,16 +156,16 @@
keyPress = commands[0]; keyPress = commands[0];
/* Lower case is ok, since we only need the key, not the sequence to reproduce the string */ /* 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([@"t" isEqualToString:[MPKeyMapper stringForKey:keyPress.keyCode]]);
XCTAssertTrue(keyPress.modifierMask == kCGEventFlagMaskCommand); XCTAssertEqual(keyPress.modifierMask, kCGEventFlagMaskCommand);
/* {USERNAME} */ /* {USERNAME} */
paste = commands[1]; paste = commands[1];
XCTAssertTrue([paste.pasteData isEqualToString:entry.username]); XCTAssertTrue([paste.pasteData isEqualToString:entry.username]);
/* %+^{TAB} */ /* %+^{TAB} */
keyPress = commands[2]; keyPress = commands[2];
XCTAssertTrue(keyPress.keyCode == kVK_Tab); // Tab is a fixed key, no mapping needed XCTAssertEqual(keyPress.keyCode, kVK_Tab); // Tab is a fixed key, no mapping needed
XCTAssertTrue(keyPress.modifierMask = kCGEventFlagMaskCommand | kCGEventFlagMaskAlphaShift | kCGEventFlagMaskAlternate); XCTAssertEqual(keyPress.modifierMask, (kCGEventFlagMaskCommand | kCGEventFlagMaskShift | kCGEventFlagMaskAlternate));
/* Whoo{PASSWORD} */ /* Whoo{PASSWORD} */
paste = commands[3]; paste = commands[3];
@@ -149,6 +174,7 @@
/* {ENTER} */ /* {ENTER} */
keyPress = commands[4]; keyPress = commands[4];
XCTAssertTrue(keyPress.keyCode = kVK_Return); XCTAssertEqual(keyPress.keyCode, kVK_Return);
XCTAssertEqual(keyPress.modifierMask, 0);
} }
@end @end

View File

@@ -53,6 +53,27 @@
XCTAssertTrue([result isEqualToString:@"NothingTitle1-Entry2URL-Changed"], @"Replaced Strings should match"); 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 { - (void)testWrongRefernce {
XCTFail(@"Missing Test"); XCTFail(@"Missing Test");
} }

View File

@@ -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 <Cocoa/Cocoa.h>
#import <XCTest/XCTest.h>
#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