/*
 * Licensed to Cloudkick, Inc ('Cloudkick') under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * Cloudkick licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var async = require('extern/async');
var fs =  require('fs');
var test = require('util/test');
var certgen = require('security/certgen');

exports['create selfsigned cert'] = function(assert, beforeExit) {
  var n = 0;

  certgen.selfsigned('testhostnamerare', '.tests/certs/t.key', '.tests/certs/t.crt', function(err) {
    assert.equal(null, err, 'no errors from cert generation');
    console.log('ssl shit worked');
    n++;
  })

  beforeExit(function() {
    assert.equal(1, n, 'callbacks run');
  });
};

exports.setup = function(done) {
  async.series([
    async.apply(require('util/pubsub').ensure, "config"),
    async.apply(fs.mkdir, '.tests/certs', 0700)
  ],
  done);
};

@@ -927,16 +927,91 @@
 rtgen');
+%0Avar exec = require('child_process').exec;%0Avar misc = require('util/misc');
 %0A%0Aexport
@@ -1068,17 +1068,17 @@
 oreExit)
- 
+%0A
 %7B%0A  var 
@@ -1084,16 +1084,51 @@
  n = 0;%0A
+  var hostname = 'testhostnamerare'
 %0A  certg
@@ -1141,29 +1141,24 @@
 fsigned(
-'test
 hostname
 rare', '
@@ -1153,14 +1153,29 @@
 name
-rare',
+,%0A                   
  '.t
@@ -1192,16 +1192,36 @@
 /t.key',
+%0A                   
  '.tests
@@ -1234,16 +1234,36 @@
 /t.crt',
+%0A                   
  functio
@@ -1268,19 +1268,30 @@
 ion(err)
+%0A 
  %7B%0A
+    n++;%0A
     asse
@@ -1353,53 +1353,256 @@
     
-console.log('ssl shit worked');%0A    n++
+exec(%22openssl x509 -noout -subject -in .tests/certs/t.crt%22, function(err, stdout, stderr) %7B%0A      n++;%0A      assert.equal(null, err, 'no errors from cert verification');%0A      assert.equal(%22subject= /CN=%22+hostname, misc.trim(stdout));%0A    %7D)
 ;%0A  %7D)
+;
 %0A%0A  
@@ -1646,9 +1646,9 @@
 ual(
-1
+2
 , n,

Improve test case for certificate