diff --git a/KeePassKit b/KeePassKit index ba0900e3..178ac05c 160000 --- a/KeePassKit +++ b/KeePassKit @@ -1 +1 @@ -Subproject commit ba0900e35faef158a5cd1833c60e3d05db80610a +Subproject commit 178ac05ceeff4577e890761715d763ea83e19bc7 diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 22af0baa..12c4072c 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -235,6 +235,7 @@ 4CCEDE2A179F203B008402BE /* MPOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCEDE29179F203B008402BE /* MPOutlineView.m */; }; 4CCEDE2E179F213B008402BE /* MPNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCEDE2D179F213B008402BE /* MPNotifications.m */; }; 4CCEDE32179F5B6C008402BE /* KPKDataStreamReader.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCEDE31179F5B6C008402BE /* KPKDataStreamReader.m */; }; + 4CD25F9318B17A17006098E9 /* KPKTestUUIDAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CD25F9218B17A17006098E9 /* KPKTestUUIDAdditions.m */; }; 4CD2B9061849424B0051B395 /* MPAutotypeContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CD2B9051849424B0051B395 /* MPAutotypeContext.m */; }; 4CD3ABBA178F71B50073F5C5 /* KPKTree.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CD3ABB4178F71B50073F5C5 /* KPKTree.m */; }; 4CD3ABBF178F72610073F5C5 /* KPKEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CD3ABBE178F72610073F5C5 /* KPKEntry.m */; }; @@ -756,6 +757,7 @@ 4CCEDE2F179F550D008402BE /* KPKTreeReading.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KPKTreeReading.h; sourceTree = ""; }; 4CCEDE30179F5B6C008402BE /* KPKDataStreamReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KPKDataStreamReader.h; sourceTree = ""; }; 4CCEDE31179F5B6C008402BE /* KPKDataStreamReader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKDataStreamReader.m; sourceTree = ""; }; + 4CD25F9218B17A17006098E9 /* KPKTestUUIDAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKTestUUIDAdditions.m; sourceTree = ""; }; 4CD2B9041849424B0051B395 /* MPAutotypeContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAutotypeContext.h; sourceTree = ""; }; 4CD2B9051849424B0051B395 /* MPAutotypeContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAutotypeContext.m; sourceTree = ""; }; 4CD3ABB2178F71B50073F5C5 /* KPKVersion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KPKVersion.h; path = Format/KPKVersion.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; @@ -1238,6 +1240,7 @@ 4C6FDD2017BC4F4C004AEEC8 /* KPKTestPlaceholder.m */, 4CBA561517C2EA4900CE13D3 /* KPKTestXmlWriting.m */, 4C473A7E18AFD6340073FD2E /* KPKTestReference.m */, + 4CD25F9218B17A17006098E9 /* KPKTestUUIDAdditions.m */, ); path = MacPassTests; sourceTree = ""; @@ -2033,6 +2036,7 @@ 4C45FB2D178E0BCB0010007D /* MPDatabaseLoading.m in Sources */, 4C45FB30178E0CE20010007D /* MPDatabaseCreation.m in Sources */, 4C473A7F18AFD6340073FD2E /* KPKTestReference.m in Sources */, + 4CD25F9318B17A17006098E9 /* KPKTestUUIDAdditions.m in Sources */, 4C19E503178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m in Sources */, 4C305F3C179A19F90082334F /* KPKIconLoading.m in Sources */, 4C1842B8179B348600E2F5BC /* KPKTestLegacyLoading.m in Sources */, diff --git a/MacPassTests/KPKTestReference.m b/MacPassTests/KPKTestReference.m index e6d162b7..dd463655 100644 --- a/MacPassTests/KPKTestReference.m +++ b/MacPassTests/KPKTestReference.m @@ -7,6 +7,10 @@ // #import + +#import "KPKTree.h" +#import "KPKGroup.h" +#import "KPKEntry.h" #import "NSString+Commands.h" @interface KPKTestReference : XCTestCase @@ -16,8 +20,40 @@ @implementation KPKTestReference - (void)testCorrectReference { - NSString *reference = @"This is some nice stuff {REF:T@U:blubber} and another Reference {REF:U@I:2687345AASTA}"; - [reference resolveReferencesWithTree:nil]; + KPKTree *tree = [[KPKTree alloc] init]; + KPKGroup *group = [[KPKGroup alloc] init]; + KPKEntry *entry1 = [[KPKEntry alloc] init]; + KPKEntry *entry2 = [[KPKEntry alloc] init]; + entry1.title = @"-Entry1Title-"; + NSString *title2 = [[NSString alloc] initWithFormat:@"Nothing{REF:T@I:%@}Changed", entry1.uuid.UUIDString]; + entry2.title = title2; + entry2.url = @"-Entry2URL-"; + + [group addEntry:entry1]; + [group addEntry:entry2]; + tree.root = group; + + NSString *result = [entry2.title resolveReferencesWithTree:tree]; + XCTAssertTrue([result isEqualToString:@"Nothing-Entry1Title-Changed"], @"Replaced Strings should match"); +} + +- (void)testRecursiveReference{ + KPKTree *tree = [[KPKTree alloc] init]; + KPKGroup *group = [[KPKGroup alloc] init]; + KPKEntry *entry1 = [[KPKEntry alloc] init]; + KPKEntry *entry2 = [[KPKEntry alloc] init]; + NSString *title1 = [[NSString alloc] initWithFormat:@"Title1{REF:A@I:%@}", entry2.uuid.UUIDString]; + entry1.title = title1; // References URL of entry 2 + NSString *title2 = [[NSString alloc] initWithFormat:@"Nothing{REF:T@I:%@}Changed", entry1.uuid.UUIDString]; + entry2.title = title2; // Refernces Title of entry 1 + 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)testWrongRefernceFormat { diff --git a/MacPassTests/KPKTestUUIDAdditions.m b/MacPassTests/KPKTestUUIDAdditions.m new file mode 100644 index 00000000..b6bd1cd1 --- /dev/null +++ b/MacPassTests/KPKTestUUIDAdditions.m @@ -0,0 +1,23 @@ +// +// KPKTestUUIDAdditions.m +// MacPass +// +// Created by Michael Starke on 16.02.14. +// Copyright (c) 2014 HicknHack Software GmbH. All rights reserved. +// + +#import +#import "NSUUID+KeePassKit.h" +@interface KPKTestUUIDAdditions : XCTestCase + +@end + +@implementation KPKTestUUIDAdditions + +- (void)testUndelemitedUUID { + NSUUID *uuid1 = [[NSUUID alloc] initWithUUIDString:@"31C1F2E6-BF71-4350-BE58-05216AFC5AFF"]; + NSUUID *uuid2 = [[NSUUID alloc] initWithUndelemittedUUIDString:@"31C1F2E6BF714350BE5805216AFC5AFF"]; + XCTAssertTrue([uuid1 isEqual:uuid2], @"UUIDs shoudl match"); +} + +@end