4 use lib 't/20_webserver/lib';
6 use OpenXPKI::Client::HTML::Mason::Test::Server;
14 if ($ENV{MASON_TEST_PORT}) {
15 # just in case someone wants to overwrite the test webserver port
17 $TEST_PORT = $ENV{MASON_TEST_PORT};
20 diag("Start page and login");
22 my $server = OpenXPKI::Client::HTML::Mason::Test::Server->new($TEST_PORT);
23 $server->started_ok('Webserver start');
24 my $mech = WWW::Mechanize->new();
27 my $index_page = $mech->get("http://127.0.0.1:$TEST_PORT/")->content();
28 unlike($index_page, qr/I18N_OPENXPKI_CLIENT_INIT_CONNECTION_FAILED/, 'No connection failed error on start page') or diag "Index: $index_page";
29 like($index_page, qr/I18N_OPENXPKI_CLIENT_HTML_MASON_GET_AUTHENTICATION_STACK_TITLE/, 'Correct title');
31 $mech->form_name('OpenXPKI');
32 $mech->field('auth_stack', 'Anonymous');
33 $mech->click('submit');
34 is($mech->response->code(), '200', 'HTTP 200 OK received');
35 like($mech->response->content, qr/meta http-equiv="refresh"/, 'Redirect page received');
37 my ($session_id) = ($mech->response->content =~ m{__session_id=([0-9a-f]+)}xms);
39 diag "Session ID: $session_id";
43 $mech->get("http://127.0.0.1:$TEST_PORT/service/index.html?__session_id=$session_id&__role=");
44 like($mech->response->content, qr/I18N_OPENXPKI_CLIENT_HTML_MASON_INTRO_TITLE/, 'Correct title');
46 foreach my $menu_item (qw(
47 I18N_OPENXPKI_HTML_MENU_HOME
48 I18N_OPENXPKI_HTML_MENU_REQUEST
49 I18N_OPENXPKI_HTML_MENU_DOWNLOAD
50 I18N_OPENXPKI_HTML_MENU_SEARCH
51 I18N_OPENXPKI_HTML_MENU_LOGOUT
53 like($mech->response->content, qr/$menu_item/,
54 "Menu item $menu_item is present on page");
56 # TODO - check for menu items that should not appear on anonymous page
58 ok($mech->follow_link(text => 'I18N_OPENXPKI_HTML_MENU_LOGOUT', n => '1'), 'Followed link');
59 like($mech->response->content, qr/I18N_OPENXPKI_CLIENT_HTML_MASON_LOGOUT_SUCCESS_TITLE/, 'Logout successfull');
62 # login using external dynamic stack
63 my %expected_menus = (
66 I18N_OPENXPKI_HTML_MENU_TASKS
67 I18N_OPENXPKI_HTML_MENU_REQUEST
68 I18N_OPENXPKI_HTML_MENU_DOWNLOAD
69 I18N_OPENXPKI_HTML_MENU_APPROVAL
70 I18N_OPENXPKI_HTML_MENU_SEARCH
71 I18N_OPENXPKI_HTML_MENU_LOGOUT
76 I18N_OPENXPKI_HTML_MENU_HOME
77 I18N_OPENXPKI_HTML_MENU_REQUEST
78 I18N_OPENXPKI_HTML_MENU_DOWNLOAD
79 I18N_OPENXPKI_HTML_MENU_SEARCH
80 I18N_OPENXPKI_HTML_MENU_LOGOUT
85 I18N_OPENXPKI_HTML_MENU_TASKS
86 I18N_OPENXPKI_HTML_MENU_REQUEST
87 I18N_OPENXPKI_HTML_MENU_DOWNLOAD
88 I18N_OPENXPKI_HTML_MENU_APPROVAL
89 I18N_OPENXPKI_HTML_MENU_SEARCH
90 I18N_OPENXPKI_HTML_MENU_LOGOUT
95 my $expected_intro_title = {
96 'User' => qr/I18N_OPENXPKI_CLIENT_HTML_MASON_INTRO_TITLE/,
97 'CA Operator' => qr/I18N_OPENXPKI_CLIENT_HTML_MASON_INTRO_CAOP_TITLE/,
98 'RA Operator' => qr/I18N_OPENXPKI_CLIENT_HTML_MASON_INTRO_RAOP_TITLE/,
101 foreach my $role (keys %expected_menus) {
102 diag "Login as external dynamic ($role) ...";
103 my $index_page = $mech->get("http://127.0.0.1:$TEST_PORT/")->content();
104 unlike($index_page, qr/I18N_OPENXPKI_CLIENT_INIT_CONNECTION_FAILED/, 'No connection failed error on start page') or diag "Index: $index_page";
105 like($index_page, qr/I18N_OPENXPKI_CLIENT_HTML_MASON_GET_AUTHENTICATION_STACK_TITLE/, 'Correct title');
107 $mech->form_name('OpenXPKI');
108 $mech->field('auth_stack', 'External Dynamic');
109 $mech->click('submit');
111 like($mech->response->content, qr/I18N_OPENXPKI_CONFIG_AUTH_HANDLER_DESCRIPTION_EXTERNAL/, 'Correct stack');
112 $mech->form_name('OpenXPKI');
113 $mech->field('login', 'test');
114 $mech->field('passwd', $role);
115 $mech->click('submit');
117 is($mech->response->code(), '200', 'HTTP 200 OK received');
118 like($mech->response->content, qr/meta http-equiv="refresh"/, 'Redirect page received');
120 my ($session_id) = ($mech->response->content =~ m{__session_id=([0-9a-f]+)}xms);
122 diag "Session ID: $session_id";
125 # go to redirect page
126 $mech->get("http://127.0.0.1:$TEST_PORT/service/index.html?__session_id=$session_id&__role=" . uri_escape($role));
127 like($mech->response->content, $expected_intro_title->{$role}, 'Correct title');
129 foreach my $menu_item (@{ $expected_menus{$role} }) {
130 like($mech->response->content, qr/$menu_item/,
131 "Menu item $menu_item is present on page");
133 # TODO - check for menu items that should not appear
135 ok($mech->follow_link(text => 'I18N_OPENXPKI_HTML_MENU_LOGOUT', n => '1'), 'Followed link');
136 like($mech->response->content, qr/I18N_OPENXPKI_CLIENT_HTML_MASON_LOGOUT_SUCCESS_TITLE/, 'Logout successfull');
140 # login using external static (RA Operator)
141 $index_page = $mech->get("http://127.0.0.1:$TEST_PORT/")->content();
142 unlike($index_page, qr/I18N_OPENXPKI_CLIENT_INIT_CONNECTION_FAILED/, 'No connection failed error on start page') or diag "Index: $index_page";
143 like($index_page, qr/I18N_OPENXPKI_CLIENT_HTML_MASON_GET_AUTHENTICATION_STACK_TITLE/, 'Correct title');
145 $mech->form_name('OpenXPKI');
146 $mech->field('auth_stack', 'External Static');
147 $mech->click('submit');
149 like($mech->response->content, qr/I18N_OPENXPKI_CONFIG_AUTH_HANDLER_DESCRIPTION_EXTERNAL/, 'Correct stack');
150 $mech->form_name('OpenXPKI');
151 $mech->field('login', 'test');
152 $mech->field('passwd', 'test');
153 $mech->click('submit');
155 is($mech->response->code(), '200', 'HTTP 200 OK received');
156 like($mech->response->content, qr/meta http-equiv="refresh"/, 'Redirect page received');
158 ($session_id) = ($mech->response->content =~ m{__session_id=([0-9a-f]+)}xms);
160 diag "Session ID: $session_id";
163 # go to redirect page
164 $mech->get("http://127.0.0.1:$TEST_PORT/service/index.html?__session_id=$session_id&__role=RA%20Operator");
165 like($mech->response->content, qr/I18N_OPENXPKI_CLIENT_HTML_MASON_INTRO_RAOP_TITLE/, 'Correct title');