Peter 76e5a7fab6 Add 'submodules/HockeySDK-iOS/' from commit 'c7d0c7026303253e2ac576c02655691e5d314fe2'
git-subtree-dir: submodules/HockeySDK-iOS
git-subtree-mainline: 085acd26c4432939403765234266e3c1be0f3dd9
git-subtree-split: c7d0c7026303253e2ac576c02655691e5d314fe2
2019-06-11 18:53:14 +01:00

81 lines
2.7 KiB
Objective-C

//
// BITKeychainUtilsTests.m
// HockeySDK
//
// Created by Stephan Diederich on 23.09.13.
//
//
#import <XCTest/XCTest.h>
#import <OCHamcrestIOS/OCHamcrestIOS.h>
#import <OCMockitoIOS/OCMockitoIOS.h>
#import "HockeySDK.h"
#import "BITKeychainUtils.h"
@interface BITKeychainUtilsTests : XCTestCase {
}
@end
@implementation BITKeychainUtilsTests
- (void)setUp {
[super setUp];
// Set-up code here.
}
- (void)tearDown {
// Tear-down code here.
[super tearDown];
}
- (void)testThatBITKeychainHelperStoresAndRetrievesPassword {
[BITKeychainUtils deleteItemForUsername:@"Peter" andServiceName:@"Test" error:nil];
BOOL success = [BITKeychainUtils storeUsername:@"Peter"
andPassword:@"Pan"
forServiceName:@"Test"
updateExisting:YES
error:nil];
assertThatBool(success, isTrue());
NSString *pass = [BITKeychainUtils getPasswordForUsername:@"Peter"
andServiceName:@"Test"
error:NULL];
assertThat(pass, equalTo(@"Pan"));
}
- (void)testThatBITKeychainHelperStoresAndRetrievesPasswordThisDeviceOnly {
[BITKeychainUtils deleteItemForUsername:@"Peter" andServiceName:@"Test" error:nil];
BOOL success = [BITKeychainUtils storeUsername:@"Peter"
andPassword:@"PanThisDeviceOnly"
forServiceName:@"Test"
updateExisting:YES
accessibility:kSecAttrAccessibleAlwaysThisDeviceOnly
error:nil];
assertThatBool(success, isTrue());
NSString *pass = [BITKeychainUtils getPasswordForUsername:@"Peter"
andServiceName:@"Test"
error:NULL];
assertThat(pass, equalTo(@"PanThisDeviceOnly"));
}
- (void)testThatBITKeychainHelperRemovesAStoredPassword {
[BITKeychainUtils deleteItemForUsername:@"Peter" andServiceName:@"Test" error:nil];
[BITKeychainUtils storeUsername:@"Peter"
andPassword:@"Pan"
forServiceName:@"Test"
updateExisting:YES
error:nil];
BOOL success = [BITKeychainUtils deleteItemForUsername:@"Peter" andServiceName:@"Test" error:nil];
assertThatBool(success, isTrue());
NSString *pass = [BITKeychainUtils getPasswordForUsername:@"Peter"
andServiceName:@"Test"
error:NULL];
assertThat(pass, equalTo(nil));
}
@end