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