From b913d377971c122634666f8a5b42c6b0b1e7944c Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 5 Aug 2013 21:26:06 +0200 Subject: [PATCH] Added loading tests for meta entries Added Test KDB database with custom icon --- KeePassKit | 2 +- MacPass.xcodeproj/project.pbxproj | 24 +++++++++ MacPassTests/Databases/KDB1_KeePassX_test.kdb | Bin 0 -> 2300 bytes MacPassTests/KPKLegacyLoadingTest.h | 8 +-- MacPassTests/KPKLegacyLoadingTest.m | 39 +++++++++------ MacPassTests/KPKTestHexColor.h | 13 +++++ MacPassTests/KPKTestHexColor.m | 47 ++++++++++++++++++ MacPassTests/KPKTestNSCoding.m | 2 +- MacPassTests/KPKTestNSCopying.m | 2 +- MiniKeePassLib | 2 +- 10 files changed, 114 insertions(+), 25 deletions(-) create mode 100644 MacPassTests/Databases/KDB1_KeePassX_test.kdb create mode 100644 MacPassTests/KPKTestHexColor.h create mode 100644 MacPassTests/KPKTestHexColor.m diff --git a/KeePassKit b/KeePassKit index cad68d0f..280e601d 160000 --- a/KeePassKit +++ b/KeePassKit @@ -1 +1 @@ -Subproject commit cad68d0f6bf914b394551827ab8e4b2fc3f2fa25 +Subproject commit 280e601dfc63081df30ae33ed829c804a0f5e1c4 diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 87ae9645..71780656 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -129,6 +129,11 @@ 4C5FE9AE17843CE20001D5A8 /* MPSelectedAttachmentTableCellView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C5FE9AD17843CE20001D5A8 /* MPSelectedAttachmentTableCellView.m */; }; 4C61EA0316D2FD0800AC519E /* MPOutlineViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C61EA0216D2FD0800AC519E /* MPOutlineViewController.m */; }; 4C61EA0516D2FFE200AC519E /* OutlineView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C61EA0416D2FFE200AC519E /* OutlineView.xib */; }; + 4C6366AC17AF1E0100AAF17D /* NSColor+KeePassKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6366AB17AF1E0100AAF17D /* NSColor+KeePassKit.m */; }; + 4C6366AF17AF207600AAF17D /* KPKTestHexColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6366AE17AF207600AAF17D /* KPKTestHexColor.m */; }; + 4C6366B317AFB52500AAF17D /* CustomIcon_Password_1234.kdbx in Resources */ = {isa = PBXBuildFile; fileRef = 4C6366B017AFB52500AAF17D /* CustomIcon_Password_1234.kdbx */; }; + 4C6366B417AFB52500AAF17D /* CustomIcon_Password_1234.xml in Resources */ = {isa = PBXBuildFile; fileRef = 4C6366B117AFB52500AAF17D /* CustomIcon_Password_1234.xml */; }; + 4C6366B517AFB52500AAF17D /* KDB1_KeePassX_test.kdb in Resources */ = {isa = PBXBuildFile; fileRef = 4C6366B217AFB52500AAF17D /* KDB1_KeePassX_test.kdb */; }; 4C63B8FB17A3154D0091BD72 /* MPContextToolbarButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C63B8FA17A3154D0091BD72 /* MPContextToolbarButton.m */; }; 4C65C79C16DD283900E32CFF /* MPToolbarButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C65C79B16DD283900E32CFF /* MPToolbarButton.m */; }; 4C65FAE916D16DDB006E0577 /* MPPasswordInputController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C65FAE716D16DDB006E0577 /* MPPasswordInputController.m */; }; @@ -504,6 +509,13 @@ 4C61EA0116D2FD0800AC519E /* MPOutlineViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPOutlineViewController.h; sourceTree = ""; }; 4C61EA0216D2FD0800AC519E /* MPOutlineViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOutlineViewController.m; sourceTree = ""; }; 4C61EA0416D2FFE200AC519E /* OutlineView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OutlineView.xib; sourceTree = ""; }; + 4C6366AA17AF1E0100AAF17D /* NSColor+KeePassKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSColor+KeePassKit.h"; sourceTree = ""; }; + 4C6366AB17AF1E0100AAF17D /* NSColor+KeePassKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSColor+KeePassKit.m"; sourceTree = ""; }; + 4C6366AD17AF207600AAF17D /* KPKTestHexColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KPKTestHexColor.h; sourceTree = ""; }; + 4C6366AE17AF207600AAF17D /* KPKTestHexColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKTestHexColor.m; sourceTree = ""; }; + 4C6366B017AFB52500AAF17D /* CustomIcon_Password_1234.kdbx */ = {isa = PBXFileReference; lastKnownFileType = file; name = CustomIcon_Password_1234.kdbx; path = Databases/CustomIcon_Password_1234.kdbx; sourceTree = ""; }; + 4C6366B117AFB52500AAF17D /* CustomIcon_Password_1234.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = CustomIcon_Password_1234.xml; path = Databases/CustomIcon_Password_1234.xml; sourceTree = ""; }; + 4C6366B217AFB52500AAF17D /* KDB1_KeePassX_test.kdb */ = {isa = PBXFileReference; lastKnownFileType = file; name = KDB1_KeePassX_test.kdb; path = Databases/KDB1_KeePassX_test.kdb; sourceTree = ""; }; 4C63B8F917A3154D0091BD72 /* MPContextToolbarButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPContextToolbarButton.h; sourceTree = ""; }; 4C63B8FA17A3154D0091BD72 /* MPContextToolbarButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPContextToolbarButton.m; sourceTree = ""; }; 4C65C79A16DD283900E32CFF /* MPToolbarButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPToolbarButton.h; sourceTree = ""; }; @@ -876,6 +888,9 @@ 4C18F9AC178E123200890BCE /* Databases */ = { isa = PBXGroup; children = ( + 4C6366B017AFB52500AAF17D /* CustomIcon_Password_1234.kdbx */, + 4C6366B117AFB52500AAF17D /* CustomIcon_Password_1234.xml */, + 4C6366B217AFB52500AAF17D /* KDB1_KeePassX_test.kdb */, 4C19E4FF178E26EF002F2CD0 /* Test_Password_1234.kdbx */, 4C18F9AA178E122500890BCE /* Test_Password_1234.kdb */, ); @@ -1202,6 +1217,8 @@ 4CECB31617AC326D00EAFB0F /* KPKLegacyWritingTest.m */, 4CAC614117AD319200023F9E /* KPKTestXmlParsing.h */, 4CAC614217AD319200023F9E /* KPKTestXmlParsing.m */, + 4C6366AD17AF207600AAF17D /* KPKTestHexColor.h */, + 4C6366AE17AF207600AAF17D /* KPKTestHexColor.m */, ); path = MacPassTests; sourceTree = ""; @@ -1584,6 +1601,8 @@ 4C055E73179620BF00BD2BAB /* NSString+CommandString.m */, 4C1842C1179B69E600E2F5BC /* NSData+HashedData.h */, 4C1842C2179B69E700E2F5BC /* NSData+HashedData.m */, + 4C6366AA17AF1E0100AAF17D /* NSColor+KeePassKit.h */, + 4C6366AB17AF1E0100AAF17D /* NSColor+KeePassKit.m */, ); path = Categories; sourceTree = ""; @@ -1803,6 +1822,9 @@ 4C18F9AB178E122500890BCE /* Test_Password_1234.kdb in Resources */, 4C19E500178E26EF002F2CD0 /* Test_Password_1234.kdbx in Resources */, 4C305F3E179A1A760082334F /* image.png in Resources */, + 4C6366B317AFB52500AAF17D /* CustomIcon_Password_1234.kdbx in Resources */, + 4C6366B417AFB52500AAF17D /* CustomIcon_Password_1234.xml in Resources */, + 4C6366B517AFB52500AAF17D /* KDB1_KeePassX_test.kdb in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1895,6 +1917,7 @@ 4C79E80917A9485600AC6CD2 /* KPKTestNSCopying.m in Sources */, 4CECB31717AC326D00EAFB0F /* KPKLegacyWritingTest.m in Sources */, 4CAC614317AD319200023F9E /* KPKTestXmlParsing.m in Sources */, + 4C6366AF17AF207600AAF17D /* KPKTestHexColor.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2100,6 +2123,7 @@ 4CFB5E9F17AAD20200D9B10C /* Kdb4Group+Undo.m in Sources */, 4CE3E62617AB0D2D00D9E4B4 /* MPAttachmentTableDataSource.m in Sources */, 4CF4FEE017AEA4A400712774 /* UUID+Pasterboard.m in Sources */, + 4C6366AC17AF1E0100AAF17D /* NSColor+KeePassKit.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/MacPassTests/Databases/KDB1_KeePassX_test.kdb b/MacPassTests/Databases/KDB1_KeePassX_test.kdb new file mode 100644 index 0000000000000000000000000000000000000000..82e605ce4daa1ee2cf3eef4b84b8751ef0fd3a9b GIT binary patch literal 2300 zcmV%I zgdg1l000060000us+A#&8jAKW=1fL2Oge*Bo{ErgGxe`D{HD`0g&*1!CQNRdQnoNw z@nZaokoh_kbvhGMhNU!FCN`(KjoZ>t!vFx_t^uK+Rf;q!!B586DP}Y|&(+s50P4ag z0^s1GV^LgH@K`-{g2`5DEPO_>TcoK1rk0Eey~8HrjY6wo&#!ULn;x>Y)}8yEmTFDW z=@LZyz{Kp__s%Bxccaos;PL~t{+7M7_44}iZSke?{Y^b}2$Ts?%V z)0eu@wMzMbE$?D;QR241l5x#C2)m0J?~w40(W{YMaNp)aap2QGvU4K$Rtd~#ieS5q zDQ@&f89P3*lhXT4nZ8(fR1M7*W9JXURDf`Ui3n{2lErY{p7ElfIan|36kFyLuiVzGT6lB}o?OT?V=2_E>1YSfTT6 z#kpytkRK@p+G)NBg_3iXu%;J_u+cq2YewwSef%%lm00){s{C{qV@k+;>#N9B$C<0; zl1X-j$+~48Zv=0!9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?!dz*J*)7heb)*jDsBD-?o0#Q^jOTp2g|4&jj+^4{j__i=#n05 zRi5yP9E#7$@7oxExwC`BZkPh*eX*-HG3vM-2wCSj_6D)>3m|PKae^@`F)HM84*jmn zFq_|B5R(FfCNKFf);N{L7AJ(QSg(M2YR}A4AS=dDV7vc-uD^5%LjE#?bY#5$UcH(+ WZO+8`JY=R(#-fUE`_CS>V@3T14vvEW literal 0 HcmV?d00001 diff --git a/MacPassTests/KPKLegacyLoadingTest.h b/MacPassTests/KPKLegacyLoadingTest.h index d4199ae1..ec680d8c 100644 --- a/MacPassTests/KPKLegacyLoadingTest.h +++ b/MacPassTests/KPKLegacyLoadingTest.h @@ -8,12 +8,6 @@ #import -@class KPKPassword; - -@interface KPKLegacyLoadingTest : SenTestCase { - @private - NSData *_data; - KPKPassword *_password; -} +@interface KPKLegacyLoadingTest : SenTestCase @end diff --git a/MacPassTests/KPKLegacyLoadingTest.m b/MacPassTests/KPKLegacyLoadingTest.m index f14d095e..f64c92a4 100644 --- a/MacPassTests/KPKLegacyLoadingTest.m +++ b/MacPassTests/KPKLegacyLoadingTest.m @@ -7,32 +7,26 @@ // #import "KPKLegacyLoadingTest.h" + #import "KPKTree+Serializing.h" #import "KPKPassword.h" +#import "KPKMetaData.h" +#import "KPKIcon.h" + #import "KPKErrors.h" @implementation KPKLegacyLoadingTest -- (void)setUp { - NSBundle *myBundle = [NSBundle bundleForClass:[self class]]; - NSURL *url = [myBundle URLForResource:@"Test_Password_1234" withExtension:@"kdb"]; - _data = [NSData dataWithContentsOfURL:url]; - _password = [[KPKPassword alloc] initWithPassword:@"1234" key:nil]; -} - -- (void)tearDown { - _data = nil; - _password = nil; -} - - (void)testValidFile { - KPKTree *tree = [[KPKTree alloc] initWithData:_data password:_password error:NULL]; + KPKPassword *password = [[KPKPassword alloc] initWithPassword:@"1234" key:nil]; + NSData *data = [self _loadTestDataBase:@"Test_Password_1234" extension:@"kdb"]; + KPKTree *tree = [[KPKTree alloc] initWithData:data password:password error:NULL]; STAssertNotNil(tree, @"Loading should result in a tree object"); } - (void)testInvalidFile { NSError *error; - uint8 bytes[] = {0x00,0x11,0x22,0x33,0x44}; + uint8_t bytes[] = {0x00,0x11,0x22,0x33,0x44}; NSData *data = [NSData dataWithBytes:bytes length:5]; KPKTree *tree = [[KPKTree alloc] initWithData:data password:nil error:&error]; STAssertNil(tree, @"Tree should be nil with invalid data"); @@ -40,4 +34,21 @@ STAssertTrue(KPKErrorUnknownFileFormat == [error code], @"Error should be Unknown file format"); } + +- (void)testMetaParsing { + NSData *data = [self _loadTestDataBase:@"KDB1_KeePassX_test" extension:@"kdb"]; + KPKPassword *password = [[KPKPassword alloc] initWithPassword:@"test" key:nil]; + KPKTree *tree = [[KPKTree alloc] initWithData:data password:password error:NULL]; + STAssertNotNil(tree, @"Tree shoudl be loaded" ); + + KPKIcon *icon = [tree.metaData.customIcons lastObject]; + STAssertNotNil(icon, @"Should load one Icon"); +} + +- (NSData *)_loadTestDataBase:(NSString *)name extension:(NSString *)extension { + NSBundle *myBundle = [NSBundle bundleForClass:[self class]]; + NSURL *url = [myBundle URLForResource:name withExtension:extension]; + return [NSData dataWithContentsOfURL:url]; +} + @end diff --git a/MacPassTests/KPKTestHexColor.h b/MacPassTests/KPKTestHexColor.h new file mode 100644 index 00000000..5cfe2a77 --- /dev/null +++ b/MacPassTests/KPKTestHexColor.h @@ -0,0 +1,13 @@ +// +// KPKTestHexColor.h +// MacPass +// +// Created by Michael Starke on 05.08.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import + +@interface KPKTestHexColor : SenTestCase + +@end diff --git a/MacPassTests/KPKTestHexColor.m b/MacPassTests/KPKTestHexColor.m new file mode 100644 index 00000000..3612c3cd --- /dev/null +++ b/MacPassTests/KPKTestHexColor.m @@ -0,0 +1,47 @@ +// +// KPKTestHexColor.m +// MacPass +// +// Created by Michael Starke on 05.08.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import "KPKTestHexColor.h" + +#import "NSColor+KeePassKit.h" + +@implementation KPKTestHexColor + +- (void)testHexToColor { + NSString *redHex = @"00ff0000"; + NSString *blueHex = @"000000ff"; + NSString *greeHex = @"0000ff00"; + + NSColor *red = [NSColor colorWithHexString:redHex]; + NSColor *blue = [NSColor colorWithHexString:blueHex]; + NSColor *green = [NSColor colorWithHexString:greeHex]; + + STAssertEquals([red redComponent], 1.0, @"Red color should have 100% red"); + STAssertEquals([red blueComponent], 0.0, @"Red color should have 0% blue"); + STAssertEquals([red greenComponent], 0.0, @"Red color should have 0% green"); + + STAssertEquals([blue redComponent], 0.0, @"Blue color should have 0% red"); + STAssertEquals([blue blueComponent], 1.0, @"Blue color should have 100% blue"); + STAssertEquals([blue greenComponent], 0.0, @"Blue color should have 0% green"); + + STAssertEquals([green redComponent], 0.0, @"Green color should have 0% red"); + STAssertEquals([green blueComponent], 0.0, @"Green color should have 0% blue"); + STAssertEquals([green greenComponent], 1.0, @"Green color should have 100% green"); +} + +- (void)testColorRefReading { + uint32_t colorBytes = 0x000000ff; + uint32_t swappedData = colorBytes;//CFSwapInt32(colorBytes); + NSData *colorData = [NSData dataWithBytesNoCopy:&swappedData length:sizeof(uint32_t) freeWhenDone:NO]; + NSColor *color = [NSColor colorWithData:colorData]; + STAssertEquals([color redComponent], 1.0, @"Red 100%"); + STAssertEquals([color blueComponent], 0.0, @"Blue 0%"); + STAssertEquals([color greenComponent], 0.0, @"Green 0%"); +} + +@end diff --git a/MacPassTests/KPKTestNSCoding.m b/MacPassTests/KPKTestNSCoding.m index 3c9e4f3e..4c3f5688 100644 --- a/MacPassTests/KPKTestNSCoding.m +++ b/MacPassTests/KPKTestNSCoding.m @@ -35,7 +35,7 @@ entry.username = @"Username"; entry.password = @"Password"; - uint8 bytes[] = { 0xFF, 0x00, 0xFF, 0x00, 0xFF }; + uint8_t bytes[] = { 0xFF, 0x00, 0xFF, 0x00, 0xFF }; NSData *data = [[NSData alloc] initWithBytes:bytes length:5]; KPKBinary *binary = [[KPKBinary alloc] init]; diff --git a/MacPassTests/KPKTestNSCopying.m b/MacPassTests/KPKTestNSCopying.m index 2998ff01..9bea9cf1 100644 --- a/MacPassTests/KPKTestNSCopying.m +++ b/MacPassTests/KPKTestNSCopying.m @@ -36,7 +36,7 @@ entry.username = @"Username"; entry.password = @"Password"; - uint8 bytes[] = { 0xFF, 0x00, 0xFF, 0x00, 0xFF }; + uint8_t bytes[] = { 0xFF, 0x00, 0xFF, 0x00, 0xFF }; NSData *data = [[NSData alloc] initWithBytes:bytes length:5]; KPKBinary *binary = [[KPKBinary alloc] init]; diff --git a/MiniKeePassLib b/MiniKeePassLib index f8829af2..8abd6117 160000 --- a/MiniKeePassLib +++ b/MiniKeePassLib @@ -1 +1 @@ -Subproject commit f8829af211aa784a298dca28d67f3a0c2c7d7438 +Subproject commit 8abd611741833857b64d41398e441f6175fca0a8