Key/Password set/reset test

This commit is contained in:
michael starke
2013-07-11 01:51:20 +02:00
parent 3d4c183bdb
commit 3d14904640
8 changed files with 112 additions and 17 deletions

View File

@@ -13,6 +13,8 @@
4C10412C178CDD44001B5239 /* NSDate+Humanized.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C10412B178CDD44001B5239 /* NSDate+Humanized.m */; }; 4C10412C178CDD44001B5239 /* NSDate+Humanized.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C10412B178CDD44001B5239 /* NSDate+Humanized.m */; };
4C16BA6217879A3C002B42BD /* MPPasswordStringFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C16BA6117879A3C002B42BD /* MPPasswordStringFormatter.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 */; }; 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 */; }; 4C1DDCDD1711ECEB00C98DA3 /* PasswordCreatorWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C1DDCDC1711ECEB00C98DA3 /* PasswordCreatorWindow.xib */; };
4C22040D1746ED160054C916 /* KdbGroup+Undo.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C22040C1746ED160054C916 /* KdbGroup+Undo.m */; }; 4C22040D1746ED160054C916 /* KdbGroup+Undo.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C22040C1746ED160054C916 /* KdbGroup+Undo.m */; };
4C245B76176E1E3D0086100E /* DDData.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C245A6A176E1E3C0086100E /* DDData.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 */; }; 4C45FB1C178E09ED0010007D /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C45FB1B178E09ED0010007D /* SenTestingKit.framework */; };
4C45FB1D178E09ED0010007D /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C77E36615B84A240093A587 /* Cocoa.framework */; }; 4C45FB1D178E09ED0010007D /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C77E36615B84A240093A587 /* Cocoa.framework */; };
4C45FB23178E09ED0010007D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4C45FB21178E09ED0010007D /* InfoPlist.strings */; }; 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 */; }; 4C45FB30178E0CE20010007D /* MPDatabaseCreation.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C45FB2F178E0CE20010007D /* MPDatabaseCreation.m */; };
4C46B88517063A070046109A /* NSString+MPPasswordCreation.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C46B88417063A070046109A /* NSString+MPPasswordCreation.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 */; }; 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 = "<group>"; }; 4C16BA6017879A3C002B42BD /* MPPasswordStringFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPPasswordStringFormatter.h; sourceTree = "<group>"; };
4C16BA6117879A3C002B42BD /* MPPasswordStringFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPPasswordStringFormatter.m; sourceTree = "<group>"; }; 4C16BA6117879A3C002B42BD /* MPPasswordStringFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPPasswordStringFormatter.m; sourceTree = "<group>"; };
4C18F9AA178E122500890BCE /* Test_Password_1234.kdb */ = {isa = PBXFileReference; lastKnownFileType = file; name = Test_Password_1234.kdb; path = Databases/Test_Password_1234.kdb; sourceTree = "<group>"; }; 4C18F9AA178E122500890BCE /* Test_Password_1234.kdb */ = {isa = PBXFileReference; lastKnownFileType = file; name = Test_Password_1234.kdb; path = Databases/Test_Password_1234.kdb; sourceTree = "<group>"; };
4C19E4FF178E26EF002F2CD0 /* Test_Password_1234.kdbx */ = {isa = PBXFileReference; lastKnownFileType = file; name = Test_Password_1234.kdbx; path = Databases/Test_Password_1234.kdbx; sourceTree = "<group>"; };
4C19E501178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDatabasePasswordAndKeyfile.h; sourceTree = "<group>"; };
4C19E502178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDatabasePasswordAndKeyfile.m; sourceTree = "<group>"; };
4C1DDCDC1711ECEB00C98DA3 /* PasswordCreatorWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PasswordCreatorWindow.xib; sourceTree = "<group>"; }; 4C1DDCDC1711ECEB00C98DA3 /* PasswordCreatorWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PasswordCreatorWindow.xib; sourceTree = "<group>"; };
4C22040B1746ED160054C916 /* KdbGroup+Undo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KdbGroup+Undo.h"; sourceTree = "<group>"; }; 4C22040B1746ED160054C916 /* KdbGroup+Undo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "KdbGroup+Undo.h"; sourceTree = "<group>"; };
4C22040C1746ED160054C916 /* KdbGroup+Undo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "KdbGroup+Undo.m"; sourceTree = "<group>"; }; 4C22040C1746ED160054C916 /* KdbGroup+Undo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "KdbGroup+Undo.m"; sourceTree = "<group>"; };
@@ -322,8 +327,8 @@
4C45FB20178E09ED0010007D /* MacPassTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "MacPassTests-Info.plist"; sourceTree = "<group>"; }; 4C45FB20178E09ED0010007D /* MacPassTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "MacPassTests-Info.plist"; sourceTree = "<group>"; };
4C45FB22178E09ED0010007D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; }; 4C45FB22178E09ED0010007D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
4C45FB27178E09ED0010007D /* MacPassTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MacPassTests-Prefix.pch"; sourceTree = "<group>"; }; 4C45FB27178E09ED0010007D /* MacPassTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MacPassTests-Prefix.pch"; sourceTree = "<group>"; };
4C45FB2B178E0BCB0010007D /* MPDatabaseLoadingTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDatabaseLoadingTest.h; sourceTree = "<group>"; }; 4C45FB2B178E0BCB0010007D /* MPDatabaseLoading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDatabaseLoading.h; sourceTree = "<group>"; };
4C45FB2C178E0BCB0010007D /* MPDatabaseLoadingTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDatabaseLoadingTest.m; sourceTree = "<group>"; }; 4C45FB2C178E0BCB0010007D /* MPDatabaseLoading.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDatabaseLoading.m; sourceTree = "<group>"; };
4C45FB2E178E0CE20010007D /* MPDatabaseCreation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDatabaseCreation.h; sourceTree = "<group>"; }; 4C45FB2E178E0CE20010007D /* MPDatabaseCreation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDatabaseCreation.h; sourceTree = "<group>"; };
4C45FB2F178E0CE20010007D /* MPDatabaseCreation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDatabaseCreation.m; sourceTree = "<group>"; }; 4C45FB2F178E0CE20010007D /* MPDatabaseCreation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDatabaseCreation.m; sourceTree = "<group>"; };
4C46B88317063A070046109A /* NSString+MPPasswordCreation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MPPasswordCreation.h"; sourceTree = "<group>"; }; 4C46B88317063A070046109A /* NSString+MPPasswordCreation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MPPasswordCreation.h"; sourceTree = "<group>"; };
@@ -665,6 +670,7 @@
4C18F9AC178E123200890BCE /* Databases */ = { 4C18F9AC178E123200890BCE /* Databases */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
4C19E4FF178E26EF002F2CD0 /* Test_Password_1234.kdbx */,
4C18F9AA178E122500890BCE /* Test_Password_1234.kdb */, 4C18F9AA178E122500890BCE /* Test_Password_1234.kdb */,
); );
name = Databases; name = Databases;
@@ -924,10 +930,12 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
4C18F9AC178E123200890BCE /* Databases */, 4C18F9AC178E123200890BCE /* Databases */,
4C45FB2B178E0BCB0010007D /* MPDatabaseLoadingTest.h */, 4C45FB2B178E0BCB0010007D /* MPDatabaseLoading.h */,
4C45FB2C178E0BCB0010007D /* MPDatabaseLoadingTest.m */, 4C45FB2C178E0BCB0010007D /* MPDatabaseLoading.m */,
4C45FB2E178E0CE20010007D /* MPDatabaseCreation.h */, 4C45FB2E178E0CE20010007D /* MPDatabaseCreation.h */,
4C45FB2F178E0CE20010007D /* MPDatabaseCreation.m */, 4C45FB2F178E0CE20010007D /* MPDatabaseCreation.m */,
4C19E501178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.h */,
4C19E502178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m */,
4C45FB1F178E09ED0010007D /* Supporting Files */, 4C45FB1F178E09ED0010007D /* Supporting Files */,
); );
path = MacPassTests; path = MacPassTests;
@@ -1413,6 +1421,7 @@
files = ( files = (
4C45FB23178E09ED0010007D /* InfoPlist.strings in Resources */, 4C45FB23178E09ED0010007D /* InfoPlist.strings in Resources */,
4C18F9AB178E122500890BCE /* Test_Password_1234.kdb in Resources */, 4C18F9AB178E122500890BCE /* Test_Password_1234.kdb in Resources */,
4C19E500178E26EF002F2CD0 /* Test_Password_1234.kdbx in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@@ -1502,8 +1511,9 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
4C45FB2D178E0BCB0010007D /* MPDatabaseLoadingTest.m in Sources */, 4C45FB2D178E0BCB0010007D /* MPDatabaseLoading.m in Sources */,
4C45FB30178E0CE20010007D /* MPDatabaseCreation.m in Sources */, 4C45FB30178E0CE20010007D /* MPDatabaseCreation.m in Sources */,
4C19E503178E2871002F2CD0 /* MPDatabasePasswordAndKeyfile.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View File

@@ -48,7 +48,7 @@
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>2403</string> <string>2409</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string> <string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key> <key>NSHumanReadableCopyright</key>

Binary file not shown.

View File

@@ -12,7 +12,13 @@
@implementation MPDatabaseCreation @implementation MPDatabaseCreation
- (void)testCreateDatabaseVersion1 { - (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 { - (void)testCreateDatabaseVersion2 {
@@ -20,7 +26,9 @@
STAssertNotNil(document, @"Document should be created"); STAssertNotNil(document, @"Document should be created");
STAssertTrue(document.version == MPDatabaseVersion4, @"Database should be Version2"); STAssertTrue(document.version == MPDatabaseVersion4, @"Database should be Version2");
STAssertNotNil(document.treeV4, @"Database Tree needs to be Kdb4Tree"); 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 @end

View File

@@ -8,6 +8,6 @@
#import <SenTestingKit/SenTestingKit.h> #import <SenTestingKit/SenTestingKit.h>
@interface MPDatabaseLoadingTest : SenTestCase @interface MPDatabaseLoading : SenTestCase
@end @end

View File

@@ -6,11 +6,11 @@
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. // Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
// //
#import "MPDatabaseLoadingTest.h" #import "MPDatabaseLoading.h"
#import "MPDocument.h" #import "MPDocument.h"
@implementation MPDatabaseLoadingTest @implementation MPDatabaseLoading
- (void)testLoadVersion1 { - (void)testLoadVersion1 {
@@ -20,10 +20,11 @@
MPDocument *document = [[MPDocument alloc] initWithContentsOfURL:url ofType:@"kdb" error:&error]; MPDocument *document = [[MPDocument alloc] initWithContentsOfURL:url ofType:@"kdb" error:&error];
STAssertNil(error, @"No Error should occur on loading"); STAssertNil(error, @"No Error should occur on loading");
STAssertNotNil(document, @"Document cannot be nil"); 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 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"); 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.version == MPDatabaseVersion3, @"Internal databse version should be correct");
} }
@@ -34,13 +35,24 @@
MPDocument *document = [[MPDocument alloc] initWithContentsOfURL:url ofType:@"kdb" error:&error]; MPDocument *document = [[MPDocument alloc] initWithContentsOfURL:url ofType:@"kdb" error:&error];
STAssertNil(error, @"No Error should occur on loading"); STAssertNil(error, @"No Error should occur on loading");
STAssertNotNil(document, @"Document should not be nil"); 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 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 { - (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 @end

View File

@@ -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 <SenTestingKit/SenTestingKit.h>
@class MPDocument;
@interface MPDatabasePasswordAndKeyfile : SenTestCase {
MPDocument *_databaseV3;
MPDocument *_databaseV4;
}
@end

View File

@@ -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