|
Lines 140-149
subtest 'header_value tests' => sub {
Link Here
|
| 140 |
$conf_csp_section, |
140 |
$conf_csp_section, |
| 141 |
{ opac => { csp_header_value => 'begin nonce-_CSP_NONCE_ end' } } |
141 |
{ opac => { csp_header_value => 'begin nonce-_CSP_NONCE_ end' } } |
| 142 |
); |
142 |
); |
| 143 |
my $cache = Koha::Cache::Memory::Lite->get_instance(); |
143 |
$csp->nonce('cached value'); |
| 144 |
$cache->set_in_cache( 'CSP-NONCE', 'cached value' ); |
|
|
| 145 |
is( $csp->header_value, 'begin nonce-cached value end', 'Cached csp_header_value' ); |
144 |
is( $csp->header_value, 'begin nonce-cached value end', 'Cached csp_header_value' ); |
| 146 |
$cache->flush; |
|
|
| 147 |
|
145 |
|
| 148 |
$csp = Koha::ContentSecurityPolicy->new( { nonce => 'forced value' } ); |
146 |
$csp = Koha::ContentSecurityPolicy->new( { nonce => 'forced value' } ); |
| 149 |
is( $csp->header_value, 'begin nonce-forced value end', 'Forced csp_header_value' ); |
147 |
is( $csp->header_value, 'begin nonce-forced value end', 'Forced csp_header_value' ); |
|
Lines 163-177
subtest 'nonce tests' => sub {
Link Here
|
| 163 |
$csp = Koha::ContentSecurityPolicy->new( { nonce => 'forced value' } ); |
161 |
$csp = Koha::ContentSecurityPolicy->new( { nonce => 'forced value' } ); |
| 164 |
is( $csp->nonce, 'forced value', 'nonce is not re-generated as was cached in memory' ); |
162 |
is( $csp->nonce, 'forced value', 'nonce is not re-generated as was cached in memory' ); |
| 165 |
|
163 |
|
| 166 |
my $cache = Koha::Cache::Memory::Lite->get_instance(); |
164 |
delete $ENV{CSP_NONCE}; |
| 167 |
$cache->flush; |
|
|
| 168 |
|
165 |
|
| 169 |
$csp = Koha::ContentSecurityPolicy->new(); |
166 |
$csp = Koha::ContentSecurityPolicy->new(); |
| 170 |
my $nonce = $csp->nonce; |
167 |
my $nonce = $csp->nonce; |
| 171 |
like( $nonce, qr/\w{22}/, 'nonce is a random string of 22 characters (128+ bits entropy)' ); |
168 |
like( $nonce, qr/\w{22}/, 'nonce is a random string of 22 characters (128+ bits entropy)' ); |
| 172 |
is( $nonce, $csp->nonce, 're-calling nonce() returns the same randomly generated cached value' ); |
169 |
is( $nonce, $csp->nonce, 're-calling nonce() returns the same randomly generated cached value' ); |
| 173 |
|
170 |
|
| 174 |
$cache->set_in_cache( 'CSP-NONCE', 'cached value' ); |
171 |
$csp->nonce('cached value'); |
| 175 |
is( $csp->nonce, 'cached value', 'nonce is not re-generated as it was previously cached' ); |
172 |
is( $csp->nonce, 'cached value', 'nonce is not re-generated as it was previously cached' ); |
| 176 |
}; |
173 |
}; |
| 177 |
|
174 |
|
| 178 |
- |
|
|