mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 01:12:31 +00:00
Added better test for modifier base key presses
This commit is contained in:
@@ -138,7 +138,7 @@
|
||||
4C586FA216D07F6A00E7DB57 /* 02_MessageBoxWarningTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C586FA116D07F6A00E7DB57 /* 02_MessageBoxWarningTemplate.pdf */; };
|
||||
4C58BD4F176370B100B8178C /* HNHBadgedTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C58BD4E176370B100B8178C /* HNHBadgedTextField.m */; };
|
||||
4C591B57178F897A0080B16B /* KPKBinary.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C591B56178F897A0080B16B /* KPKBinary.m */; };
|
||||
4C59745118B3CE7200C8EBD1 /* KPKTestAutotypeNormalization.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C59745018B3CE7200C8EBD1 /* KPKTestAutotypeNormalization.m */; };
|
||||
4C59745118B3CE7200C8EBD1 /* KPKTestAutotype.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C59745018B3CE7200C8EBD1 /* KPKTestAutotype.m */; };
|
||||
4C5A11FE1708DE8700223D8A /* MPPasswordCreatorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C5A11FC1708DE8700223D8A /* MPPasswordCreatorViewController.m */; };
|
||||
4C5AA591179549A1008ECAD7 /* KPKXmlTreeWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C5AA590179549A1008ECAD7 /* KPKXmlTreeWriter.m */; };
|
||||
4C5CD35517D15DBD000B7F38 /* NSData+Gzip.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C5CD34A17D15DBD000B7F38 /* NSData+Gzip.m */; };
|
||||
@@ -615,7 +615,7 @@
|
||||
4C58BD4E176370B100B8178C /* HNHBadgedTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHBadgedTextField.m; sourceTree = "<group>"; };
|
||||
4C591B55178F897A0080B16B /* KPKBinary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KPKBinary.h; sourceTree = "<group>"; };
|
||||
4C591B56178F897A0080B16B /* KPKBinary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKBinary.m; sourceTree = "<group>"; };
|
||||
4C59745018B3CE7200C8EBD1 /* KPKTestAutotypeNormalization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKTestAutotypeNormalization.m; sourceTree = "<group>"; };
|
||||
4C59745018B3CE7200C8EBD1 /* KPKTestAutotype.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKTestAutotype.m; sourceTree = "<group>"; };
|
||||
4C5A11FB1708DE8700223D8A /* MPPasswordCreatorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPPasswordCreatorViewController.h; sourceTree = "<group>"; };
|
||||
4C5A11FC1708DE8700223D8A /* MPPasswordCreatorViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPPasswordCreatorViewController.m; sourceTree = "<group>"; };
|
||||
4C5AA58F179549A1008ECAD7 /* KPKXmlTreeWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KPKXmlTreeWriter.h; sourceTree = "<group>"; };
|
||||
@@ -1453,7 +1453,7 @@
|
||||
4CBA561517C2EA4900CE13D3 /* KPKTestXmlWriting.m */,
|
||||
4C473A7E18AFD6340073FD2E /* KPKTestReference.m */,
|
||||
4CD25F9218B17A17006098E9 /* KPKTestUUIDAdditions.m */,
|
||||
4C59745018B3CE7200C8EBD1 /* KPKTestAutotypeNormalization.m */,
|
||||
4C59745018B3CE7200C8EBD1 /* KPKTestAutotype.m */,
|
||||
);
|
||||
path = MacPassTests;
|
||||
sourceTree = "<group>";
|
||||
@@ -2315,7 +2315,7 @@
|
||||
4C6366AF17AF207600AAF17D /* KPKTestHexColor.m in Sources */,
|
||||
4CE76DAD17B3AD010043B82B /* KPKHashedDataTest.m in Sources */,
|
||||
4CEAF85B17BA9B44001307A6 /* KPKTestKeyfileParsing.m in Sources */,
|
||||
4C59745118B3CE7200C8EBD1 /* KPKTestAutotypeNormalization.m in Sources */,
|
||||
4C59745118B3CE7200C8EBD1 /* KPKTestAutotype.m in Sources */,
|
||||
4C6FDD2117BC4F4C004AEEC8 /* KPKTestPlaceholder.m in Sources */,
|
||||
4CBA561617C2EA4900CE13D3 /* KPKTestXmlWriting.m in Sources */,
|
||||
);
|
||||
|
||||
@@ -319,10 +319,10 @@
|
||||
CGEventRef pressKey = CGEventCreateKeyboardEvent (eventSource, keyCode, YES);
|
||||
CGEventRef releaseKey = CGEventCreateKeyboardEvent (eventSource, keyCode, NO);
|
||||
|
||||
/* The modifer Masks might be set, reset them */
|
||||
CGEventSetFlags(pressKey,0);
|
||||
CGEventSetFlags(releaseKey, 0);
|
||||
/* Set the modifiers to the ones we want */
|
||||
/*
|
||||
Set the modifiers to the ones we want
|
||||
We use our private event source so no modifier reset should be needed
|
||||
*/
|
||||
CGEventSetFlags(pressKey,flags);
|
||||
CGEventSetFlags(releaseKey, flags);
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
*/
|
||||
@interface MPAutotypePaste : MPAutotypeCommand
|
||||
|
||||
@property (readonly, copy) NSString *pasteData;
|
||||
|
||||
- (instancetype)initWithString:(NSString *)aString;
|
||||
- (void)appendString:(NSString *)aString;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
@interface MPAutotypePaste ()
|
||||
|
||||
@property (strong) NSString *pasteData;
|
||||
@property (copy) NSString *pasteData;
|
||||
|
||||
@end
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
self.pasteData = [self.pasteData stringByAppendingString:aString];
|
||||
}
|
||||
|
||||
|
||||
- (void)execute {
|
||||
if([self.pasteData length] > 0) {
|
||||
MPPasteBoardController *controller = [MPPasteBoardController defaultController];
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>2548</string>
|
||||
<string>2550</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
|
||||
115
MacPassTests/KPKTestAutotype.m
Normal file
115
MacPassTests/KPKTestAutotype.m
Normal file
@@ -0,0 +1,115 @@
|
||||
//
|
||||
// KPKTestAutotypeNormalization.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 18.02.14.
|
||||
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
#import <Carbon/Carbon.h>
|
||||
|
||||
#import "NSString+Commands.h"
|
||||
#import "MPAutotypeCommand.h"
|
||||
#import "MPAutotypeContext.h"
|
||||
#import "MPAutotypePaste.h"
|
||||
#import "MPAutotypeKeyPress.h"
|
||||
|
||||
#import "MPKeyMapper.h"
|
||||
|
||||
#import "KPKEntry.h"
|
||||
|
||||
@interface KPKTestAutotype : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation KPKTestAutotype
|
||||
|
||||
- (void)testSimpleNormalization {
|
||||
NSString *normalized = [@"Whoo %{%}{^}{SHIFT}+ {SPACE}{ENTER}^V%V~T" normalizedAutotypeSequence];
|
||||
XCTAssertTrue([normalized isEqualToString:@"Whoo{SPACE}{ALT}{%}{^}{SHIFT}{SHIFT}{SPACE}{SPACE}{ENTER}{CONTROL}V{ALT}V{ENTER}T"]);
|
||||
}
|
||||
|
||||
- (void)testCommandRepetition {
|
||||
NSString *normalized = [@"Whoo %{% 2}{^}{SHIFT 5}+ {SPACE}{ENTER}^V%V~T" normalizedAutotypeSequence];
|
||||
XCTAssertTrue([normalized isEqualToString:@"Whoo{SPACE}{ALT}{%}{%}{^}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SPACE}{SPACE}{ENTER}{CONTROL}V{ALT}V{ENTER}T"]);
|
||||
normalized = [@"{TAB 5}TAB{TAB}{SHIFT}{SHIFT 10}ENTER{ENTER}{%%}" normalizedAutotypeSequence];
|
||||
XCTAssertTrue([normalized isEqualToString:@"{TAB}{TAB}{TAB}{TAB}{TAB}TAB{TAB}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}ENTER{ENTER}{%%}"]);
|
||||
}
|
||||
|
||||
- (void)testeBracketValidation {
|
||||
XCTAssertFalse([@"{BOOO}NO-COMMAND{TAB}{WHOO}{WHOO}{SPACE}!!!thisIsFun{{MISMATCH!!!}" validateCommmand]);
|
||||
XCTAssertFalse([@"{{}}}}" validateCommmand]);
|
||||
XCTAssertFalse([@"{}{}{{{}{{{{{{}}" validateCommmand]);
|
||||
XCTAssertTrue([@"{}{}{}{}{}{ }ThisIsValid{}{STOP}" validateCommmand]);
|
||||
}
|
||||
|
||||
- (void)testCommandCreation {
|
||||
KPKEntry *entry = [[KPKEntry alloc] init];
|
||||
entry.title = @"Title";
|
||||
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];
|
||||
|
||||
XCTAssertTrue(commands.count == 4);
|
||||
XCTAssertTrue([commands[0] isKindOfClass:[MPAutotypePaste class]]);
|
||||
XCTAssertTrue([commands[1] isKindOfClass:[MPAutotypeKeyPress class]]);
|
||||
XCTAssertTrue([commands[2] isKindOfClass:[MPAutotypePaste class]]);
|
||||
XCTAssertTrue([commands[3] isKindOfClass:[MPAutotypeKeyPress class]]);
|
||||
|
||||
/* {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);
|
||||
|
||||
/* {PASSWORD} */
|
||||
paste = commands[2];
|
||||
XCTAssertTrue([entry.password isEqualToString:paste.pasteData]);
|
||||
|
||||
/* {ENTER} */
|
||||
keyPress = commands[3];
|
||||
XCTAssertTrue(keyPress.keyCode = kVK_Return);
|
||||
|
||||
/* Command 2 */
|
||||
context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"^T{USERNAME}%+^{TAB}Whoo{PASSWORD}{ENTER}"];
|
||||
commands = [MPAutotypeCommand commandsForContext:context];
|
||||
XCTAssertTrue(commands.count == 5);
|
||||
XCTAssertTrue([commands[0] isKindOfClass:[MPAutotypeKeyPress class]]);
|
||||
XCTAssertTrue([commands[1] isKindOfClass:[MPAutotypePaste class]]);
|
||||
XCTAssertTrue([commands[2] isKindOfClass:[MPAutotypeKeyPress class]]);
|
||||
XCTAssertTrue([commands[3] isKindOfClass:[MPAutotypePaste class]]);
|
||||
XCTAssertTrue([commands[4] isKindOfClass:[MPAutotypeKeyPress class]]);
|
||||
|
||||
/* ^T */
|
||||
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);
|
||||
|
||||
/* {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);
|
||||
|
||||
/* Whoo{PASSWORD} */
|
||||
paste = commands[3];
|
||||
NSString *pasteString = [[NSString alloc] initWithFormat:@"%@%@", @"Whoo", entry.password];
|
||||
XCTAssertTrue([pasteString isEqualToString:paste.pasteData]);
|
||||
|
||||
/* {ENTER} */
|
||||
keyPress = commands[4];
|
||||
XCTAssertTrue(keyPress.keyCode = kVK_Return);
|
||||
}
|
||||
@end
|
||||
@@ -1,68 +0,0 @@
|
||||
//
|
||||
// KPKTestAutotypeNormalization.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 18.02.14.
|
||||
// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "NSString+Commands.h"
|
||||
#import "MPAutotypeCommand.h"
|
||||
#import "MPAutotypeContext.h"
|
||||
#import "MPAutotypePaste.h"
|
||||
#import "MPAutotypeKeyPress.h"
|
||||
|
||||
#import "KPKEntry.h"
|
||||
|
||||
@interface KPKTestAutotypeNormalization : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation KPKTestAutotypeNormalization
|
||||
|
||||
- (void)testSimpleNormalization {
|
||||
NSString *normalized = [@"Whoo %{%}{^}{SHIFT}+ {SPACE}{ENTER}^V%V~T" normalizedAutotypeSequence];
|
||||
XCTAssertTrue([normalized isEqualToString:@"Whoo{SPACE}{ALT}{%}{^}{SHIFT}{SHIFT}{SPACE}{SPACE}{ENTER}{CONTROL}V{ALT}V{ENTER}T"]);
|
||||
}
|
||||
|
||||
- (void)testCommandRepetition {
|
||||
NSString *normalized = [@"Whoo %{% 2}{^}{SHIFT 5}+ {SPACE}{ENTER}^V%V~T" normalizedAutotypeSequence];
|
||||
XCTAssertTrue([normalized isEqualToString:@"Whoo{SPACE}{ALT}{%}{%}{^}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SPACE}{SPACE}{ENTER}{CONTROL}V{ALT}V{ENTER}T"]);
|
||||
normalized = [@"{TAB 5}TAB{TAB}{SHIFT}{SHIFT 10}ENTER{ENTER}{%%}" normalizedAutotypeSequence];
|
||||
XCTAssertTrue([normalized isEqualToString:@"{TAB}{TAB}{TAB}{TAB}{TAB}TAB{TAB}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}{SHIFT}ENTER{ENTER}{%%}"]);
|
||||
}
|
||||
|
||||
- (void)testeBracketValidation {
|
||||
XCTAssertFalse([@"{BOOO}NO-COMMAND{TAB}{WHOO}{WHOO}{SPACE}!!!thisIsFun{{MISMATCH!!!}" validateCommmand]);
|
||||
XCTAssertFalse([@"{{}}}}" validateCommmand]);
|
||||
XCTAssertFalse([@"{}{}{{{}{{{{{{}}" validateCommmand]);
|
||||
XCTAssertTrue([@"{}{}{}{}{}{ }ThisIsValid{}{STOP}" validateCommmand]);
|
||||
}
|
||||
|
||||
- (void)testCommandCreation {
|
||||
KPKEntry *entry = [[KPKEntry alloc] init];
|
||||
entry.title = @"Title";
|
||||
entry.url = @"www.myurl.com";
|
||||
entry.username = @"{{User{name}}}";
|
||||
entry.password = @"Pass{word}";
|
||||
|
||||
MPAutotypeContext *context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"{USERNAME}{TAB}{PASSWORD}{ENTER}"];
|
||||
NSArray *commands = [MPAutotypeCommand commandsForContext:context];
|
||||
|
||||
XCTAssert([commands count] == 4);
|
||||
XCTAssert([commands[0] isKindOfClass:[MPAutotypePaste class]]);
|
||||
XCTAssert([commands[1] isKindOfClass:[MPAutotypeKeyPress class]]);
|
||||
XCTAssert([commands[2] isKindOfClass:[MPAutotypePaste class]]);
|
||||
XCTAssert([commands[3] isKindOfClass:[MPAutotypeKeyPress class]]);
|
||||
|
||||
context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"{DELAY=5}{VKEY-NX 1}{VKEY-EX 200}{DELAY 5}{VKEY 300}"];
|
||||
commands = [MPAutotypeCommand commandsForContext:context];
|
||||
|
||||
context = [[MPAutotypeContext alloc] initWithEntry:entry andSequence:@"^T{USERNAME}%+^{TAB}Whoo{PASSWORD}{ENTER}"];
|
||||
commands = [MPAutotypeCommand commandsForContext:context];
|
||||
|
||||
|
||||
//XCTAssert([commands count] == 5);
|
||||
}
|
||||
@end
|
||||
Reference in New Issue
Block a user