]> git.saurik.com Git - apple/security.git/blob - KeychainCircle/Tests/KCPairingTest.m
Security-59306.11.20.tar.gz
[apple/security.git] / KeychainCircle / Tests / KCPairingTest.m
1 //
2 // SecurityPairing.m
3 // Security_ios
4 //
5 // Created by Love Hörnquist Åstrand on 2017-02-28.
6 //
7
8 #import <Foundation/Foundation.h>
9 #import <Security/Security.h>
10 #import <Security/SecKeyPriv.h>
11 #import <Security/SecItemPriv.h>
12 #import "keychain/SecureObjectSync/SOSAccount.h"
13 #include "keychain/SecureObjectSync/SOSAccountPriv.h"
14 #include "keychain/SecureObjectSync/SOSCircle.h"
15 #import <KeychainCircle/KeychainCircle.h>
16 #import <XCTest/XCTest.h>
17 #import "SecCFWrappers.h"
18 #import "SOSRegressionUtilities.h"
19 #import "FakeSOSControl.h"
20
21 @interface KCPairingTest : XCTestCase
22
23 @end
24
25 @implementation KCPairingTest
26
27 - (void)checkRoundtrip:(KCPairingChannelContext *)c1 check:(NSString *)check
28 {
29 KCPairingChannelContext *c2;
30 NSData *data;
31
32 data = [NSKeyedArchiver archivedDataWithRootObject:c1 requiringSecureCoding:TRUE error:NULL];
33 XCTAssertNotNil(data, "data should be valid: %@", check);
34
35 NSKeyedUnarchiver* unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:data error:nil];
36 c2 = [unarchiver decodeObjectOfClass:[KCPairingChannelContext class] forKey:NSKeyedArchiveRootObjectKey];
37
38 XCTAssertEqualObjects(c1, c2, "c1 should be same as c2: %@", check);
39 }
40
41 - (void)testPairingChannelContextValid {
42 KCPairingChannelContext *c;
43
44 c = [[KCPairingChannelContext alloc] init];
45
46 [self checkRoundtrip:c check:@"empty"];
47
48 c.intent = KCPairingIntent_Type_None;
49 [self checkRoundtrip:c check:@"with intent"];
50
51 c.intent = @"invalid";
52 }
53
54 - (void)testPairingChannelContextInvalid {
55 KCPairingChannelContext *c1, *c2;
56 NSData *data;
57
58 c1 = [[KCPairingChannelContext alloc] init];
59 c1.intent = @"invalid";
60
61 data = [NSKeyedArchiver archivedDataWithRootObject:c1 requiringSecureCoding:TRUE error:NULL];
62 XCTAssertNotNil(data, "data should be valid");
63
64 NSKeyedUnarchiver* unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:data error:nil];
65 c2 = [unarchiver decodeObjectOfClass:[KCPairingChannelContext class] forKey:NSKeyedArchiveRootObjectKey];
66
67 XCTAssertNil(c2, "c2 should be NULL");
68 }
69
70
71 @end