2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #import <XCTest/XCTest.h>
25 #import <TrustedPeers/TrustedPeers.h>
26 #import "TPDummySigningKey.h"
28 @interface TPPeerStableInfoTests : XCTestCase
32 @implementation TPPeerStableInfoTests
34 - (void)testSigningKeyIsUnavailable
36 NSData *keyData = [@"key123" dataUsingEncoding:NSUTF8StringEncoding];
37 TPDummySigningKey *key = [[TPDummySigningKey alloc] initWithPublicKeyData:keyData];
38 key.privateKeyIsAvailable = NO;
41 TPPeerStableInfo *info
42 = [TPPeerStableInfo stableInfoWithDict:@{}
50 XCTAssertNotNil(error);
53 - (void)testNonDictionary
55 NSData *data = [NSPropertyListSerialization dataWithPropertyList:@[ @"foo", @"bar"]
56 format:NSPropertyListXMLFormat_v1_0
59 TPPeerStableInfo *info
60 = [TPPeerStableInfo stableInfoWithPListData:data
67 NSData *data = [TPUtils serializedPListWithDictionary:@{
70 TPPeerStableInfo *info
71 = [TPPeerStableInfo stableInfoWithPListData:data
76 - (void)testBadPolicyVersion
78 NSData *data = [TPUtils serializedPListWithDictionary:@{
80 @"policyVersion": @"five",
82 TPPeerStableInfo *info
83 = [TPPeerStableInfo stableInfoWithPListData:data
88 - (void)testBadPolicyHash
90 NSData *data = [TPUtils serializedPListWithDictionary:@{
95 TPPeerStableInfo *info
96 = [TPPeerStableInfo stableInfoWithPListData:data
101 - (void)testBadSecrets
103 NSData *data = [TPUtils serializedPListWithDictionary:@{
105 @"policyVersion": @5,
106 @"policyHash": @"foo",
109 TPPeerStableInfo *info
110 = [TPPeerStableInfo stableInfoWithPListData:data
115 - (void)testBadSecretData
117 NSData *data = [TPUtils serializedPListWithDictionary:@{
119 @"policyVersion": @5,
120 @"policyHash": @"foo",
125 TPPeerStableInfo *info
126 = [TPPeerStableInfo stableInfoWithPListData:data