mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 03:32:40 +00:00
Migrated project to XCTest
This commit is contained in:
@@ -6,10 +6,15 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKHashedDataTest.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "NSData+HashedData.h"
|
||||
#import "NSData+Random.h"
|
||||
|
||||
@interface KPKHashedDataTest : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation KPKHashedDataTest
|
||||
|
||||
- (void)testHashedData {
|
||||
@@ -17,7 +22,7 @@
|
||||
NSData *data = [NSData dataWithRandomBytes:10000];
|
||||
NSData *hashedData = [data hashedDataWithBlockSize:512];
|
||||
NSData *unhashedData = [hashedData unhashedData];
|
||||
STAssertTrue([unhashedData isEqualToData:data], @"Data needs to be the same after hashing and unhashing");
|
||||
XCTAssertTrue([unhashedData isEqualToData:data], @"Data needs to be the same after hashing and unhashing");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -6,9 +6,16 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKIconLoading.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "KPKIcon.h"
|
||||
|
||||
@interface KPKIconLoading : XCTestCase {
|
||||
NSImage *_image;
|
||||
NSData *_imageData;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation KPKIconLoading
|
||||
|
||||
- (void)setUp {
|
||||
@@ -26,17 +33,17 @@
|
||||
NSBundle *myBundle = [NSBundle bundleForClass:[self class]];
|
||||
NSURL *imageURL = [myBundle URLForImageResource:@"image.png"];
|
||||
KPKIcon *icon = [[KPKIcon alloc] initWithImageAtURL:imageURL];
|
||||
STAssertNotNil(icon, @"Icon should have been loaded");
|
||||
XCTAssertNotNil(icon, @"Icon should have been loaded");
|
||||
NSString *iconString = [icon encodedString];
|
||||
KPKIcon *iconFromString = [[KPKIcon alloc] initWithUUID:[NSUUID UUID] encodedString:iconString];
|
||||
STAssertTrue([iconString isEqualToString:[iconFromString encodedString]], @"Encoding and Decoding should result in the same string");
|
||||
XCTAssertTrue([iconString isEqualToString:[iconFromString encodedString]], @"Encoding and Decoding should result in the same string");
|
||||
Class repClass = [NSBitmapImageRep class];
|
||||
NSImageRep *imageRep = [[icon.image representations] lastObject];
|
||||
STAssertNotNil(imageRep, @"One image rep shoudl be there");
|
||||
STAssertTrue([imageRep isKindOfClass:repClass], @"Representation should be bitmap");
|
||||
XCTAssertNotNil(imageRep, @"One image rep shoudl be there");
|
||||
XCTAssertTrue([imageRep isKindOfClass:repClass], @"Representation should be bitmap");
|
||||
NSBitmapImageRep *bitmapRep = (NSBitmapImageRep *)imageRep;
|
||||
NSData *pngData = [bitmapRep representationUsingType:NSPNGFileType properties:nil];
|
||||
STAssertTrue([pngData isEqualToData:_imageData], @"Image and PNG data shoudl be identical");
|
||||
XCTAssertTrue([pngData isEqualToData:_imageData], @"Image and PNG data shoudl be identical");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,15 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKTestHexColor.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "NSColor+KeePassKit.h"
|
||||
|
||||
|
||||
@interface KPKTestHexColor : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation KPKTestHexColor
|
||||
|
||||
- (void)testHexToColor {
|
||||
@@ -21,26 +26,26 @@
|
||||
NSColor *green = [NSColor colorWithHexString:greeHex];
|
||||
NSColor *blue = [NSColor colorWithHexString:blueHex];
|
||||
|
||||
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");
|
||||
XCTAssertEqual([red redComponent], 1.0, @"Red color should have 100%% red");
|
||||
XCTAssertEqual([red blueComponent], 0.0, @"Red color should have 0%% blue");
|
||||
XCTAssertEqual([red greenComponent], 0.0, @"Red color should have 0%% green");
|
||||
|
||||
STAssertEquals([green redComponent], 0.0, @"Green color should have 0% red");
|
||||
STAssertEquals([green greenComponent], 1.0, @"Green color should have 100% green");
|
||||
STAssertEquals([green blueComponent], 0.0, @"Green color should have 0% blue");
|
||||
XCTAssertEqual([green redComponent], 0.0, @"Green color should have 0%% red");
|
||||
XCTAssertEqual([green greenComponent], 1.0, @"Green color should have 100%% green");
|
||||
XCTAssertEqual([green blueComponent], 0.0, @"Green color should have 0%% blue");
|
||||
|
||||
STAssertEquals([blue redComponent], 0.0, @"Blue color should have 0% red");
|
||||
STAssertEquals([blue greenComponent], 0.0, @"Blue color should have 0% green");
|
||||
STAssertEquals([blue blueComponent], 1.0, @"Blue color should have 100% blue");
|
||||
XCTAssertEqual([blue redComponent], 0.0, @"Blue color should have 0%% red");
|
||||
XCTAssertEqual([blue greenComponent], 0.0, @"Blue color should have 0%% green");
|
||||
XCTAssertEqual([blue blueComponent], 1.0, @"Blue color should have 100%% blue");
|
||||
}
|
||||
|
||||
- (void)testColorRefReading {
|
||||
uint32_t colorBytes = 0x000000FF;
|
||||
NSData *colorData = [NSData dataWithBytesNoCopy:&colorBytes length:3 freeWhenDone:NO];
|
||||
NSColor *color = [NSColor colorWithData:colorData];
|
||||
STAssertEquals([color redComponent], 1.0, @"Red 100%");
|
||||
STAssertEquals([color greenComponent], 0.0, @"Green 0%");
|
||||
STAssertEquals([color blueComponent], 0.0, @"Blue 100%");
|
||||
XCTAssertEqual([color redComponent], 1.0, @"Red 100%%");
|
||||
XCTAssertEqual([color greenComponent], 0.0, @"Green 0%%");
|
||||
XCTAssertEqual([color blueComponent], 0.0, @"Blue 100%%");
|
||||
}
|
||||
|
||||
- (void)testColorRefWriting {
|
||||
@@ -48,7 +53,7 @@
|
||||
NSData *colorData = [NSData dataWithBytesNoCopy:&colorBytes length:4 freeWhenDone:NO];
|
||||
NSColor *color = [NSColor colorWithData:colorData];
|
||||
NSData *newData = [color colorData];
|
||||
STAssertEqualObjects(colorData, newData, @"Convertion should result in same data");
|
||||
XCTAssertEqualObjects(colorData, newData, @"Convertion should result in same data");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -6,9 +6,13 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKTestKeyfileParsing.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "NSData+Keyfile.h"
|
||||
|
||||
@interface KPKTestKeyfileParsing : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation KPKTestKeyfileParsing
|
||||
|
||||
- (void)testXmlKeyfileLoadingValidFile {
|
||||
@@ -16,32 +20,32 @@
|
||||
NSURL *url = [myBundle URLForResource:@"Keepass2Key" withExtension:@"xml"];
|
||||
NSError *error;
|
||||
NSData *data = [NSData dataWithContentsOfKeyFile:url version:KPKXmlVersion error:&error];
|
||||
STAssertNotNil(data, @"Data should be loaded");
|
||||
STAssertNil(error, @"No error should occur on keyfile loading");
|
||||
XCTAssertNotNil(data, @"Data should be loaded");
|
||||
XCTAssertNil(error, @"No error should occur on keyfile loading");
|
||||
}
|
||||
|
||||
- (void)testXmlKeyfileLoadingCorruptData {
|
||||
STAssertFalse(NO, @"Not Implemented");
|
||||
XCTAssertFalse(NO, @"Not Implemented");
|
||||
}
|
||||
|
||||
- (void)testXmlKeyfileLoadingMissingVersion {
|
||||
STAssertFalse(NO, @"Not Implemented");
|
||||
XCTAssertFalse(NO, @"Not Implemented");
|
||||
}
|
||||
|
||||
- (void)testXmlKeyfileLoadingLowerVersion {
|
||||
STAssertFalse(NO, @"Not Implemented");
|
||||
XCTAssertFalse(NO, @"Not Implemented");
|
||||
}
|
||||
|
||||
- (void)testXmlKeyfilGeneration {
|
||||
NSData *data = [NSData generateKeyfiledataForVersion:KPKXmlVersion];
|
||||
// Test if structure is sound;
|
||||
STAssertNotNil(data, @"Keydata should have been generated");
|
||||
XCTAssertNotNil(data, @"Keydata should have been generated");
|
||||
}
|
||||
|
||||
- (void)testLegacyKeyfileGeneration {
|
||||
NSData *data = [NSData generateKeyfiledataForVersion:KPKLegacyVersion];
|
||||
// test if strucutre is sound;
|
||||
STAssertNotNil(data, @"Keydata should have been generated");
|
||||
XCTAssertNotNil(data, @"Keydata should have been generated");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKTestLegacyLoading.h"
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "KPKTree+Serializing.h"
|
||||
#import "KPKCompositeKey.h"
|
||||
@@ -15,13 +16,17 @@
|
||||
|
||||
#import "KPKErrors.h"
|
||||
|
||||
@interface KPKTestLegacyLoading : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation KPKTestLegacyLoading
|
||||
|
||||
- (void)testValidFile {
|
||||
KPKCompositeKey *password = [[KPKCompositeKey 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");
|
||||
XCTAssertNotNil(tree, @"Loading should result in a tree object");
|
||||
}
|
||||
|
||||
- (void)testWrongPassword {
|
||||
@@ -29,8 +34,8 @@
|
||||
NSData *data = [self _loadTestDataBase:@"KeePass1_native_test" extension:@"kdb"];
|
||||
NSError *error;
|
||||
KPKTree *tree = [[KPKTree alloc] initWithData:data password:password error:&error];
|
||||
STAssertNil(tree, @"Wrong password should yield nil tree");
|
||||
STAssertNotNil(error, @"Wrong password should yield error");
|
||||
XCTAssertNil(tree, @"Wrong password should yield nil tree");
|
||||
XCTAssertNotNil(error, @"Wrong password should yield error");
|
||||
//STAssertTrue([error code] == KPKErrorPasswordAndOrKeyfileWrong, @"Error code should be wrong password and/or keyfile");
|
||||
}
|
||||
|
||||
@@ -39,9 +44,9 @@
|
||||
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");
|
||||
STAssertNotNil(error, @"Error object should have been created");
|
||||
STAssertTrue(KPKErrorUnknownFileFormat == [error code], @"Error should be Unknown file format");
|
||||
XCTAssertNil(tree, @"Tree should be nil with invalid data");
|
||||
XCTAssertNotNil(error, @"Error object should have been created");
|
||||
XCTAssertTrue(KPKErrorUnknownFileFormat == [error code], @"Error should be Unknown file format");
|
||||
}
|
||||
|
||||
|
||||
@@ -49,10 +54,10 @@
|
||||
NSData *data = [self _loadTestDataBase:@"KDB1_KeePassX_test" extension:@"kdb"];
|
||||
KPKCompositeKey *password = [[KPKCompositeKey alloc] initWithPassword:@"test" key:nil];
|
||||
KPKTree *tree = [[KPKTree alloc] initWithData:data password:password error:NULL];
|
||||
STAssertNotNil(tree, @"Tree shoudl be loaded" );
|
||||
XCTAssertNotNil(tree, @"Tree shoudl be loaded" );
|
||||
|
||||
KPKIcon *icon = [tree.metaData.customIcons lastObject];
|
||||
STAssertNotNil(icon, @"Should load one Icon");
|
||||
XCTAssertNotNil(icon, @"Should load one Icon");
|
||||
}
|
||||
|
||||
- (NSData *)_loadTestDataBase:(NSString *)name extension:(NSString *)extension {
|
||||
|
||||
@@ -6,11 +6,15 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKTestLegacyWriting.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "KPKCompositeKey.h"
|
||||
#import "KPKTree+Serializing.h"
|
||||
|
||||
@interface KPKTestLegacyWriting : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation KPKTestLegacyWriting
|
||||
|
||||
- (void)testWriting {
|
||||
@@ -18,15 +22,15 @@
|
||||
NSURL *dbUrl = [self _urlForFile:@"CustomIcon_Password_1234" extension:@"kdbx"];
|
||||
KPKCompositeKey *password = [[KPKCompositeKey alloc] initWithPassword:@"1234" key:nil];
|
||||
KPKTree *tree = [[KPKTree alloc] initWithContentsOfUrl:dbUrl password:password error:&error];
|
||||
STAssertNotNil(tree, @"Tree should be created");
|
||||
XCTAssertNotNil(tree, @"Tree should be created");
|
||||
error = nil;
|
||||
NSData *data = [tree encryptWithPassword:password forVersion:KPKLegacyVersion error:&error];
|
||||
STAssertNotNil(data, @"Serialized Data shoudl be created");
|
||||
XCTAssertNotNil(data, @"Serialized Data shoudl be created");
|
||||
NSString *tempFile = [NSTemporaryDirectory() stringByAppendingString:@"CustomIcon_Password_1234.kdb"];
|
||||
NSLog(@"Saved to %@", tempFile);
|
||||
[data writeToFile:tempFile atomically:YES];
|
||||
KPKTree *loadTree = [[KPKTree alloc] initWithData:data password:password error:&error];
|
||||
STAssertNotNil(loadTree, @"Tree should be loadable from kdb file data");
|
||||
XCTAssertNotNil(loadTree, @"Tree should be loadable from kdb file data");
|
||||
}
|
||||
|
||||
- (NSData *)_dataForFile:(NSString *)name extension:(NSString *)extension {
|
||||
|
||||
@@ -6,12 +6,17 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKTestNSCoding.h"
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "KPKEntry.h"
|
||||
#import "KPKBinary.h"
|
||||
#import "KPKAttribute.h"
|
||||
#import "KPKXmlElements.h"
|
||||
|
||||
@interface KPKTestNSCoding : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation KPKTestNSCoding
|
||||
|
||||
- (void)testAttributeCoding {
|
||||
@@ -19,13 +24,13 @@
|
||||
NSData *data = [self encode:attribute];
|
||||
KPKAttribute *copy = [self decode:data ofClass:[KPKAttribute class]];
|
||||
|
||||
STAssertTrue([copy.value isEqualToString:attribute.value], @"Values should be preseved");
|
||||
STAssertTrue([copy.key isEqualToString:attribute.key], @"Keys should be preserved");
|
||||
STAssertTrue(copy.isProtected == attribute.isProtected, @"Protected status should be the same");
|
||||
XCTAssertTrue([copy.value isEqualToString:attribute.value], @"Values should be preseved");
|
||||
XCTAssertTrue([copy.key isEqualToString:attribute.key], @"Keys should be preserved");
|
||||
XCTAssertTrue(copy.isProtected == attribute.isProtected, @"Protected status should be the same");
|
||||
}
|
||||
|
||||
- (void)testBinaryCoding {
|
||||
|
||||
XCTFail(@"Not Tested");
|
||||
}
|
||||
|
||||
- (void)testEntryCoding {
|
||||
@@ -49,19 +54,19 @@
|
||||
NSData *encodedData = [self encode:entry];
|
||||
KPKEntry *copyEntry = [self decode:encodedData ofClass:[KPKEntry class]];
|
||||
|
||||
STAssertNotNil(copyEntry, @"Copied Entry cannot be nil");
|
||||
STAssertTrue([copyEntry.title isEqualToString:entry.title], @"Titles should match");
|
||||
STAssertTrue([copyEntry.url isEqualToString:entry.url], @"URLS should match");
|
||||
STAssertTrue([copyEntry.binaries count] == 1, @"Binareis should be copied");
|
||||
XCTAssertNotNil(copyEntry, @"Copied Entry cannot be nil");
|
||||
XCTAssertTrue([copyEntry.title isEqualToString:entry.title], @"Titles should match");
|
||||
XCTAssertTrue([copyEntry.url isEqualToString:entry.url], @"URLS should match");
|
||||
XCTAssertTrue([copyEntry.binaries count] == 1, @"Binareis should be copied");
|
||||
|
||||
KPKBinary *copiedBinary = [copyEntry.binaries lastObject];
|
||||
STAssertTrue([copiedBinary.data isEqualToData:binary.data], @"Binary data should match");
|
||||
STAssertTrue([copiedBinary.name isEqualToString:binary.name], @"Binary names should macht");
|
||||
XCTAssertTrue([copiedBinary.data isEqualToData:binary.data], @"Binary data should match");
|
||||
XCTAssertTrue([copiedBinary.name isEqualToString:binary.name], @"Binary names should macht");
|
||||
}
|
||||
|
||||
|
||||
- (void)testGroupCoding {
|
||||
|
||||
XCTFail(@"Not Implemented");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,11 +6,14 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKTestNSCopying.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "KPKEntry.h"
|
||||
#import "KPKAttribute.h"
|
||||
#import "KPKBinary.h"
|
||||
|
||||
@interface KPKTestNSCopying : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation KPKTestNSCopying
|
||||
|
||||
@@ -22,10 +25,10 @@
|
||||
attribute.value = @"NewValue";
|
||||
attribute.isProtected = YES;
|
||||
|
||||
STAssertNotNil(copy, @"Copy shoule exist");
|
||||
STAssertTrue([copy.key isEqualToString:@"Key"], @"Copy key should be key");
|
||||
STAssertTrue([copy.value isEqualToString:@"Value"], @"Copy value should be value");
|
||||
STAssertFalse(copy.isProtected, @"Copy should not be protected");
|
||||
XCTAssertNotNil(copy, @"Copy shoule exist");
|
||||
XCTAssertTrue([copy.key isEqualToString:@"Key"], @"Copy key should be key");
|
||||
XCTAssertTrue([copy.value isEqualToString:@"Value"], @"Copy value should be value");
|
||||
XCTAssertFalse(copy.isProtected, @"Copy should not be protected");
|
||||
}
|
||||
|
||||
- (void)testEntryCopying {
|
||||
@@ -52,14 +55,14 @@
|
||||
[entry removeBinary:binary];
|
||||
[[entry.customAttributes lastObject] setKey:@"NewCustomKey"];
|
||||
|
||||
STAssertNotNil(copyEntry, @"Copied Entry cannot be nil");
|
||||
STAssertTrue([copyEntry.title isEqualToString:@"Title"], @"Titles should match");
|
||||
STAssertTrue([copyEntry.url isEqualToString:@"URL"], @"URLS should match");
|
||||
STAssertTrue([copyEntry.binaries count] == 1, @"Binareis should be copied");
|
||||
XCTAssertNotNil(copyEntry, @"Copied Entry cannot be nil");
|
||||
XCTAssertTrue([copyEntry.title isEqualToString:@"Title"], @"Titles should match");
|
||||
XCTAssertTrue([copyEntry.url isEqualToString:@"URL"], @"URLS should match");
|
||||
XCTAssertTrue([copyEntry.binaries count] == 1, @"Binareis should be copied");
|
||||
|
||||
KPKBinary *copiedBinary = [copyEntry.binaries lastObject];
|
||||
STAssertTrue([copiedBinary.data isEqualToData:binary.data], @"Binary data should match");
|
||||
STAssertTrue([copiedBinary.name isEqualToString:binary.name], @"Binary names should macht");
|
||||
XCTAssertTrue([copiedBinary.data isEqualToData:binary.data], @"Binary data should match");
|
||||
XCTAssertTrue([copiedBinary.name isEqualToString:binary.name], @"Binary names should macht");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -6,12 +6,17 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKTestPlaceholder.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "KPKEntry.h"
|
||||
#import "KPKAttribute.h"
|
||||
|
||||
#import "NSString+Commands.h"
|
||||
|
||||
|
||||
@interface KPKTextPlaceholder : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation KPKTextPlaceholder
|
||||
|
||||
- (void)testPlaceholder {
|
||||
@@ -25,10 +30,9 @@
|
||||
[entry addCustomAttribute:attribute];
|
||||
|
||||
NSString *placeholder = @"{USERNAME}{PASSWORD}{NOTHING}{URL}{S:extended}";
|
||||
BOOL replaced;
|
||||
NSString *evaluated = [placeholder evaluatePlaceholderWithEntry:entry didReplace:&replaced];
|
||||
//NSString *evaluatedGoal = [NSString stringWithFormat:@"%@%@{NOTHING}%@%@", entry.username, entry.password, entry.url, attribute.value];
|
||||
//STAssertTrue([evaluated isEqualToString:evaluatedGoal], @"Evaluated string must match");
|
||||
NSString *evaluated = [placeholder evaluatePlaceholderWithEntry:entry];
|
||||
NSString *evaluatedGoal = [NSString stringWithFormat:@"%@%@{NOTHING}%@%@", entry.username, entry.password, entry.url, attribute.value];
|
||||
XCTAssertTrue([evaluated isEqualToString:evaluatedGoal], @"Evaluated string must match");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -14,21 +14,9 @@
|
||||
|
||||
@implementation KPKTestReference
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
[super setUp];
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)testExample
|
||||
{
|
||||
XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -6,13 +6,23 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKTestXmlLoading.h"
|
||||
#import "KPKCompositeKey.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "KPKCompositeKey.h"
|
||||
#import "KPKTree+Serializing.h"
|
||||
#import "KPKEntry.h"
|
||||
#import "KPKGroup.h"
|
||||
|
||||
|
||||
@interface KPKTestXmlLoading : XCTestCase {
|
||||
@private
|
||||
NSData *_data;
|
||||
KPKCompositeKey *_password;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation KPKTestXmlLoading
|
||||
|
||||
- (void)setUp {
|
||||
@@ -30,10 +40,10 @@
|
||||
- (void)testLoading {
|
||||
NSError *error;
|
||||
KPKTree *tree = [[KPKTree alloc] initWithData:_data password:_password error:&error];
|
||||
STAssertNotNil(tree, @"Loading should result in a tree object");
|
||||
XCTAssertNotNil(tree, @"Loading should result in a tree object");
|
||||
|
||||
STAssertTrue([tree.root.groups count] == 0, @"Tree contains just root group");
|
||||
STAssertTrue([tree.root.entries count] == 1, @"Tree has only one entry");
|
||||
XCTAssertTrue([tree.root.groups count] == 0, @"Tree contains just root group");
|
||||
XCTAssertTrue([tree.root.entries count] == 1, @"Tree has only one entry");
|
||||
}
|
||||
|
||||
- (void)testAutotypeLoading {
|
||||
@@ -42,9 +52,9 @@
|
||||
KPKCompositeKey *password = [[KPKCompositeKey alloc] initWithPassword:@"test" key:nil];
|
||||
NSError *error;
|
||||
KPKTree *tree = [[KPKTree alloc] initWithContentsOfUrl:url password:password error:&error];
|
||||
STAssertNotNil(tree, @"Tree shoud be loaded");
|
||||
XCTAssertNotNil(tree, @"Tree shoud be loaded");
|
||||
KPKEntry *entry = tree.root.entries[0];
|
||||
STAssertNotNil(entry, @"Entry should be there");
|
||||
XCTAssertNotNil(entry, @"Entry should be there");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -6,12 +6,18 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKTestXmlParsing.h"
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "KPKXmlTreeReader.h"
|
||||
#import "KPKErrors.h"
|
||||
|
||||
#import "DDXMLDocument.h"
|
||||
|
||||
@interface KPKTestXmlParsing : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation KPKTestXmlParsing
|
||||
|
||||
- (void)testEmptyXmlFile {
|
||||
@@ -19,9 +25,9 @@
|
||||
KPKXmlTreeReader *reader = [[KPKXmlTreeReader alloc] initWithData:[document XMLData] headerReader:nil];
|
||||
NSError *error;
|
||||
KPKTree *tree = [reader tree:&error];
|
||||
STAssertNil(tree, @"No Tree form emptry data");
|
||||
STAssertNotNil(error, @"Error Object should be provided");
|
||||
STAssertTrue([error code] == KPKErrorNoData, @"Error Code should be No Data");
|
||||
XCTAssertNil(tree, @"No Tree form emptry data");
|
||||
XCTAssertNotNil(error, @"Error Object should be provided");
|
||||
XCTAssertTrue([error code] == KPKErrorNoData, @"Error Code should be No Data");
|
||||
}
|
||||
|
||||
- (void)testNoNodeXmlFile {
|
||||
@@ -29,9 +35,9 @@
|
||||
KPKXmlTreeReader *reader = [[KPKXmlTreeReader alloc] initWithData:[document XMLData] headerReader:nil];
|
||||
NSError *error;
|
||||
KPKTree *tree = [reader tree:&error];
|
||||
STAssertNil(tree, @"No Tree form emptry data");
|
||||
STAssertNotNil(error, @"Error Object should be provided");
|
||||
STAssertTrue([error code] == KPKErrorXMLKeePassFileElementMissing, @"Error Code should be KeePassFile root missing");
|
||||
XCTAssertNil(tree, @"No Tree form emptry data");
|
||||
XCTAssertNotNil(error, @"Error Object should be provided");
|
||||
XCTAssertTrue([error code] == KPKErrorXMLKeePassFileElementMissing, @"Error Code should be KeePassFile root missing");
|
||||
}
|
||||
|
||||
- (void)testNoRoodXmlFil {
|
||||
@@ -39,9 +45,9 @@
|
||||
KPKXmlTreeReader *reader = [[KPKXmlTreeReader alloc] initWithData:[document XMLData] headerReader:nil];
|
||||
NSError *error;
|
||||
KPKTree *tree = [reader tree:&error];
|
||||
STAssertNil(tree, @"No Tree form emptry data");
|
||||
STAssertNotNil(error, @"Error Object should be provided");
|
||||
STAssertTrue([error code] == KPKErrorXMLMetaElementMissing, @"Error Code should be KeePassFile root missing");
|
||||
XCTAssertNil(tree, @"No Tree form emptry data");
|
||||
XCTAssertNotNil(error, @"Error Object should be provided");
|
||||
XCTAssertTrue([error code] == KPKErrorXMLMetaElementMissing, @"Error Code should be KeePassFile root missing");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -6,10 +6,15 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KPKTestXmlWriting.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "KPKCompositeKey.h"
|
||||
#import "KPKTree+Serializing.h"
|
||||
|
||||
@interface KPKTestXmlWriting : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation KPKTestXmlWriting
|
||||
|
||||
- (void)testXmlWriting {
|
||||
@@ -19,7 +24,7 @@
|
||||
KPKTree *tree = [[KPKTree alloc] initWithData:data password:password error:&error];
|
||||
error = nil;
|
||||
NSData *saveData = [tree encryptWithPassword:password forVersion:KPKXmlVersion error:&error];
|
||||
STAssertNotNil(saveData, @"Serialization should yield data");
|
||||
XCTAssertNotNil(saveData, @"Serialization should yield data");
|
||||
NSString *tempFile = [NSTemporaryDirectory() stringByAppendingString:@"CustomIcon_Password_1234_save.kdbx"];
|
||||
NSLog(@"Saved file to %@", tempFile);
|
||||
[saveData writeToFile:tempFile atomically:YES];
|
||||
@@ -27,7 +32,7 @@
|
||||
error = nil;
|
||||
NSURL *url = [NSURL fileURLWithPath:tempFile];
|
||||
KPKTree *reloadedTree = [[KPKTree alloc] initWithContentsOfUrl:url password:password error:&error];
|
||||
STAssertNotNil(reloadedTree, @"Reloaded tree should not be nil");
|
||||
XCTAssertNotNil(reloadedTree, @"Reloaded tree should not be nil");
|
||||
}
|
||||
|
||||
- (NSData *)_loadTestDataBase:(NSString *)name extension:(NSString *)extension {
|
||||
|
||||
@@ -6,19 +6,24 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPDatabaseCreation.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "MPDocument.h"
|
||||
#import "KPKTree.h"
|
||||
#import "KPKCompositeKey.h"
|
||||
|
||||
@interface MPDatabaseCreation : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPDatabaseCreation
|
||||
|
||||
- (void)testCreateNewDatabase {
|
||||
MPDocument *document = [[MPDocument alloc] init];
|
||||
STAssertNotNil(document, @"Document should be 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.compositeKey.hasPasswordOrKeyFile, @"Document has no Password/Keyfile and thus is not secured");
|
||||
XCTAssertNotNil(document, @"Document should be created");
|
||||
XCTAssertTrue(document.tree.minimumVersion == KPKLegacyVersion, @"Tree should be Legacy Version in defautl case");
|
||||
XCTAssertFalse(document.encrypted, @"Document cannot be encrypted at creation");
|
||||
XCTAssertFalse(document.compositeKey.hasPasswordOrKeyFile, @"Document has no Password/Keyfile and thus is not secured");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPDatabaseLoading.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "MPDocument.h"
|
||||
|
||||
#import "KPKTree.h"
|
||||
|
||||
@interface MPDatabaseLoading : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPDatabaseLoading
|
||||
|
||||
|
||||
@@ -20,12 +23,12 @@
|
||||
NSURL *url = [myBundle URLForResource:@"Test_Password_1234" withExtension:@"kdb"];
|
||||
NSError *error = nil;
|
||||
MPDocument *document = [[MPDocument alloc] initWithContentsOfURL:url ofType:@"kdb" error:&error];
|
||||
STAssertNil(error, @"No Error should occur on loading");
|
||||
STAssertNotNil(document, @"Document cannot be nil");
|
||||
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");
|
||||
XCTAssertNil(error, @"No Error should occur on loading");
|
||||
XCTAssertNotNil(document, @"Document cannot be nil");
|
||||
XCTAssertTrue(document.encrypted, @"Loaded but unencrypted should be not decrypted");
|
||||
XCTAssertTrue([document unlockWithPassword:@"1234" keyFileURL:nil error:&error], @"Should decrypt with password");
|
||||
XCTAssertNil(error, @"No Error should occur on unlocking with correct password");
|
||||
XCTAssertTrue((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");
|
||||
}
|
||||
|
||||
@@ -34,11 +37,11 @@
|
||||
NSURL *url = [myBundle URLForResource:@"Test_Password_1234" withExtension:@"kdb"];
|
||||
NSError *error = nil;
|
||||
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");
|
||||
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");
|
||||
XCTAssertNil(error, @"No Error should occur on loading");
|
||||
XCTAssertNotNil(document, @"Document should not be nil");
|
||||
XCTAssertTrue(document.encrypted, @"Loaded but unencrypted should be not decrypted");
|
||||
XCTAssertFalse([document unlockWithPassword:@"123" keyFileURL:nil error:&error], @"Decryption should fail");
|
||||
XCTAssertNotNil(error, @"Error should occur on unlocking with correct password");
|
||||
}
|
||||
|
||||
- (void)testLoadDatabaseVerions2 {
|
||||
@@ -46,8 +49,8 @@
|
||||
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");
|
||||
XCTAssertNil(error, @"No Error should occur on loading");
|
||||
XCTAssertNotNil(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");
|
||||
|
||||
@@ -6,11 +6,17 @@
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPDatabasePasswordAndKeyfile.h"
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "MPDocument.h"
|
||||
#import "KPKCompositeKey.h"
|
||||
|
||||
@interface MPDatabasePasswordAndKeyfile : XCTestCase {
|
||||
MPDocument *_database;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation MPDatabasePasswordAndKeyfile
|
||||
|
||||
- (void)setUp {
|
||||
@@ -22,9 +28,9 @@
|
||||
}
|
||||
|
||||
- (void)testSetPassword {
|
||||
STAssertNil(_database.compositeKey, @"New database should not have a composite key");
|
||||
STAssertTrue([_database changePassword:@"password" keyFileURL:nil], @"Setting the Password should succeed");
|
||||
STAssertFalse([_database changePassword:nil keyFileURL:nil], @"resetting the password and key to nil should not work");
|
||||
XCTAssertNil(_database.compositeKey, @"New database should not have a composite key");
|
||||
XCTAssertTrue([_database changePassword:@"password" keyFileURL:nil], @"Setting the Password should succeed");
|
||||
XCTAssertFalse([_database changePassword:nil keyFileURL:nil], @"resetting the password and key to nil should not work");
|
||||
}
|
||||
|
||||
- (void)testSetKeyfile {/*
|
||||
|
||||
Reference in New Issue
Block a user