lemonldap-ng/lemonldap-ng-manager/t/06-rest-api-RSA.t

64 lines
1.3 KiB
Perl
Raw Normal View History

2016-01-07 12:40:24 +01:00
# Test RSA key generation
use Test::More;
use strict;
2016-01-13 20:47:56 +01:00
use JSON;
use IO::String;
2015-05-14 08:45:03 +02:00
require 't/test-lib.pm';
sub checkResult {
2021-01-20 09:15:52 +01:00
my $res = shift;
my $expecthash = shift;
ok( $res->[0] == 200, "Result code is 200" );
my $key;
ok( $key = from_json( $res->[2]->[0] ), 'Response is JSON' );
like( $key->{private}, qr/BEGIN/, "is PEM formatted" );
like( $key->{public}, qr/BEGIN/, "is PEM formatted" );
2021-01-20 09:15:52 +01:00
ok( $key->{hash}, "hash is non empty" ) if $expecthash;
2022-02-16 17:43:29 +01:00
count(1) if $expecthash;
count(4);
}
my $res;
ok(
2016-01-01 20:55:35 +01:00
$res = &client->_post(
'/confs/newRSAKey', '', IO::String->new(''), 'application/json', 0,
),
"Request succeed"
);
count(1);
2021-01-20 09:15:52 +01:00
checkResult( $res, 1 );
ok(
2016-01-01 20:55:35 +01:00
$res = &client->_post(
'/confs/newRSAKey', '', IO::String->new('{"password":"hello"}'),
'application/json', 20,
),
"Request succeed"
);
count(1);
2021-01-20 09:15:52 +01:00
checkResult( $res, 1 );
ok(
$res = &client->_post(
'/confs/newCertificate', '',
IO::String->new(''), 'application/json',
0,
),
"Request succeed"
);
count(1);
checkResult($res);
ok(
$res = &client->_post(
'/confs/newCertificate', '', IO::String->new('{"password":"hello"}'),
2022-02-16 17:43:29 +01:00
'application/json', 20,
),
"Request succeed"
);
count(1);
checkResult($res);
2015-10-22 10:40:12 +02:00
done_testing( count() );