Added loading tests for meta entries

Added Test KDB database with custom icon
This commit is contained in:
michael starke
2013-08-05 21:26:06 +02:00
parent f87e60442e
commit b913d37797
10 changed files with 114 additions and 25 deletions

View File

@@ -129,6 +129,11 @@
4C5FE9AE17843CE20001D5A8 /* MPSelectedAttachmentTableCellView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C5FE9AD17843CE20001D5A8 /* MPSelectedAttachmentTableCellView.m */; };
4C61EA0316D2FD0800AC519E /* MPOutlineViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C61EA0216D2FD0800AC519E /* MPOutlineViewController.m */; };
4C61EA0516D2FFE200AC519E /* OutlineView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C61EA0416D2FFE200AC519E /* OutlineView.xib */; };
4C6366AC17AF1E0100AAF17D /* NSColor+KeePassKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6366AB17AF1E0100AAF17D /* NSColor+KeePassKit.m */; };
4C6366AF17AF207600AAF17D /* KPKTestHexColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C6366AE17AF207600AAF17D /* KPKTestHexColor.m */; };
4C6366B317AFB52500AAF17D /* CustomIcon_Password_1234.kdbx in Resources */ = {isa = PBXBuildFile; fileRef = 4C6366B017AFB52500AAF17D /* CustomIcon_Password_1234.kdbx */; };
4C6366B417AFB52500AAF17D /* CustomIcon_Password_1234.xml in Resources */ = {isa = PBXBuildFile; fileRef = 4C6366B117AFB52500AAF17D /* CustomIcon_Password_1234.xml */; };
4C6366B517AFB52500AAF17D /* KDB1_KeePassX_test.kdb in Resources */ = {isa = PBXBuildFile; fileRef = 4C6366B217AFB52500AAF17D /* KDB1_KeePassX_test.kdb */; };
4C63B8FB17A3154D0091BD72 /* MPContextToolbarButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C63B8FA17A3154D0091BD72 /* MPContextToolbarButton.m */; };
4C65C79C16DD283900E32CFF /* MPToolbarButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C65C79B16DD283900E32CFF /* MPToolbarButton.m */; };
4C65FAE916D16DDB006E0577 /* MPPasswordInputController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C65FAE716D16DDB006E0577 /* MPPasswordInputController.m */; };
@@ -504,6 +509,13 @@
4C61EA0116D2FD0800AC519E /* MPOutlineViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPOutlineViewController.h; sourceTree = "<group>"; };
4C61EA0216D2FD0800AC519E /* MPOutlineViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOutlineViewController.m; sourceTree = "<group>"; };
4C61EA0416D2FFE200AC519E /* OutlineView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OutlineView.xib; sourceTree = "<group>"; };
4C6366AA17AF1E0100AAF17D /* NSColor+KeePassKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSColor+KeePassKit.h"; sourceTree = "<group>"; };
4C6366AB17AF1E0100AAF17D /* NSColor+KeePassKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSColor+KeePassKit.m"; sourceTree = "<group>"; };
4C6366AD17AF207600AAF17D /* KPKTestHexColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KPKTestHexColor.h; sourceTree = "<group>"; };
4C6366AE17AF207600AAF17D /* KPKTestHexColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KPKTestHexColor.m; sourceTree = "<group>"; };
4C6366B017AFB52500AAF17D /* CustomIcon_Password_1234.kdbx */ = {isa = PBXFileReference; lastKnownFileType = file; name = CustomIcon_Password_1234.kdbx; path = Databases/CustomIcon_Password_1234.kdbx; sourceTree = "<group>"; };
4C6366B117AFB52500AAF17D /* CustomIcon_Password_1234.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = CustomIcon_Password_1234.xml; path = Databases/CustomIcon_Password_1234.xml; sourceTree = "<group>"; };
4C6366B217AFB52500AAF17D /* KDB1_KeePassX_test.kdb */ = {isa = PBXFileReference; lastKnownFileType = file; name = KDB1_KeePassX_test.kdb; path = Databases/KDB1_KeePassX_test.kdb; sourceTree = "<group>"; };
4C63B8F917A3154D0091BD72 /* MPContextToolbarButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPContextToolbarButton.h; sourceTree = "<group>"; };
4C63B8FA17A3154D0091BD72 /* MPContextToolbarButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPContextToolbarButton.m; sourceTree = "<group>"; };
4C65C79A16DD283900E32CFF /* MPToolbarButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPToolbarButton.h; sourceTree = "<group>"; };
@@ -876,6 +888,9 @@
4C18F9AC178E123200890BCE /* Databases */ = {
isa = PBXGroup;
children = (
4C6366B017AFB52500AAF17D /* CustomIcon_Password_1234.kdbx */,
4C6366B117AFB52500AAF17D /* CustomIcon_Password_1234.xml */,
4C6366B217AFB52500AAF17D /* KDB1_KeePassX_test.kdb */,
4C19E4FF178E26EF002F2CD0 /* Test_Password_1234.kdbx */,
4C18F9AA178E122500890BCE /* Test_Password_1234.kdb */,
);
@@ -1202,6 +1217,8 @@
4CECB31617AC326D00EAFB0F /* KPKLegacyWritingTest.m */,
4CAC614117AD319200023F9E /* KPKTestXmlParsing.h */,
4CAC614217AD319200023F9E /* KPKTestXmlParsing.m */,
4C6366AD17AF207600AAF17D /* KPKTestHexColor.h */,
4C6366AE17AF207600AAF17D /* KPKTestHexColor.m */,
);
path = MacPassTests;
sourceTree = "<group>";
@@ -1584,6 +1601,8 @@
4C055E73179620BF00BD2BAB /* NSString+CommandString.m */,
4C1842C1179B69E600E2F5BC /* NSData+HashedData.h */,
4C1842C2179B69E700E2F5BC /* NSData+HashedData.m */,
4C6366AA17AF1E0100AAF17D /* NSColor+KeePassKit.h */,
4C6366AB17AF1E0100AAF17D /* NSColor+KeePassKit.m */,
);
path = Categories;
sourceTree = "<group>";
@@ -1803,6 +1822,9 @@
4C18F9AB178E122500890BCE /* Test_Password_1234.kdb in Resources */,
4C19E500178E26EF002F2CD0 /* Test_Password_1234.kdbx in Resources */,
4C305F3E179A1A760082334F /* image.png in Resources */,
4C6366B317AFB52500AAF17D /* CustomIcon_Password_1234.kdbx in Resources */,
4C6366B417AFB52500AAF17D /* CustomIcon_Password_1234.xml in Resources */,
4C6366B517AFB52500AAF17D /* KDB1_KeePassX_test.kdb in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1895,6 +1917,7 @@
4C79E80917A9485600AC6CD2 /* KPKTestNSCopying.m in Sources */,
4CECB31717AC326D00EAFB0F /* KPKLegacyWritingTest.m in Sources */,
4CAC614317AD319200023F9E /* KPKTestXmlParsing.m in Sources */,
4C6366AF17AF207600AAF17D /* KPKTestHexColor.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2100,6 +2123,7 @@
4CFB5E9F17AAD20200D9B10C /* Kdb4Group+Undo.m in Sources */,
4CE3E62617AB0D2D00D9E4B4 /* MPAttachmentTableDataSource.m in Sources */,
4CF4FEE017AEA4A400712774 /* UUID+Pasterboard.m in Sources */,
4C6366AC17AF1E0100AAF17D /* NSColor+KeePassKit.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

Binary file not shown.

View File

@@ -8,12 +8,6 @@
#import <SenTestingKit/SenTestingKit.h>
@class KPKPassword;
@interface KPKLegacyLoadingTest : SenTestCase {
@private
NSData *_data;
KPKPassword *_password;
}
@interface KPKLegacyLoadingTest : SenTestCase
@end

View File

@@ -7,32 +7,26 @@
//
#import "KPKLegacyLoadingTest.h"
#import "KPKTree+Serializing.h"
#import "KPKPassword.h"
#import "KPKMetaData.h"
#import "KPKIcon.h"
#import "KPKErrors.h"
@implementation KPKLegacyLoadingTest
- (void)setUp {
NSBundle *myBundle = [NSBundle bundleForClass:[self class]];
NSURL *url = [myBundle URLForResource:@"Test_Password_1234" withExtension:@"kdb"];
_data = [NSData dataWithContentsOfURL:url];
_password = [[KPKPassword alloc] initWithPassword:@"1234" key:nil];
}
- (void)tearDown {
_data = nil;
_password = nil;
}
- (void)testValidFile {
KPKTree *tree = [[KPKTree alloc] initWithData:_data password:_password error:NULL];
KPKPassword *password = [[KPKPassword 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");
}
- (void)testInvalidFile {
NSError *error;
uint8 bytes[] = {0x00,0x11,0x22,0x33,0x44};
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");
@@ -40,4 +34,21 @@
STAssertTrue(KPKErrorUnknownFileFormat == [error code], @"Error should be Unknown file format");
}
- (void)testMetaParsing {
NSData *data = [self _loadTestDataBase:@"KDB1_KeePassX_test" extension:@"kdb"];
KPKPassword *password = [[KPKPassword alloc] initWithPassword:@"test" key:nil];
KPKTree *tree = [[KPKTree alloc] initWithData:data password:password error:NULL];
STAssertNotNil(tree, @"Tree shoudl be loaded" );
KPKIcon *icon = [tree.metaData.customIcons lastObject];
STAssertNotNil(icon, @"Should load one Icon");
}
- (NSData *)_loadTestDataBase:(NSString *)name extension:(NSString *)extension {
NSBundle *myBundle = [NSBundle bundleForClass:[self class]];
NSURL *url = [myBundle URLForResource:name withExtension:extension];
return [NSData dataWithContentsOfURL:url];
}
@end

View File

@@ -0,0 +1,13 @@
//
// KPKTestHexColor.h
// MacPass
//
// Created by Michael Starke on 05.08.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import <SenTestingKit/SenTestingKit.h>
@interface KPKTestHexColor : SenTestCase
@end

View File

@@ -0,0 +1,47 @@
//
// KPKTestHexColor.m
// MacPass
//
// Created by Michael Starke on 05.08.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "KPKTestHexColor.h"
#import "NSColor+KeePassKit.h"
@implementation KPKTestHexColor
- (void)testHexToColor {
NSString *redHex = @"00ff0000";
NSString *blueHex = @"000000ff";
NSString *greeHex = @"0000ff00";
NSColor *red = [NSColor colorWithHexString:redHex];
NSColor *blue = [NSColor colorWithHexString:blueHex];
NSColor *green = [NSColor colorWithHexString:greeHex];
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");
STAssertEquals([blue redComponent], 0.0, @"Blue color should have 0% red");
STAssertEquals([blue blueComponent], 1.0, @"Blue color should have 100% blue");
STAssertEquals([blue greenComponent], 0.0, @"Blue color should have 0% green");
STAssertEquals([green redComponent], 0.0, @"Green color should have 0% red");
STAssertEquals([green blueComponent], 0.0, @"Green color should have 0% blue");
STAssertEquals([green greenComponent], 1.0, @"Green color should have 100% green");
}
- (void)testColorRefReading {
uint32_t colorBytes = 0x000000ff;
uint32_t swappedData = colorBytes;//CFSwapInt32(colorBytes);
NSData *colorData = [NSData dataWithBytesNoCopy:&swappedData length:sizeof(uint32_t) freeWhenDone:NO];
NSColor *color = [NSColor colorWithData:colorData];
STAssertEquals([color redComponent], 1.0, @"Red 100%");
STAssertEquals([color blueComponent], 0.0, @"Blue 0%");
STAssertEquals([color greenComponent], 0.0, @"Green 0%");
}
@end

View File

@@ -35,7 +35,7 @@
entry.username = @"Username";
entry.password = @"Password";
uint8 bytes[] = { 0xFF, 0x00, 0xFF, 0x00, 0xFF };
uint8_t bytes[] = { 0xFF, 0x00, 0xFF, 0x00, 0xFF };
NSData *data = [[NSData alloc] initWithBytes:bytes length:5];
KPKBinary *binary = [[KPKBinary alloc] init];

View File

@@ -36,7 +36,7 @@
entry.username = @"Username";
entry.password = @"Password";
uint8 bytes[] = { 0xFF, 0x00, 0xFF, 0x00, 0xFF };
uint8_t bytes[] = { 0xFF, 0x00, 0xFF, 0x00, 0xFF };
NSData *data = [[NSData alloc] initWithBytes:bytes length:5];
KPKBinary *binary = [[KPKBinary alloc] init];