File: basic.m

package info (click to toggle)
gnustep-base 1.31.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,580 kB
  • sloc: objc: 239,446; ansic: 36,519; cpp: 122; sh: 112; makefile: 100; xml: 32
file content (51 lines) | stat: -rw-r--r-- 1,605 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#import "ObjectTesting.h"
#import "../../../Headers/GNUstepBase/config.h"
#import "../../../Headers/Foundation/Foundation.h"
#import "../../../Headers/GNUstepBase/GSTLS.h"

int
main() {
  NSAutoreleasePool *arp = [NSAutoreleasePool new];
START_SET("TLS support")
#if GS_USE_GNUTLS
#ifndef HAVE_GNUTLS_X509_PRIVKEY_IMPORT2
 testHopeful = YES;
#endif
  GSTLSPrivateKey       *k;
  GSTLSCertificateList  *c;
  GSTLSCredentials	*cred;
  NSDateFormatter       *dateFormatter;
  NSDate                *expiresAt;

  k = [GSTLSPrivateKey keyFromFile: @"test.key" withPassword: @"asdf"]; 
  PASS(k != nil, "OpenSSL encrypted key can be loaded");

  c = [GSTLSCertificateList listFromFile: @"test.crt"];
  PASS(c != nil, "Certificate list can be loaded from a file");  

  PASS([c expiresAt: -1] == nil, "Return nil for invalid index");
  PASS([c expiresAt: 2] == nil, "Return nil for invalid index");
  expiresAt = [c expiresAt: 0];
  dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss zzz"];
  /* Test guaranteed to fail on 32-bit architectures.  */
#if __LP64__
  PASS_EQUAL(expiresAt,
    [dateFormatter dateFromString: @"2118-12-14 15:35:11 +0000"],
    "Expiration date can be retrieved");
#endif
  [dateFormatter release];
  PASS_EQUAL([c expiresAt], expiresAt,
    "Expiration for entire list is that of the single item");
  
  cred = [GSTLSCredentials selfSigned: YES];
  NSLog(@"%@", cred);
  PASS(cred != nil, "generates self signed certificate");
#else
  SKIP("TLS support disabled");
#endif
  
  END_SET("TLS support");
  DESTROY(arp);
  return 0;
}