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

@@ -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

View File

@@ -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");
}

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