From 3d14904640b1d7e5eb2eab57725d44bc550d5e1a Mon Sep 17 00:00:00 2001 From: michael starke Date: Thu, 11 Jul 2013 01:51:20 +0200 Subject: [PATCH] Key/Password set/reset test --- MacPass.xcodeproj/project.pbxproj | 22 +++++--- MacPass/MacPass-Info.plist | 2 +- .../Databases/Test_Password_1234.kdbx | Bin 0 -> 1118 bytes MacPassTests/MPDatabaseCreation.m | 12 ++++- ...abaseLoadingTest.h => MPDatabaseLoading.h} | 2 +- ...abaseLoadingTest.m => MPDatabaseLoading.m} | 26 +++++++--- MacPassTests/MPDatabasePasswordAndKeyfile.h | 18 +++++++ MacPassTests/MPDatabasePasswordAndKeyfile.m | 47 ++++++++++++++++++ 8 files changed, 112 insertions(+), 17 deletions(-) create mode 100644 MacPassTests/Databases/Test_Password_1234.kdbx rename MacPassTests/{MPDatabaseLoadingTest.h => MPDatabaseLoading.h} (81%) rename MacPassTests/{MPDatabaseLoadingTest.m => MPDatabaseLoading.m} (51%) create mode 100644 MacPassTests/MPDatabasePasswordAndKeyfile.h create mode 100644 MacPassTests/MPDatabasePasswordAndKeyfile.m diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 3a128d0b..4d06d971 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -13,6 +13,8 @@ 4C10412C178CDD44001B5239 /* NSDate+Humanized.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C10412B178CDD44001B5239 /* NSDate+Humanized.m */; }; 4C16BA6217879A3C002B42BD /* MPPasswordStringFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C16BA6117879A3C002B42BD /* MPPasswordStringFormatter.m */; }; 4C18F9AB178E122500890BCE /* Test_Password_1234.kdb in Resources */ = {isa = PBXBuildFile; fileRef = 4C18F9AA178E122500890BCE /* Test_Password_1234.kdb */; }; + 4C19E500178E26EF002F2CD0 /* Test_Password_1234.kdbx in Resources */ = {isa = PBXBuildFile; fileRef = 4C19E4FF178E26EF002F2CD0 /* Test_Password_1234.kdbx */; }; + 4C19E503178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C19E502178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m */; }; 4C1DDCDD1711ECEB00C98DA3 /* PasswordCreatorWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C1DDCDC1711ECEB00C98DA3 /* PasswordCreatorWindow.xib */; }; 4C22040D1746ED160054C916 /* KdbGroup+Undo.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C22040C1746ED160054C916 /* KdbGroup+Undo.m */; }; 4C245B76176E1E3D0086100E /* DDData.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C245A6A176E1E3C0086100E /* DDData.m */; }; @@ -68,7 +70,7 @@ 4C45FB1C178E09ED0010007D /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C45FB1B178E09ED0010007D /* SenTestingKit.framework */; }; 4C45FB1D178E09ED0010007D /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C77E36615B84A240093A587 /* Cocoa.framework */; }; 4C45FB23178E09ED0010007D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4C45FB21178E09ED0010007D /* InfoPlist.strings */; }; - 4C45FB2D178E0BCB0010007D /* MPDatabaseLoadingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C45FB2C178E0BCB0010007D /* MPDatabaseLoadingTest.m */; }; + 4C45FB2D178E0BCB0010007D /* MPDatabaseLoading.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C45FB2C178E0BCB0010007D /* MPDatabaseLoading.m */; }; 4C45FB30178E0CE20010007D /* MPDatabaseCreation.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C45FB2F178E0CE20010007D /* MPDatabaseCreation.m */; }; 4C46B88517063A070046109A /* NSString+MPPasswordCreation.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C46B88417063A070046109A /* NSString+MPPasswordCreation.m */; }; 4C46B88817063A170046109A /* NSString+PasswordStrength.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C46B88717063A170046109A /* NSString+PasswordStrength.m */; }; @@ -221,6 +223,9 @@ 4C16BA6017879A3C002B42BD /* MPPasswordStringFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPPasswordStringFormatter.h; sourceTree = ""; }; 4C16BA6117879A3C002B42BD /* MPPasswordStringFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPPasswordStringFormatter.m; sourceTree = ""; }; 4C18F9AA178E122500890BCE /* Test_Password_1234.kdb */ = {isa = PBXFileReference; lastKnownFileType = file; name = Test_Password_1234.kdb; path = Databases/Test_Password_1234.kdb; sourceTree = ""; }; + 4C19E4FF178E26EF002F2CD0 /* Test_Password_1234.kdbx */ = {isa = PBXFileReference; lastKnownFileType = file; name = Test_Password_1234.kdbx; path = Databases/Test_Password_1234.kdbx; sourceTree = ""; }; + 4C19E501178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDatabasePasswordAndKeyfile.h; sourceTree = ""; }; + 4C19E502178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDatabasePasswordAndKeyfile.m; sourceTree = ""; }; 4C1DDCDC1711ECEB00C98DA3 /* PasswordCreatorWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PasswordCreatorWindow.xib; sourceTree = ""; }; 4C22040B1746ED160054C916 /* KdbGroup+Undo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KdbGroup+Undo.h"; sourceTree = ""; }; 4C22040C1746ED160054C916 /* KdbGroup+Undo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "KdbGroup+Undo.m"; sourceTree = ""; }; @@ -322,8 +327,8 @@ 4C45FB20178E09ED0010007D /* MacPassTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "MacPassTests-Info.plist"; sourceTree = ""; }; 4C45FB22178E09ED0010007D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 4C45FB27178E09ED0010007D /* MacPassTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MacPassTests-Prefix.pch"; sourceTree = ""; }; - 4C45FB2B178E0BCB0010007D /* MPDatabaseLoadingTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDatabaseLoadingTest.h; sourceTree = ""; }; - 4C45FB2C178E0BCB0010007D /* MPDatabaseLoadingTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDatabaseLoadingTest.m; sourceTree = ""; }; + 4C45FB2B178E0BCB0010007D /* MPDatabaseLoading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDatabaseLoading.h; sourceTree = ""; }; + 4C45FB2C178E0BCB0010007D /* MPDatabaseLoading.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDatabaseLoading.m; sourceTree = ""; }; 4C45FB2E178E0CE20010007D /* MPDatabaseCreation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDatabaseCreation.h; sourceTree = ""; }; 4C45FB2F178E0CE20010007D /* MPDatabaseCreation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDatabaseCreation.m; sourceTree = ""; }; 4C46B88317063A070046109A /* NSString+MPPasswordCreation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MPPasswordCreation.h"; sourceTree = ""; }; @@ -665,6 +670,7 @@ 4C18F9AC178E123200890BCE /* Databases */ = { isa = PBXGroup; children = ( + 4C19E4FF178E26EF002F2CD0 /* Test_Password_1234.kdbx */, 4C18F9AA178E122500890BCE /* Test_Password_1234.kdb */, ); name = Databases; @@ -924,10 +930,12 @@ isa = PBXGroup; children = ( 4C18F9AC178E123200890BCE /* Databases */, - 4C45FB2B178E0BCB0010007D /* MPDatabaseLoadingTest.h */, - 4C45FB2C178E0BCB0010007D /* MPDatabaseLoadingTest.m */, + 4C45FB2B178E0BCB0010007D /* MPDatabaseLoading.h */, + 4C45FB2C178E0BCB0010007D /* MPDatabaseLoading.m */, 4C45FB2E178E0CE20010007D /* MPDatabaseCreation.h */, 4C45FB2F178E0CE20010007D /* MPDatabaseCreation.m */, + 4C19E501178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.h */, + 4C19E502178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m */, 4C45FB1F178E09ED0010007D /* Supporting Files */, ); path = MacPassTests; @@ -1413,6 +1421,7 @@ files = ( 4C45FB23178E09ED0010007D /* InfoPlist.strings in Resources */, 4C18F9AB178E122500890BCE /* Test_Password_1234.kdb in Resources */, + 4C19E500178E26EF002F2CD0 /* Test_Password_1234.kdbx in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1502,8 +1511,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4C45FB2D178E0BCB0010007D /* MPDatabaseLoadingTest.m in Sources */, + 4C45FB2D178E0BCB0010007D /* MPDatabaseLoading.m in Sources */, 4C45FB30178E0CE20010007D /* MPDatabaseCreation.m in Sources */, + 4C19E503178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/MacPass/MacPass-Info.plist b/MacPass/MacPass-Info.plist index 5c4be01a..49e87599 100644 --- a/MacPass/MacPass-Info.plist +++ b/MacPass/MacPass-Info.plist @@ -48,7 +48,7 @@ CFBundleSignature ???? CFBundleVersion - 2403 + 2409 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright diff --git a/MacPassTests/Databases/Test_Password_1234.kdbx b/MacPassTests/Databases/Test_Password_1234.kdbx new file mode 100644 index 0000000000000000000000000000000000000000..fe1036b700428a538b51cfc4d13fb99074cd3502 GIT binary patch literal 1118 zcmV-k1flx_*`k_f`%AR}00RI55CAd3^5(yBLr}h01tDtuTK@wC0096100bZa8I?(9 zv*d`CcT9Y`XB%`vx1jsyhyXocnx+x|@0iZA1t0+Wno$UqMmUCmZ{x)kSM7u=QJUcr zLTq2_2*=J7nZVfw2mnyS00000000LN0DZbQtw?bB#pvuZ`-=_9B?uq@of01Seg6m) z_t66r=oMO~Qi`Gv0$G2zBLi#sTiC%P2_OK0Hj@qtD~oY%Ckfn8zW?^?`=?c>jIlP$YyA`+5E5w zhP^mhu#1(mm)uc%3mn6L4R>s*?R06KLm~D zLIolf0EPkoQ_9}jKJE7Qg9jG>b}5tl{1EL>C0<~3b7LOBjMTyRGmDX^nGltAiSlBF z0TeV4rC=$Y5_Q&Y*+2zJp+i2C_IGodm3IBCApen!kO<_N=FAw5<`V(<@GW17DmA~H zUs;}pw|T8YM)c4Pp?NV;6kl+#0G4vV?9A;jxNI28aK#3iZc{6JU8Mgn1ixXpl`#9q zlUjYxe-;7OBhd1Cm=Az;f2SSgf?0eo>Rq9;UEWppRBZ4Ifqp@YTK(^jE1IjmAS@n5 zx4HB@b9aTGN6XoKl;a^_MJ+r3&xOETYxKMh&h8kF6|O>4xM zd`^PoGpc69E;>m}A$#HaYee>eU@kFt&4YRvSpbYILmrpf! z_|J)1R-xY`30Z+s4Nxop*1@xX1*rHY4@Ng^ZU*5Q^?kv^@u3NElLjIF#WcRqcsaC2 zRB@CfRyBc$y$VwAt1&!cZLIAHt}}SBqHYl<{zG2=m!kTCZakyYQ!9O!?GmV4HPoQ$ zBSj2ag5(@KCa+3JbxMf6>L%mnf`$kTA!jl?#dLGmW_{FZN=N k%Hs9n7Zdq(+z)W#jJlm#lMvgl;Y1{nnp)c^nh literal 0 HcmV?d00001 diff --git a/MacPassTests/MPDatabaseCreation.m b/MacPassTests/MPDatabaseCreation.m index 6ce4963b..396adb59 100644 --- a/MacPassTests/MPDatabaseCreation.m +++ b/MacPassTests/MPDatabaseCreation.m @@ -12,7 +12,13 @@ @implementation MPDatabaseCreation - (void)testCreateDatabaseVersion1 { - STFail(@"Not implemented"); + MPDocument *document = [[MPDocument alloc] initWithVersion:MPDatabaseVersion3]; + STAssertNotNil(document, @"Document should be created"); + STAssertTrue(document.version == MPDatabaseVersion3, @"Database should be Version1"); + STAssertNotNil(document.treeV3, @"Database Tree needs to be Kdb3Tree"); + STAssertNil(document.treeV4, @"Database Tree cannot be Kdb4Tree"); + STAssertTrue(document.isDecrypted, @"Document has to be decrypted new database is created"); + STAssertFalse(document.isSecured, @"Document has no Password/Keyfile and thus is not secured"); } - (void)testCreateDatabaseVersion2 { @@ -20,7 +26,9 @@ STAssertNotNil(document, @"Document should be created"); STAssertTrue(document.version == MPDatabaseVersion4, @"Database should be Version2"); STAssertNotNil(document.treeV4, @"Database Tree needs to be Kdb4Tree"); - STFail(@"Not implemented"); + STAssertNil(document.treeV3, @"Database Tree cannot be Kdb3Tree"); + STAssertTrue(document.isDecrypted, @"Document has to be decrypted new database is created"); + STAssertFalse(document.isSecured, @"Document has no Password/Keyfile and thus is not secured"); } @end diff --git a/MacPassTests/MPDatabaseLoadingTest.h b/MacPassTests/MPDatabaseLoading.h similarity index 81% rename from MacPassTests/MPDatabaseLoadingTest.h rename to MacPassTests/MPDatabaseLoading.h index 58193a3d..5bb02b4f 100644 --- a/MacPassTests/MPDatabaseLoadingTest.h +++ b/MacPassTests/MPDatabaseLoading.h @@ -8,6 +8,6 @@ #import -@interface MPDatabaseLoadingTest : SenTestCase +@interface MPDatabaseLoading : SenTestCase @end diff --git a/MacPassTests/MPDatabaseLoadingTest.m b/MacPassTests/MPDatabaseLoading.m similarity index 51% rename from MacPassTests/MPDatabaseLoadingTest.m rename to MacPassTests/MPDatabaseLoading.m index 0a0a2824..6713eaab 100644 --- a/MacPassTests/MPDatabaseLoadingTest.m +++ b/MacPassTests/MPDatabaseLoading.m @@ -6,11 +6,11 @@ // Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. // -#import "MPDatabaseLoadingTest.h" +#import "MPDatabaseLoading.h" #import "MPDocument.h" -@implementation MPDatabaseLoadingTest +@implementation MPDatabaseLoading - (void)testLoadVersion1 { @@ -20,10 +20,11 @@ MPDocument *document = [[MPDocument alloc] initWithContentsOfURL:url ofType:@"kdb" error:&error]; STAssertNil(error, @"No Error should occur on loading"); STAssertNotNil(document, @"Document cannot be nil"); - STAssertFalse(document.decrypted, @"Document is not decrypted after inital load"); + STAssertFalse(document.isDecrypted, @"Document is not decrypted after inital load"); STAssertTrue([document decryptWithPassword:@"1234" keyFileURL:nil], @"Should decrypt with password"); - STAssertTrue(document.decrypted, @"Document is decrypted if decryptiong succeeds"); + STAssertTrue(document.isDecrypted, @"Document is decrypted if decryptiong succeeds"); STAssertNotNil(document.treeV3, @"Tree shoudl be version1"); + STAssertNil(document.treeV4, @"Tree should not be version2"); STAssertTrue(document.version == MPDatabaseVersion3, @"Internal databse version should be correct"); } @@ -34,13 +35,24 @@ MPDocument *document = [[MPDocument alloc] initWithContentsOfURL:url ofType:@"kdb" error:&error]; STAssertNil(error, @"No Error should occur on loading"); STAssertNotNil(document, @"Document should not be nil"); - STAssertFalse(document.decrypted, @"Document is not decrypted after inital load"); + STAssertFalse(document.isDecrypted, @"Document is not decrypted after inital load"); STAssertFalse([document decryptWithPassword:@"123" keyFileURL:nil], @"Decryption should fail"); - STAssertFalse(document.decrypted, @"Document is not decrypted with wrong password supplied"); + STAssertFalse(document.isDecrypted, @"Document is not decrypted with wrong password supplied"); } - (void)testLoadDatabaseVerions2 { - STFail(@"Not implemented"); + NSBundle *myBundle = [NSBundle bundleForClass:[self class]]; + NSURL *url = [myBundle URLForResource:@"Test_Password_1234" withExtension:@"kdbx"]; + NSError *error = nil; + MPDocument *document = [[MPDocument alloc] initWithContentsOfURL:url ofType:@"kdbx" error:&error]; + STAssertNil(error, @"No Error should occur on loading"); + STAssertNotNil(document, @"Document cannot be nil"); + STAssertFalse(document.isDecrypted, @"Document is not decrypted after inital load"); + STAssertTrue([document decryptWithPassword:@"1234" keyFileURL:nil], @"Should decrypt with password"); + STAssertTrue(document.isDecrypted, @"Document is decrypted if decryptiong succeeds"); + STAssertNil(document.treeV3, @"Tree should not be version1"); + STAssertNotNil(document.treeV4, @"Tree shoud be version2"); + STAssertTrue(document.version == MPDatabaseVersion4, @"Internal database version should be correct"); } @end diff --git a/MacPassTests/MPDatabasePasswordAndKeyfile.h b/MacPassTests/MPDatabasePasswordAndKeyfile.h new file mode 100644 index 00000000..36af89ed --- /dev/null +++ b/MacPassTests/MPDatabasePasswordAndKeyfile.h @@ -0,0 +1,18 @@ +// +// MPDatabasePasswordAndKeyfile.h +// MacPass +// +// Created by Michael Starke on 11.07.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import + +@class MPDocument; + +@interface MPDatabasePasswordAndKeyfile : SenTestCase { + MPDocument *_databaseV3; + MPDocument *_databaseV4; +} + +@end diff --git a/MacPassTests/MPDatabasePasswordAndKeyfile.m b/MacPassTests/MPDatabasePasswordAndKeyfile.m new file mode 100644 index 00000000..6fe57c19 --- /dev/null +++ b/MacPassTests/MPDatabasePasswordAndKeyfile.m @@ -0,0 +1,47 @@ +// +// MPDatabasePasswordAndKeyfile.m +// MacPass +// +// Created by Michael Starke on 11.07.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import "MPDatabasePasswordAndKeyfile.h" + +#import "MPDocument.h" + +@implementation MPDatabasePasswordAndKeyfile + +- (void)setUp { + _databaseV3 = [[MPDocument alloc] initWithVersion:MPDatabaseVersion3]; + _databaseV4 = [[MPDocument alloc] initWithVersion:MPDatabaseVersion4]; +} + +- (void)tearDown { + _databaseV3 = nil; + _databaseV4 = nil; +} + +- (void)testSetPassword { + STAssertTrue([_databaseV3.password length] == 0, @"Password should not be set"); + STAssertNil(_databaseV3.key, @"Keyfile should not be set"); + STAssertFalse(_databaseV3.isSecured, @"Database without password is not secure"); + _databaseV3.password = @"test"; + STAssertTrue([_databaseV3.password isEqualToString:@"test"], @"Password should be set"); + STAssertTrue(_databaseV3.isSecured, @"Database with password is secured"); + _databaseV3.password = nil; + STAssertFalse(_databaseV3.isSecured, @"Database with removed password is not secure anymore"); +} + +- (void)testSetKeyfile { + STAssertTrue([_databaseV3.password length] == 0, @"Password should not be set"); + STAssertNil(_databaseV3.key, @"Keyfile should not be set"); + STAssertFalse(_databaseV3.isSecured, @"Database without keyfile is not secure"); + _databaseV3.key = [NSURL URLWithString:@"noKeyFile"]; + STAssertTrue(_databaseV3.isSecured, @"Database with keyfile is secured"); + _databaseV3.key = nil; + STAssertFalse(_databaseV3.isSecured, @"Database with removed keyfile is not secure anymore"); +} + + +@end