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