| 1 |
# Test RSA key generation |
| 2 |
|
| 3 |
use warnings; |
| 4 |
use Test::More; |
| 5 |
use strict; |
| 6 |
use JSON; |
| 7 |
use IO::String; |
| 8 |
require 't/test-lib.pm'; |
| 9 |
|
| 10 |
sub checkResult { |
| 11 |
my $res = shift; |
| 12 |
my $expecthash = shift; |
| 13 |
ok( $res->[0] == 200, "Result code is 200" ); |
| 14 |
my $key; |
| 15 |
ok( $key = from_json( $res->[2]->[0] ), 'Response is JSON' ); |
| 16 |
like( $key->{private}, qr/BEGIN/, "is PEM formatted" ); |
| 17 |
like( $key->{public}, qr/BEGIN/, "is PEM formatted" ); |
| 18 |
ok( $key->{hash}, "hash is non empty" ) if $expecthash; |
| 19 |
count(1) if $expecthash; |
| 20 |
count(4); |
| 21 |
} |
| 22 |
|
| 23 |
my $res; |
| 24 |
ok( |
| 25 |
$res = &client->_post( |
| 26 |
'/confs/newRSAKey', '', IO::String->new(''), 'application/json', 0, |
| 27 |
), |
| 28 |
"Request succeed" |
| 29 |
); |
| 30 |
count(1); |
| 31 |
checkResult( $res, 1 ); |
| 32 |
|
| 33 |
ok( |
| 34 |
$res = &client->_post( |
| 35 |
'/confs/newRSAKey', '', IO::String->new('{"password":"hello"}'), |
| 36 |
'application/json', 20, |
| 37 |
), |
| 38 |
"Request succeed" |
| 39 |
); |
| 40 |
count(1); |
| 41 |
checkResult( $res, 1 ); |
| 42 |
|
| 43 |
ok( |
| 44 |
$res = &client->_post( |
| 45 |
'/confs/newCertificate', '', |
| 46 |
IO::String->new(''), 'application/json', |
| 47 |
0, |
| 48 |
), |
| 49 |
"Request succeed" |
| 50 |
); |
| 51 |
count(1); |
| 52 |
checkResult($res); |
| 53 |
|
| 54 |
ok( |
| 55 |
$res = &client->_post( |
| 56 |
'/confs/newCertificate', '', IO::String->new('{"password":"hello"}'), |
| 57 |
'application/json', 20, |
| 58 |
), |
| 59 |
"Request succeed" |
| 60 |
); |
| 61 |
count(1); |
| 62 |
checkResult($res); |
| 63 |
|
| 64 |
done_testing( count() ); |