blob: 07cd6fa2e2b5145945972874bd5df0c1ed2a7c91 [file] [log] [blame]
Nils Diewalda898dac2015-05-06 21:04:16 +00001use Mojo::Base -strict;
Nils Diewalda898dac2015-05-06 21:04:16 +00002use Test::More;
3use Test::Mojo;
4
5# Test the documentation
6
Akron07d8de62020-02-04 17:45:40 +01007my $t = Test::Mojo->new('Kalamar' => {
8 Kalamar => {
Akron07d8de62020-02-04 17:45:40 +01009 proxy_prefix => '/test'
10 }
11});
Nils Diewalda898dac2015-05-06 21:04:16 +000012
Helge3d1d04d2026-01-28 18:04:39 +010013# Get API version from app config (set in Kalamar.pm startup)
14my $api_version = $t->app->config('Kalamar')->{api_version};
15
16
Akronaa5cf802021-06-11 11:31:00 +020017# Bug 2021-06-11
18$t->get_ok('/doc/ql/wildcards?cat=1')
Akronb9ca92b2024-03-14 10:20:18 +010019 ->status_is(404) # ! Should be 404!
20 ;
21
22$t->get_ok('/doc/ql/')
23 ->status_is(200)
24 ->text_is('title','KorAP: Query Languages')
25 ;
26
27$t->get_ok('/doc/ql')
28 ->status_is(200)
29 ->text_is('title','KorAP: Query Languages')
Akronaa5cf802021-06-11 11:31:00 +020030 ;
31
Akronccd71a42017-06-30 18:09:19 +020032# Embedding
Nils Diewalda898dac2015-05-06 21:04:16 +000033$t->get_ok('/doc/ql/poliqarp-plus')
34 ->status_is(200)
35 ->text_like('title', qr/poliqarp/i)
36 ->element_exists('aside.active')
Akron1d09b532021-06-15 18:18:25 +020037 ->element_exists_not('aside.settings')
Nils Diewalda898dac2015-05-06 21:04:16 +000038 ->element_exists('main.tutorial')
39 ->element_exists('header')
40 ->element_exists('aside nav')
Nils Diewalda748b0e2015-05-19 22:54:06 +000041 ->text_is('h1 span', 'KorAP: Poliqarp+')
42 ->element_exists('li.folded.active')
43 ->text_is('li.folded.active a', 'Poliqarp+');
Nils Diewalda898dac2015-05-06 21:04:16 +000044
45$t->get_ok('/doc/ql/poliqarp-plus?embedded=true')
46 ->status_is(200)
47 ->text_like('title', qr/poliqarp/i)
48 ->element_exists('aside.active')
49 ->element_exists('main.tutorial')
Nils Diewalda748b0e2015-05-19 22:54:06 +000050 ->element_exists_not('header')
51 ->element_exists('li.folded.active')
52 ->text_is('li.folded.active a', 'Poliqarp+');
Nils Diewalda898dac2015-05-06 21:04:16 +000053
Akronccd71a42017-06-30 18:09:19 +020054# Languages
55$t->get_ok('/' => { 'Accept-Language' => 'de-DE, en-US, en' })
56 ->status_is(200)
57 ->text_is("title", "KorAP - Korpusanalyseplattform der nächsten Generation");
58
59$t->get_ok('/' => { 'Accept-Language' => 'en-US, en, de-DE' })
60 ->status_is(200)
61 ->text_is("title", "KorAP - Corpus Analysis Platform");
62
Akronb9ca92b2024-03-14 10:20:18 +010063$t->get_ok('/doc/ql/' => { 'Accept-Language' => 'de-DE, en-US, en' })
64 ->status_is(200)
65 ->text_is('title','KorAP: Anfragesprachen')
Helgec166a632025-03-05 10:52:58 +010066 ->text_is('#examples > h3','Beispielanfragen')
Akronb9ca92b2024-03-14 10:20:18 +010067 ;
68
69$t->get_ok('/doc/ql' => { 'Accept-Language' => 'de-DE, en-US, en' })
70 ->status_is(200)
71 ->text_is('title','KorAP: Anfragesprachen')
72 ;
Akronccd71a42017-06-30 18:09:19 +020073
74# Pages
75$t->get_ok('/doc/ql/poliqarp-plus' => { 'Accept-Language' => 'en-US, en, de-DE' })
76 ->status_is(200)
77 ->text_is("title", "KorAP: Poliqarp+")
78 ->text_is('main section > h3', 'Simple Segments');
79
80$t->get_ok('/doc/ql/poliqarp-plus' => { 'Accept-Language' => 'de-DE, en-US, en' })
81 ->status_is(200)
82 ->text_is("title", "KorAP: Poliqarp+")
83 ->text_is('main section > h3', 'Einfache Segmente');
84
Akronccd71a42017-06-30 18:09:19 +020085$t->get_ok('/doc/ql/annis' => { 'Accept-Language' => 'en-US, en, de-DE' })
86 ->status_is(200)
Rebecca Wilm45e9afe2024-11-07 15:17:29 +010087 ->text_is("title", "KorAP: ANNIS QL");
Akronccd71a42017-06-30 18:09:19 +020088
Akronf4a7cf42018-01-09 15:58:45 +010089# Check corpus examples
90$t->get_ok('/doc/ql/poliqarp-plus')
91 ->status_is(200)
92 ->text_is('#segments pre.query.tutorial:nth-of-type(1) code', 'Baum');
93
Akron1bd65d92019-07-17 18:26:36 +020094# Check data
95$t->get_ok('/doc/data/annotation' => { 'Accept-Language' => 'en-US, en, de-DE' })
96 ->status_is(200)
Akron9490e3b2019-10-17 12:26:29 +020097 ->text_is('#page-top', 'KorAP: Annotations');
Akron1bd65d92019-07-17 18:26:36 +020098$t->get_ok('/doc/data/annotation' => { 'Accept-Language' => 'de-DE, en-US, en' })
99 ->status_is(200)
Akron9490e3b2019-10-17 12:26:29 +0200100 ->text_is('#page-top', 'KorAP: Annotationen');
Akron1bd65d92019-07-17 18:26:36 +0200101
Akronc8ffbac2026-07-22 17:58:54 +0200102# Path-traversal attempt via Accept-Language header
103$t->get_ok('/doc/ql' => { 'Accept-Language' => '../../etc/passwd, en' })
104 ->status_is(200)
105 ->text_is('title', 'KorAP: Query Languages')
106 ;
107
108# Null-byte injection attempt
109$t->get_ok('/doc/ql' => { 'Accept-Language' => "de\x00malicious, en" })
110 ->status_is(200)
111 ;
112
113# Overly long locale
114$t->get_ok('/doc/ql' => { 'Accept-Language' => 'abcdefghijklmnop, en' })
115 ->status_is(200)
116 ->text_is('title', 'KorAP: Query Languages')
117 ;
118
119# Locale with special/shell characters
120$t->get_ok('/doc/ql' => { 'Accept-Language' => 'de;rm -rf /, en' })
121 ->status_is(200)
122 ;
123
124# Locale with slashes (directory traversal)
125$t->get_ok('/doc/ql' => { 'Accept-Language' => 'de/../../../etc, en' })
126 ->status_is(200)
127 ;
128
129# Construct an Accept-Language header with far more than 6 non-English locales.
130my @many_locales = map { "xx-" . sprintf("%02d", $_) } (1..50);
131my $huge_header = join(', ', @many_locales, 'en');
132
133$t->get_ok('/doc/ql' => { 'Accept-Language' => $huge_header })
134 ->status_is(200)
135 ->text_is('title', 'KorAP: Query Languages')
136 ;
137
Akronf4a7cf42018-01-09 15:58:45 +0100138my $app = $t->app;
139
140$app->plugin(
141 'Localize' => {
142 dict => {
143 Q => {
144 newexample => {
145 poliqarp => {
146 simple => '** Beispiel'
147 }
148 }
149 }
150 }
151 }
152);
153
154# Set other example query
155$app->config('Kalamar')->{examplecorpus} = 'newexample';
156
157is($app->loc('Q_poliqarp_simple'), '** Beispiel');
158
159# Check corpus examples
160$t->get_ok('/doc/ql/poliqarp-plus')
161 ->status_is(200)
162 ->text_is('#segments pre.query.tutorial:nth-of-type(1) code', 'Beispiel')
163 ->text_is('#segments pre.query.tutorial:nth-of-type(1) span', '*');
Nils Diewalda898dac2015-05-06 21:04:16 +0000164
Akron07d8de62020-02-04 17:45:40 +0100165# Check API endpoint
166$t->get_ok('/doc/api' => { 'X-Forwarded-Host' => 'korap.ids-mannheim.de' })
167 ->status_is(200)
Helge3d1d04d2026-01-28 18:04:39 +0100168 ->text_is('#api-service-uri', 'https://korap.ids-mannheim.de/test/api/v' . $api_version . '/');
Akron07d8de62020-02-04 17:45:40 +0100169
Helge23f7abd2024-02-27 16:35:15 +0100170# Set openapi path
Helge3d1d04d2026-01-28 18:04:39 +0100171$app->config('Kalamar')->{openapi} = '/api/v' . $api_version . '/openapi/';
Helge23f7abd2024-02-27 16:35:15 +0100172
173# Check openapi endpoint
174$t->get_ok('/doc/api' => { 'X-Forwarded-Host' => 'korap.ids-mannheim.de' })
175 ->status_is(200)
Helge3d1d04d2026-01-28 18:04:39 +0100176 ->element_exists('#openapi > a[href="https://korap.ids-mannheim.de/api/v' . $api_version . '/openapi/"]');
Akron07d8de62020-02-04 17:45:40 +0100177
Marc Kupietzfcadda62021-09-08 09:06:25 +0200178# Languages of dev pages
179$t->get_ok('/doc/development/kalamar')
180 ->status_is(200)
181 ->text_is("title", "KorAP: Kalamar")
182 ->content_like(qr!Main developer!);
183
184$t->get_ok('/doc/development/kalamar' => { 'Accept-Language' => 'de-DE, en-US, en' })
185 ->status_is(200)
186 ->text_is("title", "KorAP: Kalamar")
187 ->content_like(qr!Hauptentwickler!);
188
189
Akron1011daf2021-03-01 12:34:58 +0100190# Check mail_to_chiffre
191like($t->app->mail_to_chiffre('korap@korap.example'),qr!rel="nofollow"!);
192like($t->app->mail_to_chiffre('korap@korap.example'),qr!class="PArok"!);
193
Nils Diewalda898dac2015-05-06 21:04:16 +0000194done_testing();