PageRenderTime 77ms CodeModel.GetById 12ms app.highlight 61ms RepoModel.GetById 1ms app.codeStats 0ms

/core/autoinstaller/UpdateEngineExtensions/SignedPlistServerTest.m

http://macfuse.googlecode.com/
Objective C | 165 lines | 138 code | 20 blank | 7 comment | 1 complexity | 202ed2bc406c47997342fc72c1b3788d MD5 | raw file
  1//
  2//  SignedPlistServerTest.m
  3//  autoinstaller
  4//
  5//  Created by Greg Miller on 7/18/08.
  6//  Copyright 2008 Google Inc. All rights reserved.
  7//
  8
  9#import <SenTestingKit/SenTestingKit.h>
 10#import "KSExistenceChecker.h"
 11#import "KSTicket.h"
 12#import "SignedPlistServer.h"
 13#import "Signer.h"
 14
 15
 16static unsigned char public_key_der[] = {
 170x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
 180x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81,
 190x89, 0x02, 0x81, 0x81, 0x00, 0xf1, 0x66, 0x86, 0xc8, 0xca, 0x65, 0xb5,
 200x40, 0x31, 0x1c, 0xd1, 0x10, 0x62, 0x46, 0xcb, 0x60, 0x01, 0xd3, 0x32,
 210x80, 0xb8, 0x2f, 0x75, 0x2a, 0x46, 0xbd, 0x42, 0xb1, 0xb6, 0xcf, 0x81,
 220xd9, 0xe9, 0xb9, 0xdd, 0x02, 0xbf, 0xf6, 0xfa, 0x6f, 0x9e, 0x06, 0x16,
 230x22, 0xb8, 0x95, 0x1a, 0x53, 0xba, 0xdb, 0x6e, 0x55, 0x66, 0x94, 0xfb,
 240xe8, 0xab, 0xcd, 0xfa, 0xd2, 0x05, 0xdf, 0xf4, 0xfd, 0x9c, 0x08, 0x3a,
 250x23, 0x9c, 0xe3, 0x95, 0xc3, 0x59, 0x17, 0xe9, 0xfb, 0xea, 0xf1, 0x6c,
 260x3f, 0x42, 0xc8, 0xfb, 0xfb, 0x0e, 0x6a, 0x6c, 0xec, 0x40, 0x0d, 0x0d,
 270x1f, 0x31, 0x5c, 0xa8, 0x94, 0x7b, 0x54, 0x0e, 0x44, 0xf0, 0x27, 0xa3,
 280xb1, 0x72, 0xbb, 0x5d, 0x78, 0xd4, 0x76, 0x05, 0x1c, 0x78, 0x9d, 0x12,
 290xae, 0x37, 0xff, 0x45, 0x9f, 0x57, 0xf9, 0x98, 0xdc, 0xd0, 0x03, 0xec,
 300xa3, 0x02, 0x03, 0x01, 0x00, 0x01
 31};
 32static unsigned int public_key_der_len = 162;
 33
 34
 35static NSString *const kUnsignedPlist = 
 36@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
 37@"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
 38@"<plist version=\"1.0\">"
 39@"<dict>"
 40@"	<key>Rules</key>"
 41@"	<array>"
 42@"		<dict>"
 43@"			<key>Codebase</key>"
 44@"			<string>http://macfuse.googlecode.com/svn/releases/MacFUSE-1.7.dmg</string>"
 45@"			<key>Hash</key>"
 46@"			<string>9I5CFGd/dHClCLycl2UJlvW3LKg=</string>"
 47@"			<key>Predicate</key>"
 48@"			<string>1 == 1</string>"
 49@"			<key>ProductID</key>"
 50@"			<string>com.google.filesystems.fusefs</string>"
 51@"			<key>Size</key>"
 52@"			<string>1732368</string>"
 53@"			<key>Version</key>"
 54@"			<string>1.7.1</string>"
 55@"		</dict>"
 56@"	</array>"
 57@"</dict>"
 58@"</plist>"
 59;
 60
 61static NSString *const kSignedPlist = 
 62@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
 63@"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
 64@"<plist version=\"1.0\">"
 65@"<dict>"
 66@"	<key>Rules</key>"
 67@"	<array>"
 68@"		<dict>"
 69@"			<key>Codebase</key>"
 70@"			<string>http://macfuse.googlecode.com/svn/releases/MacFUSE-1.7.dmg</string>"
 71@"			<key>Hash</key>"
 72@"			<string>9I5CFGd/dHClCLycl2UJlvW3LKg=</string>"
 73@"			<key>Predicate</key>"
 74@"			<string>1 == 1</string>"
 75@"			<key>ProductID</key>"
 76@"			<string>com.google.filesystems.fusefs</string>"
 77@"			<key>Size</key>"
 78@"			<string>1732368</string>"
 79@"			<key>Version</key>"
 80@"			<string>1.7.1</string>"
 81@"		</dict>"
 82@"	</array>"
 83@"	<key>Signature</key>"
 84@"	<data>"
 85@"	juw5jH4IfedUlYYZI+I8D2p5V95pzwFElFVC5U3q34HpLG0gSNDvEFaPMdkhenv4Chgd"
 86@"	dGBufYefSMA9qQrSkUWVXTeENAzJJ765Wt82D+ttJ6l3vAvh9GzdUe3rchJGTFnB71lZ"
 87@"	ChS8nOXZRvmsS4PT+5Bx2mRq/FJQPzgadD8="
 88@"	</data>"
 89@"</dict>"
 90@"</plist>"
 91;
 92
 93
 94@interface SignedPlistServerTest : SenTestCase {
 95 @private
 96  NSURL *url_;
 97  Signer *signer_;
 98  SignedPlistServer *server_;
 99}
