Skip to content
This repository has been archived by the owner on Mar 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #350 from cloudant/349-unique-names
Browse files Browse the repository at this point in the history
Use unique paths for encrypted databases.
  • Loading branch information
rhyshort authored Dec 6, 2016
2 parents 32974bb + 05bb2f5 commit a49cfd7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
14 changes: 7 additions & 7 deletions CDTDatastoreTests/Encryption/DatastoreEncryptionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ - (void)testEncryptionKeyProviderReturnsTheSameProviderUsedToCreateTheDatastore

- (void)testInitWithoutEncryptionKeyThrowsException
{
NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"datastoreEncryptionTests_exception"];

TD_Database *db = [[TD_Database alloc] initWithPath:path];
Expand All @@ -61,7 +61,7 @@ - (void)testInitReturnsNilIfEncryptionKeyProviderReturnsAValueAndDBIsNotEncrypte
// Create non-encrypted db
CDTEncryptionKeyNilProvider *nilProvider = [CDTEncryptionKeyNilProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"datastoreEncryptionTests_nonEncryptDB"];
[TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:nilProvider];

Expand Down Expand Up @@ -119,7 +119,7 @@ - (void)testInitWithoutEncryptionKeyThrowsExceptionAlthoughDBIsAlreadyOpen
// Create non-encrypted db
CDTEncryptionKeyNilProvider *nilProvider = [CDTEncryptionKeyNilProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"datastoreEncryptionTests_alreadyOpen"];
TD_Database *db = [TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:nilProvider];

Expand All @@ -135,7 +135,7 @@ - (void)testInitReturnsNilIfEncryptionKeyProviderReturnsAValueWithAnAlreadyOpenN
// Create non-encrypted db
CDTEncryptionKeyNilProvider *nilProvider = [CDTEncryptionKeyNilProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"datastoreEncryptionTests_alreadyOpenNonEncryptDB"];
TD_Database *db = [TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:nilProvider];

Expand All @@ -155,7 +155,7 @@ - (void)testInitReturnsNilIfEncryptionKeyProviderDoesNotReturnTheKeyUsedToCipher
// Create encrypted db
CDTHelperFixedKeyProvider *fixedProvider = [CDTHelperFixedKeyProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"datastoreEncryptionTests_encryptDBWrongKey"];
[TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:fixedProvider];

Expand All @@ -176,7 +176,7 @@ - (void)testInitReturnsNilIfEncryptionKeyProviderReturnsNilWithAnAlreadyOpenEncr
// Create encrypted db
CDTHelperFixedKeyProvider *fixedProvider = [CDTHelperFixedKeyProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"datastoreEncryptionTests_alreadyOpenEncryptDB"];
TD_Database *db =
[TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:fixedProvider];
Expand All @@ -195,7 +195,7 @@ - (void)testInitReturnsNilIfEncryptionKeyProviderDoesNotReturnTheKeyUsedToOpenTh
// Create encrypted db
CDTHelperFixedKeyProvider *fixedProvider = [CDTHelperFixedKeyProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"datastoreEncryptionTests_encryptDBWrongKey_again"];
TD_Database *db =
[TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:fixedProvider];
Expand Down
25 changes: 13 additions & 12 deletions CDTDatastoreTests/Encryption/TD_DatabaseEncryptionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

#import "CDTEncryptionKeyNilProvider.h"
#import "CDTHelperFixedKeyProvider.h"
#import "CloudantSyncTests.h"
#import "CloudantTests+EncryptionTests.h"
#import "FMDatabase+SQLCipher.h"

#import "TD_Database.h"

@interface TD_DatabaseEncryptionTests : CloudantTests
@interface TD_DatabaseEncryptionTests : CloudantSyncTests

@end

Expand All @@ -33,7 +34,7 @@ - (void)testCreateEmptyWithEncryptionKeyNilProviderDoesNotCipherDatabase
// Create db
CDTEncryptionKeyNilProvider *provider = [CDTEncryptionKeyNilProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"TD_DatabaseEncryptionTests_NilNotCipher"];
[TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:provider];

