RT notifier: parse templates without header correctly
[openxpki.git] / trunk / clients / perl / OpenXPKI-Client-SCEP / t / 40.approve-initial-scep-request.t
blob26ada70766aad373f74def57e28b86a715e13956
1 use Test::More tests => 1;
2 use English;
4 use strict;
5 use warnings;
7 use OpenXPKI::Client;
9 our %config;
10 require 't/common.pl';
12 my $debug = $config{debug};
14 diag("SCEP Client Test: approving the SCEP request");
15 my $sscep = 'sscep';
16 SKIP: {
17     if (system("$sscep >/dev/null 2>&1") != 0) {
18         skip "sscep binary not installed.", 1;
19     }
20     if (! (`$config{openssl} version` =~ m{\A OpenSSL\ 0\.9\.8 }xms)) {
21         skip "OpenSSL 0.9.8 not available.", 1;
22     }
23     
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`;
30     my $success;
32     APPROVE:
33     for (my $i = 0; $i < 10; $i++) {
34         my $message = "Approval try #" . ($i+1);
35         diag($message);
36         my $stderr = "2>/dev/null";
37         # hangs prove, see OpenXPKI::Tests
38         #if ($debug) {
39         #    $stderr = "";
40         #}
41         if ($i > 0) {
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`;
47         }
49         my $client = OpenXPKI::Client->new({
50             SOCKETFILE => $config{'socket_file'},
51         });
52         $client->init_session();
53     
54         #my $msg = $client->collect();
55     
56         my $msg = $client->send_receive_service_msg(
57             'GET_AUTHENTICATION_STACK',
58             {
59                 'AUTHENTICATION_STACK' => 'External Dynamic',
60             },
61         );
62         $msg = $client->send_receive_service_msg(
63             'GET_PASSWD_LOGIN',
64             {
65                 'LOGIN'  => 'raop',
66                 'PASSWD' => 'RA Operator',
67             },
68         );
69         if (exists $msg->{'SERVICE_MSG'} &&
70                    $msg->{'SERVICE_MSG'} eq 'SERVICE_READY') {
71             if ($debug) {
72                 print STDERR "logged in ...\n";
73             }
74         }
75         else {
76             next APPROVE;
77         }
78         
79         $msg = $client->send_receive_command_msg(
80             'search_workflow_instances',
81             {
82                 TYPE    => 'I18N_OPENXPKI_WF_TYPE_SCEP_REQUEST',
83                 CONTEXT => [
84                     {
85                         KEY   => 'cert_subject',
86                         VALUE => '%Test%',
87                     },
88                 ],
89             }
90         );
91         
92         if (ref $msg->{'PARAMS'} eq 'ARRAY' &&
93             exists $msg->{'PARAMS'}->[0]->{'WORKFLOW.WORKFLOW_STATE'} &&
94             $msg->{'PARAMS'}->[0]->{'WORKFLOW.WORKFLOW_STATE'} eq 'PENDING') {
95             if ($debug) {
96                 print STDERR "pending ...\n";
97             }
98         }
99         else {
100             next APPROVE;
101         }
102         my $wf_id = $msg->{'PARAMS'}->[0]->{'WORKFLOW.WORKFLOW_SERIAL'};
103         
104         $msg = $client->send_receive_command_msg(
105             'execute_workflow_activity',
106             {
107                 'WORKFLOW' => 'I18N_OPENXPKI_WF_TYPE_SCEP_REQUEST',
108                 'ID'       => $wf_id,
109                 'ACTIVITY' =>  'I18N_OPENXPKI_WF_ACTION_APPROVE_CSR',
110             },
111         );
112         
113         if (exists $msg->{'PARAMS'}->{'WORKFLOW'}->{'STATE'}  &&
114             $msg->{'PARAMS'}->{'WORKFLOW'}->{'STATE'} eq 'APPROVAL') {
115             if ($debug) {
116                 print STDERR "approved ...\n";
117             }
118         }
119         else {
120             next APPROVE;
121         }
122         
123         $msg = $client->send_receive_command_msg(
124             'execute_workflow_activity',
125             {
126                 'WORKFLOW' => 'I18N_OPENXPKI_WF_TYPE_SCEP_REQUEST',
127                 'ID'       => $wf_id,
128                 'ACTIVITY' =>  'I18N_OPENXPKI_WF_ACTION_PERSIST_CSR',
129             },
130         );
131         
132         $msg = $client->send_receive_command_msg(
133             'get_workflow_info',
134             {
135                 'WORKFLOW' => 'I18N_OPENXPKI_WF_TYPE_SCEP_REQUEST',
136                 'ID'       => $wf_id,
137             },
138         );
139         if (exists $msg->{'PARAMS'}->{'WORKFLOW'}->{'STATE'} &&
140             ($msg->{'PARAMS'}->{'WORKFLOW'}->{'STATE'} eq 'SUCCESS'
141           || $msg->{'PARAMS'}->{'WORKFLOW'}->{'STATE'} eq 'WAITING_FOR_CHILD')) {
142             $success = 1;
143             if ($debug) {
144                 print STDERR "success ...\n";
145             }
146             last APPROVE;
147         }
148     }
149     ok($success);