100@end
101
102@implementation SignedPlistServerTest
103
104- (void)setUp {
105  NSData *pubKey = [NSData dataWithBytes:public_key_der
106                                  length:public_key_der_len];
107  signer_ = [[Signer alloc] initWithPublicKey:pubKey privateKey:nil];
108  STAssertNotNil(signer_, nil);
109  
110  url_ = [[NSURL alloc] initWithString:
111           @"http://macfuse.googlecode.com/svn/trunk/CurrentRelease.plist"];
112  STAssertNotNil(url_, nil);
113  
114  server_ = [[SignedPlistServer alloc] initWithURL:url_
115                                            signer:signer_];
116  STAssertNotNil(server_, nil);
117  
118  KSExistenceChecker *xc = [KSPathExistenceChecker checkerWithPath:@"/"];
119  KSTicket *fakeTicket = [KSTicket ticketWithProductID:@"com.google.filesystems.fusefs"
120                                               version:@"0"
121                                      existenceChecker:xc
122                                             serverURL:url_];
123  [server_ requestsForTickets:[NSArray arrayWithObject:fakeTicket]];
124}
125
126- (void)tearDown {
127  [signer_ release];
128  [url_ release];
129  [server_ release];
130}
131
132- (void)testCreation {  
133  SignedPlistServer *server = [[[SignedPlistServer alloc] init] autorelease];
134  STAssertNil(server, nil);
135  
136  server = [[[SignedPlistServer alloc] initWithURL:url_] autorelease];
137  STAssertNotNil(server, nil);
138  
139  server = [[[SignedPlistServer alloc] initWithURL:url_
140                                            signer:signer_] autorelease];
141  STAssertNotNil(server, nil);
142}
143
144- (void)testUnsignedPlist {
145  NSDictionary *plist = [kUnsignedPlist propertyList];
146  NSData *plistData = [NSPropertyListSerialization
147                       dataFromPropertyList:plist
148                       format:NSPropertyListXMLFormat_v1_0
149                       errorDescription:NULL];
150  NSArray *infos = [server_ updateInfosForResponse:nil data:plistData];
151  STAssertNil(infos, nil);
152}
153
154- (void)testSignedPlist {
155  NSDictionary *plist = [kSignedPlist propertyList];
156  NSData *plistData = [NSPropertyListSerialization
157                       dataFromPropertyList:plist
158                       format:NSPropertyListXMLFormat_v1_0
159                       errorDescription:NULL];
160  NSArray *infos = [server_ updateInfosForResponse:nil data:plistData];
161  STAssertNotNil(infos, nil);
162  STAssertTrue([infos count] == 1, nil);
163}
164
165@end