5 // Created by Love Hörnquist Åstrand on 2017-02-28.
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"
21 @interface KCPairingTest : XCTestCase
25 @implementation KCPairingTest
27 - (void)checkRoundtrip:(KCPairingChannelContext *)c1 check:(NSString *)check
29 KCPairingChannelContext *c2;
32 data = [NSKeyedArchiver archivedDataWithRootObject:c1 requiringSecureCoding:TRUE error:NULL];
33 XCTAssertNotNil(data, "data should be valid: %@", check);
35 NSKeyedUnarchiver* unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:data error:nil];
36 c2 = [unarchiver decodeObjectOfClass:[KCPairingChannelContext class] forKey:NSKeyedArchiveRootObjectKey];
38 XCTAssertEqualObjects(c1, c2, "c1 should be same as c2: %@", check);
41 - (void)testPairingChannelContextValid {
42 KCPairingChannelContext *c;
44 c = [[KCPairingChannelContext alloc] init];
46 [self checkRoundtrip:c check:@"empty"];
48 c.intent = KCPairingIntent_Type_None;
49 [self checkRoundtrip:c check:@"with intent"];
51 c.intent = @"invalid";
54 - (void)testPairingChannelContextInvalid {
55 KCPairingChannelContext *c1, *c2;
58 c1 = [[KCPairingChannelContext alloc] init];
59 c1.intent = @"invalid";
61 data = [NSKeyedArchiver archivedDataWithRootObject:c1 requiringSecureCoding:TRUE error:NULL];
62 XCTAssertNotNil(data, "data should be valid");
64 NSKeyedUnarchiver* unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:data error:nil];
65 c2 = [unarchiver decodeObjectOfClass:[KCPairingChannelContext class] forKey:NSKeyedArchiveRootObjectKey];
67 XCTAssertNil(c2, "c2 should be NULL");