pEpObjCTests/PEPPassphraseCacheTest.m
author Dirk Zimmermann <dz@pep.security>
Thu, 25 Jun 2020 17:08:21 +0200
branchIOSAD-172
changeset 1455 1b007f0523d3
parent 1453 2da4a0ba6b07
child 1458 8e31ce01a795
permissions -rw-r--r--
IOSAD-172 Test 20 and 21 passphrases
dz@1449
     1
//
dz@1449
     2
//  PEPPassphraseCacheTest.m
dz@1449
     3
//  pEpObjCAdapterTests
dz@1449
     4
//
dz@1449
     5
//  Created by Dirk Zimmermann on 25.06.20.
dz@1449
     6
//  Copyright © 2020 p≡p. All rights reserved.
dz@1449
     7
//
dz@1449
     8
dz@1449
     9
#import <XCTest/XCTest.h>
dz@1449
    10
dz@1449
    11
#import "PEPPassphraseCache.h"
dz@1449
    12
dz@1450
    13
@interface PEPPassphraseCacheTest : XCTestCase
dz@1449
    14
dz@1450
    15
@property (nonatomic) PEPPassphraseCache *cache;
dz@1449
    16
dz@1449
    17
@end
dz@1449
    18
dz@1449
    19
@implementation PEPPassphraseCacheTest
dz@1449
    20
dz@1449
    21
- (void)setUp
dz@1449
    22
{
dz@1450
    23
    self.cache = [[PEPPassphraseCache alloc] init];
dz@1449
    24
}
dz@1449
    25
dz@1449
    26
- (void)testContainsEmptyPassphrase
dz@1449
    27
{
dz@1449
    28
    XCTAssertEqual(self.cache.passphrases.count, 1);
dz@1449
    29
    XCTAssertEqualObjects(self.cache.passphrases, @[@""]);
dz@1449
    30
}
dz@1449
    31
dz@1449
    32
- (void)testContainsSetPassphrase
dz@1449
    33
{
dz@1449
    34
    NSString *passphrase = @"somepass";
dz@1449
    35
    [self.cache addPassphrase:passphrase];
dz@1449
    36
    XCTAssertEqual(self.cache.passphrases.count, 2);
dz@1453
    37
    NSArray *expected = @[@"", passphrase];
dz@1453
    38
    XCTAssertEqualObjects(self.cache.passphrases, expected);
dz@1453
    39
}
dz@1453
    40
dz@1453
    41
- (void)testContainsSetPassphrases
dz@1453
    42
{
dz@1453
    43
    NSString *passphrase1 = @"somepass1";
dz@1453
    44
    NSString *passphrase2 = @"somepass2";
dz@1453
    45
dz@1453
    46
    [self.cache addPassphrase:passphrase1];
dz@1453
    47
    [self.cache addPassphrase:passphrase2];
dz@1453
    48
dz@1453
    49
    XCTAssertEqual(self.cache.passphrases.count, 3);
dz@1453
    50
    NSArray *expected = @[@"", passphrase1, passphrase2];
dz@1453
    51
    XCTAssertEqualObjects(self.cache.passphrases, expected);
dz@1449
    52
}
dz@1449
    53
dz@1455
    54
- (void)testTwentyPassphrases
dz@1455
    55
{
dz@1455
    56
    NSMutableArray *passphrases = [NSMutableArray arrayWithCapacity:20];
dz@1455
    57
    for (NSUInteger i = 0; i < 20; ++i) {
dz@1455
    58
        NSString *newPhrase = [NSString stringWithFormat:@"passphrase_%lu", (unsigned long) i];
dz@1455
    59
        [passphrases addObject:newPhrase];
dz@1455
    60
        [self.cache addPassphrase:newPhrase];
dz@1455
    61
    }
dz@1455
    62
dz@1455
    63
    XCTAssertEqual(self.cache.passphrases.count, passphrases.count + 1);
dz@1455
    64
    NSMutableArray *expected = [NSMutableArray arrayWithArray:passphrases];
dz@1455
    65
    [expected insertObject:@"" atIndex:0];
dz@1455
    66
    XCTAssertEqualObjects(self.cache.passphrases, expected);
dz@1455
    67
}
dz@1455
    68
dz@1455
    69
- (void)testTwentyOnePassphrases
dz@1455
    70
{
dz@1455
    71
    NSMutableArray *passphrases = [NSMutableArray arrayWithCapacity:20];
dz@1455
    72
    for (NSUInteger i = 0; i < 20; ++i) {
dz@1455
    73
        NSString *newPhrase = [NSString stringWithFormat:@"passphrase_%lu", (unsigned long) i];
dz@1455
    74
        [passphrases addObject:newPhrase];
dz@1455
    75
        [self.cache addPassphrase:newPhrase];
dz@1455
    76
    }
dz@1455
    77
dz@1455
    78
    NSString *latestPassphrase = @"theLatest";
dz@1455
    79
    [passphrases replaceObjectAtIndex:0 withObject:latestPassphrase];
dz@1455
    80
dz@1455
    81
    XCTAssertEqual(self.cache.passphrases.count, passphrases.count + 1);
dz@1455
    82
    NSMutableArray *expected = [NSMutableArray arrayWithArray:passphrases];
dz@1455
    83
    [expected insertObject:@"" atIndex:0];
dz@1455
    84
    XCTAssertEqualObjects(self.cache.passphrases, expected);
dz@1455
    85
}
dz@1455
    86
dz@1449
    87
@end