]> git.saurik.com Git - apple/security.git/blob - keychain/trust/TrustedPeersTests/TPPeerStableInfoTests.m
Security-58286.41.2.tar.gz
[apple/security.git] / keychain / trust / TrustedPeersTests / TPPeerStableInfoTests.m
1 /*
2 * Copyright (c) 2017 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #import <XCTest/XCTest.h>
25 #import <TrustedPeers/TrustedPeers.h>
26 #import "TPDummySigningKey.h"
27
28 @interface TPPeerStableInfoTests : XCTestCase
29
30 @end
31
32 @implementation TPPeerStableInfoTests
33
34 - (void)testSigningKeyIsUnavailable
35 {
36 NSData *keyData = [@"key123" dataUsingEncoding:NSUTF8StringEncoding];
37 TPDummySigningKey *key = [[TPDummySigningKey alloc] initWithPublicKeyData:keyData];
38 key.privateKeyIsAvailable = NO;
39
40 NSError *error = nil;
41 TPPeerStableInfo *info
42 = [TPPeerStableInfo stableInfoWithDict:@{}
43 clock:1
44 policyVersion:1
45 policyHash:@"foo"
46 policySecrets:nil
47 trustSigningKey:key
48 error:&error];
49 XCTAssertNil(info);
50 XCTAssertNotNil(error);
51 }
52
53 - (void)testNonDictionary
54 {
55 NSData *data = [NSPropertyListSerialization dataWithPropertyList:@[ @"foo", @"bar"]
56 format:NSPropertyListXMLFormat_v1_0
57 options:0
58 error:NULL];
59 TPPeerStableInfo *info
60 = [TPPeerStableInfo stableInfoWithPListData:data
61 stableInfoSig:data];
62 XCTAssertNil(info);
63 }
64
65 - (void)testBadClock
66 {
67 NSData *data = [TPUtils serializedPListWithDictionary:@{
68 @"clock": @"five"
69 }];
70 TPPeerStableInfo *info
71 = [TPPeerStableInfo stableInfoWithPListData:data
72 stableInfoSig:data];
73 XCTAssertNil(info);
74 }
75
76 - (void)testBadPolicyVersion
77 {
78 NSData *data = [TPUtils serializedPListWithDictionary:@{
79 @"clock": @5,
80 @"policyVersion": @"five",
81 }];
82 TPPeerStableInfo *info
83 = [TPPeerStableInfo stableInfoWithPListData:data
84 stableInfoSig:data];
85 XCTAssertNil(info);
86 }
87
88 - (void)testBadPolicyHash
89 {
90 NSData *data = [TPUtils serializedPListWithDictionary:@{
91 @"clock": @5,
92 @"policyVersion": @5,
93 @"policyHash": @5
94 }];
95 TPPeerStableInfo *info
96 = [TPPeerStableInfo stableInfoWithPListData:data
97 stableInfoSig:data];
98 XCTAssertNil(info);
99 }
100
101 - (void)testBadSecrets
102 {
103 NSData *data = [TPUtils serializedPListWithDictionary:@{
104 @"clock": @5,
105 @"policyVersion": @5,
106 @"policyHash": @"foo",
107 @"policySecrets": @5
108 }];
109 TPPeerStableInfo *info
110 = [TPPeerStableInfo stableInfoWithPListData:data
111 stableInfoSig:data];
112 XCTAssertNil(info);
113 }
114
115 - (void)testBadSecretData
116 {
117 NSData *data = [TPUtils serializedPListWithDictionary:@{
118 @"clock": @5,
119 @"policyVersion": @5,
120 @"policyHash": @"foo",
121 @"policySecrets": @{
122 @"foo": @5
123 }
124 }];
125 TPPeerStableInfo *info
126 = [TPPeerStableInfo stableInfoWithPListData:data
127 stableInfoSig:data];
128 XCTAssertNil(info);
129 }
130
131 @end