From accfdbc4f2673fa6f165645ba8305ea62c8c7aff Mon Sep 17 00:00:00 2001 From: michael starke Date: Fri, 20 Sep 2013 01:54:02 +0200 Subject: [PATCH] Fixed MPDocument tests to work again --- MacPass.xcodeproj/project.pbxproj | 2 + MacPass/Base.lproj/InspectorView.xib | 114 +++++++++++++++++++- MacPass/MacPass-Info.plist | 4 +- MacPassTests/MPDatabaseCreation.m | 21 +--- MacPassTests/MPDatabaseLoading.m | 21 ++-- MacPassTests/MPDatabasePasswordAndKeyfile.h | 3 +- MacPassTests/MPDatabasePasswordAndKeyfile.m | 36 +++---- 7 files changed, 148 insertions(+), 53 deletions(-) diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 376ba048..6fb494ec 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -2203,6 +2203,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_OBJC_ARC = YES; + CODE_SIGN_IDENTITY = "Developer ID Application"; COMBINE_HIDPI_IMAGES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "MacPass/MacPass-Prefix.pch"; @@ -2217,6 +2218,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_OBJC_ARC = YES; + CODE_SIGN_IDENTITY = "Developer ID Application"; COMBINE_HIDPI_IMAGES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "MacPass/MacPass-Prefix.pch"; diff --git a/MacPass/Base.lproj/InspectorView.xib b/MacPass/Base.lproj/InspectorView.xib index 90d5d8e1..17fdf5a3 100644 --- a/MacPass/Base.lproj/InspectorView.xib +++ b/MacPass/Base.lproj/InspectorView.xib @@ -42,7 +42,7 @@ NSApplication - + 268 @@ -50,6 +50,7 @@ 268 {{57, 409}, {204, 17}} + _NS:1535 {249, 750} @@ -99,13 +100,14 @@ {{20, 401}, {32, 32}} + _NS:9 YES 134217728 33554432 - + NSImage NSActionTemplate @@ -127,17 +129,20 @@ 268 {{20, 2}, {42, 25}} + + _NS:22 YES -2080374784 134217728 - Edit + _NS:22 -2034483200 163 + 400 @@ -148,6 +153,7 @@ {278, 30} + _NS:9 HNHGradientView @@ -157,6 +163,8 @@ 268 {{0, 30}, {278, 369}} + + _NS:9 @@ -166,7 +174,8 @@ 274 {278, 369} - + + _NS:28 Entry @@ -243,6 +252,8 @@ {278, 443} + + _NS:9 NSView @@ -966,7 +977,100 @@ 3117 - + + + + HNHGradientView + NSView + + IBProjectSource + ./Classes/HNHGradientView.h + + + + MPInspectorViewController + MPViewController + + showImagePopup: + id + + + showImagePopup: + + showImagePopup: + id + + + + HNHGradientView + NSTextField + MPPopupImageView + NSTextField + NSTextField + NSTextField + NSTabView + + + + bottomBar + HNHGradientView + + + createdTextField + NSTextField + + + itemImageView + MPPopupImageView + + + itemNameTextField + NSTextField + + + modifiedTextField + NSTextField + + + noSelectionInfo + NSTextField + + + tabView + NSTabView + + + + IBProjectSource + ./Classes/MPInspectorViewController.h + + + + MPPopupImageView + NSImageView + + IBProjectSource + ./Classes/MPPopupImageView.h + + + + MPViewController + NSViewController + + IBProjectSource + ./Classes/MPViewController.h + + + + NSLayoutConstraint + NSObject + + IBProjectSource + ./Classes/NSLayoutConstraint.h + + + + 0 IBCocoaFramework YES diff --git a/MacPass/MacPass-Info.plist b/MacPass/MacPass-Info.plist index 5c6c4db5..c448580c 100644 --- a/MacPass/MacPass-Info.plist +++ b/MacPass/MacPass-Info.plist @@ -12,7 +12,7 @@ kdbx CFBundleTypeName - + kdbxFileType CFBundleTypeRole Editor LSItemContentTypes @@ -28,7 +28,7 @@ kdb CFBundleTypeName - + kdbFileType CFBundleTypeRole Editor LSItemContentTypes diff --git a/MacPassTests/MPDatabaseCreation.m b/MacPassTests/MPDatabaseCreation.m index 1a36c4f1..709ea18d 100644 --- a/MacPassTests/MPDatabaseCreation.m +++ b/MacPassTests/MPDatabaseCreation.m @@ -8,26 +8,15 @@ #import "MPDatabaseCreation.h" #import "MPDocument.h" +#import "KPKTree.h" @implementation MPDatabaseCreation -- (void)testCreateDatabaseVersion1 { - MPDocument *document = [[MPDocument alloc] initWithVersion:MPDatabaseVersion3]; +- (void)testCreateNewDatabase { + MPDocument *document = [[MPDocument alloc] init]; 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.decrypted, @"Document has to be decrypted new database is created"); - STAssertFalse(document.hasPasswordOrKey, @"Document has no Password/Keyfile and thus is not secured"); -} - -- (void)testCreateDatabaseVersion2 { - MPDocument *document = [[MPDocument alloc] initWithVersion:MPDatabaseVersion4]; - STAssertNotNil(document, @"Document should be created"); - STAssertTrue(document.version == MPDatabaseVersion4, @"Database should be Version2"); - STAssertNotNil(document.treeV4, @"Database Tree needs to be Kdb4Tree"); - STAssertNil(document.treeV3, @"Database Tree cannot be Kdb3Tree"); - STAssertTrue(document.decrypted, @"Document has to be decrypted new database is created"); + STAssertTrue(document.tree.minimumVersion == KPKLegacyVersion, @"Tree should be Legacy Version in defautl case"); + STAssertFalse(document.encrypted, @"Document cannot be encrypted at creation"); STAssertFalse(document.hasPasswordOrKey, @"Document has no Password/Keyfile and thus is not secured"); } diff --git a/MacPassTests/MPDatabaseLoading.m b/MacPassTests/MPDatabaseLoading.m index c608cba0..a561b806 100644 --- a/MacPassTests/MPDatabaseLoading.m +++ b/MacPassTests/MPDatabaseLoading.m @@ -10,6 +10,8 @@ #import "MPDocument.h" +#import "KPKTree.h" + @implementation MPDatabaseLoading @@ -20,12 +22,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"); - STAssertTrue([document unlockWithPassword:@"1234" keyFileURL:nil], @"Should decrypt with password"); - STAssertTrue(document.decrypted, @"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"); + STAssertTrue(document.encrypted, @"Loaded but unencrypted should be not decrypted"); + STAssertTrue([document unlockWithPassword:@"1234" keyFileURL:nil error:&error], @"Should decrypt with password"); + STAssertNil(error, @"No Error should occur on unlocking with correct password"); + STAssertTrue((document.tree.minimumVersion = KPKLegacyVersion), @"Minimal Version should not increase with KDB File loaded"); + //STAssertTrue([document.fileType isEqualToString:[MPDocument fileTypeForVersion:KPKLegacyVersion]], @"File type needs to match opened file"); } - (void)testVersion1WrongPassword { @@ -35,9 +36,9 @@ 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 unlockWithPassword:@"123" keyFileURL:nil], @"Decryption should fail"); - STAssertFalse(document.decrypted, @"Document is not decrypted with wrong password supplied"); + STAssertTrue(document.encrypted, @"Loaded but unencrypted should be not decrypted"); + STAssertFalse([document unlockWithPassword:@"123" keyFileURL:nil error:&error], @"Decryption should fail"); + STAssertNotNil(error, @"Error should occur on unlocking with correct password"); } - (void)testLoadDatabaseVerions2 { @@ -47,12 +48,14 @@ 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.decrypted, @"Document is not decrypted after inital load"); STAssertTrue([document unlockWithPassword:@"1234" keyFileURL:nil], @"Should decrypt with password"); STAssertTrue(document.decrypted, @"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 index 36af89ed..4820ffec 100644 --- a/MacPassTests/MPDatabasePasswordAndKeyfile.h +++ b/MacPassTests/MPDatabasePasswordAndKeyfile.h @@ -11,8 +11,7 @@ @class MPDocument; @interface MPDatabasePasswordAndKeyfile : SenTestCase { - MPDocument *_databaseV3; - MPDocument *_databaseV4; + MPDocument *_database; } @end diff --git a/MacPassTests/MPDatabasePasswordAndKeyfile.m b/MacPassTests/MPDatabasePasswordAndKeyfile.m index aba4c179..81daab45 100644 --- a/MacPassTests/MPDatabasePasswordAndKeyfile.m +++ b/MacPassTests/MPDatabasePasswordAndKeyfile.m @@ -13,34 +13,32 @@ @implementation MPDatabasePasswordAndKeyfile - (void)setUp { - _databaseV3 = [[MPDocument alloc] initWithVersion:MPDatabaseVersion3]; - _databaseV4 = [[MPDocument alloc] initWithVersion:MPDatabaseVersion4]; + _database = [[MPDocument alloc] init]; } - (void)tearDown { - _databaseV3 = nil; - _databaseV4 = nil; + _database = nil; } - (void)testSetPassword { - STAssertTrue([_databaseV3.password length] == 0, @"Password should not be set"); - STAssertNil(_databaseV3.key, @"Keyfile should not be set"); - STAssertFalse(_databaseV3.hasPasswordOrKey, @"Database without password is not secure"); - _databaseV3.password = @"test"; - STAssertTrue([_databaseV3.password isEqualToString:@"test"], @"Password should be set"); - STAssertTrue(_databaseV3.hasPasswordOrKey, @"Database with password is secured"); - _databaseV3.password = nil; - STAssertFalse(_databaseV3.hasPasswordOrKey, @"Database with removed password is not secure anymore"); + STAssertTrue([_database.password length] == 0, @"Password should not be set"); + STAssertNil(_database.key, @"Keyfile should not be set"); + STAssertFalse(_database.hasPasswordOrKey, @"Database without password is not secure"); + _database.password = @"test"; + STAssertTrue([_database.password isEqualToString:@"test"], @"Password should be set"); + STAssertTrue(_database.hasPasswordOrKey, @"Database with password is secured"); + _database.password = nil; + STAssertFalse(_database.hasPasswordOrKey, @"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.hasPasswordOrKey, @"Database without keyfile is not secure"); - _databaseV3.key = [NSURL URLWithString:@"noKeyFile"]; - STAssertTrue(_databaseV3.hasPasswordOrKey, @"Database with keyfile is secured"); - _databaseV3.key = nil; - STAssertFalse(_databaseV3.hasPasswordOrKey, @"Database with removed keyfile is not secure anymore"); + STAssertTrue([_database.password length] == 0, @"Password should not be set"); + STAssertNil(_database.key, @"Keyfile should not be set"); + STAssertFalse(_database.hasPasswordOrKey, @"Database without keyfile is not secure"); + _database.key = [NSURL URLWithString:@"noKeyFile"]; + STAssertTrue(_database.hasPasswordOrKey, @"Database with keyfile is secured"); + _database.key = nil; + STAssertFalse(_database.hasPasswordOrKey, @"Database with removed keyfile is not secure anymore"); }