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

Binary file not shown.

View File

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

View File

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

View File

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

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