Expand All @@ -50,7 +51,7 @@ - (void)testCreateEmptyWithFixedKeyProviderFails
// Create db
CDTHelperFixedKeyProvider *provider = [CDTHelperFixedKeyProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"TD_DatabaseEncryptionTests_DoCipherDb"];
TD_Database *db = [TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:provider];

Expand All @@ -62,7 +63,7 @@ - (void)testCreateEmptyWithFixedKeyProviderFails
- (void)testOpenFailsIfEncryptionKeyProviderReturnsAValue
{
CDTHelperFixedKeyProvider *provider = [CDTHelperFixedKeyProvider provider];
NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"TD_DatabaseEncryptionTests_OpenFails"];

TD_Database *db = [[TD_Database alloc] initWithPath:path];
Expand All @@ -88,7 +89,7 @@ - (void)testOpenFailsIfEncryptionKeyProviderReturnsAValueWithANonEncryptedDataba
// Create non-encrypted db
CDTEncryptionKeyNilProvider *nilProvider = [CDTEncryptionKeyNilProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"TD_DatabaseEncryptionTests_nonEncryptDB"];
[TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:nilProvider];

Expand Down Expand Up @@ -139,7 +140,7 @@ - (void)testReopenWithoutEncryptionKeyThrowsException
// Create non-encrypted db
CDTEncryptionKeyNilProvider *nilProvider = [CDTEncryptionKeyNilProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"TD_DatabaseEncryptionTests_reOpen"];
TD_Database *db = [TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:nilProvider];

Expand All @@ -153,7 +154,7 @@ - (void)testReopenFailsIfEncryptionKeyProviderReturnsAValueWithANonEncryptedData
// Create non-encrypted db
CDTEncryptionKeyNilProvider *nilProvider = [CDTEncryptionKeyNilProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"TD_DatabaseEncryptionTests_reOpenNonEncryptDB"];
TD_Database *db = [TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:nilProvider];

Expand All @@ -170,7 +171,7 @@ - (void)testCreateEmptyWithFixedKeyProviderCiphersDatabase
// Create db
CDTHelperFixedKeyProvider *provider = [CDTHelperFixedKeyProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"TD_DatabaseEncryptionTests_DoCipherDb"];
[TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:provider];

Expand All @@ -182,7 +183,7 @@ - (void)testCreateEmptyWithFixedKeyProviderCiphersDatabase
- (void)testOpenDoesNotFailIfEncryptionKeyProviderReturnsAValue
{
CDTHelperFixedKeyProvider *provider = [CDTHelperFixedKeyProvider provider];
NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"TD_DatabaseEncryptionTests_openNotFail"];

TD_Database *db = [[TD_Database alloc] initWithPath:path];
Expand All @@ -196,7 +197,7 @@ - (void)testOpenFailsIfEncryptionKeyProviderDoesNotReturnTheKeyUsedToCipherTheDa
// Create encrypted db
CDTHelperFixedKeyProvider *fixedProvider = [CDTHelperFixedKeyProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"TD_DatabaseEncryptionTests_encryptDBWrongKey"];
[TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:fixedProvider];

Expand All @@ -215,7 +216,7 @@ - (void)testReopenFailsIfEncryptionKeyProviderReturnsNilWithAnEncryptedDatabase
// Create encrypted db
CDTHelperFixedKeyProvider *fixedProvider = [CDTHelperFixedKeyProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"TD_DatabaseEncryptionTests_reOpenEncryptDB"];
TD_Database *db =
[TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:fixedProvider];
Expand All @@ -232,7 +233,7 @@ - (void)testReopenFailsIfEncryptionKeyProviderDoesNotReturnTheKeyUsedToCipherThe
// Create encrypted db
CDTHelperFixedKeyProvider *fixedProvider = [CDTHelperFixedKeyProvider provider];

NSString *path = [NSTemporaryDirectory()
NSString *path = [[self createTemporaryDirectoryAndReturnPath]
stringByAppendingPathComponent:@"TD_DatabaseEncryptionTests_reOpenEncryptDBWrongKey"];
TD_Database *db =
[TD_Database createEmptyDBAtPath:path withEncryptionKeyProvider:fixedProvider];
Expand Down

0 comments on commit a49cfd7

Please sign in to comment.