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

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];