1 use Test::More tests => 1;
10 require 't/common.pl';
12 my $debug = $config{debug};
14 diag("SCEP Client Test: approving the SCEP request");
17 if (system("$sscep >/dev/null 2>&1") != 0) {
18 skip "sscep binary not installed.", 1;
20 if (! (`$config{openssl} version` =~ m{\A OpenSSL\ 0\.9\.8 }xms)) {
21 skip "OpenSSL 0.9.8 not available.", 1;
24 # we need to backup the sqlite db, as the approval might fail
25 # because of DB issues. We retry up to 10 times so that we don't
26 # fail for this reason (which is no problem with a non-SQlite-DB)
27 `mkdir t/instance/sqlite_backup`;
28 `cp t/instance/var/openxpki/sqlite* t/instance/sqlite_backup`;
33 for (my $i = 0; $i < 10; $i++) {
34 my $message = "Approval try #" . ($i+1);
36 my $stderr = "2>/dev/null";
37 # hangs prove, see OpenXPKI::Tests
42 # restore sqlite backup & restart server
43 `openxpkictl --config $config{config_file} stop $stderr`;
44 `cp t/instance/sqlite_backup/* t/instance/var/openxpki/`;
45 my $args = "--debug 150" if ($debug);
46 `openxpkictl --config $config{config_file} $args start $stderr`;
49 my $client = OpenXPKI::Client->new({
50 SOCKETFILE => $config{'socket_file'},
52 $client->init_session();
54 #my $msg = $client->collect();
56 my $msg = $client->send_receive_service_msg(
57 'GET_AUTHENTICATION_STACK',
59 'AUTHENTICATION_STACK' => 'External Dynamic',
62 $msg = $client->send_receive_service_msg(
66 'PASSWD' => 'RA Operator',
69 if (exists $msg->{'SERVICE_MSG'} &&
70 $msg->{'SERVICE_MSG'} eq 'SERVICE_READY') {
72 print STDERR "logged in ...\n";
79 $msg = $client->send_receive_command_msg(
80 'search_workflow_instances',
82 TYPE => 'I18N_OPENXPKI_WF_TYPE_SCEP_REQUEST',
85 KEY => 'cert_subject',
92 if (ref $msg->{'PARAMS'} eq 'ARRAY' &&
93 exists $msg->{'PARAMS'}->[0]->{'WORKFLOW.WORKFLOW_STATE'} &&
94 $msg->{'PARAMS'}->[0]->{'WORKFLOW.WORKFLOW_STATE'} eq 'PENDING') {
96 print STDERR "pending ...\n";
102 my $wf_id = $msg->{'PARAMS'}->[0]->{'WORKFLOW.WORKFLOW_SERIAL'};
104 $msg = $client->send_receive_command_msg(
105 'execute_workflow_activity',
107 'WORKFLOW' => 'I18N_OPENXPKI_WF_TYPE_SCEP_REQUEST',
109 'ACTIVITY' => 'I18N_OPENXPKI_WF_ACTION_APPROVE_CSR',
113 if (exists $msg->{'PARAMS'}->{'WORKFLOW'}->{'STATE'} &&
114 $msg->{'PARAMS'}->{'WORKFLOW'}->{'STATE'} eq 'APPROVAL') {
116 print STDERR "approved ...\n";
123 $msg = $client->send_receive_command_msg(
124 'execute_workflow_activity',
126 'WORKFLOW' => 'I18N_OPENXPKI_WF_TYPE_SCEP_REQUEST',
128 'ACTIVITY' => 'I18N_OPENXPKI_WF_ACTION_PERSIST_CSR',
132 $msg = $client->send_receive_command_msg(
135 'WORKFLOW' => 'I18N_OPENXPKI_WF_TYPE_SCEP_REQUEST',
139 if (exists $msg->{'PARAMS'}->{'WORKFLOW'}->{'STATE'} &&
140 ($msg->{'PARAMS'}->{'WORKFLOW'}->{'STATE'} eq 'SUCCESS'
141 || $msg->{'PARAMS'}->{'WORKFLOW'}->{'STATE'} eq 'WAITING_FOR_CHILD')) {
144 print STDERR "success ...\n";