View | Details | Raw Unified | Return to bug 38365
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Template/Plugin/Koha.t (-5 / +19 lines)
Lines 29-34 use Koha::Cache::Memory::Lite; Link Here
29
use Koha::Database;
29
use Koha::Database;
30
use Koha::Template::Plugin::Koha;
30
use Koha::Template::Plugin::Koha;
31
31
32
use t::lib::Mocks;
33
32
my $schema = Koha::Database->new->schema;
34
my $schema = Koha::Database->new->schema;
33
35
34
my $session_id  = 42;
36
my $session_id  = 42;
Lines 81-87 subtest 'GenerateCSRF - New CSRF token generated every time we need one' => sub Link Here
81
};
83
};
82
84
83
subtest 'CSPNonce' => sub {
85
subtest 'CSPNonce' => sub {
84
    plan tests => 1;
86
    plan tests => 3;
85
87
86
    $schema->storage->txn_begin;
88
    $schema->storage->txn_begin;
87
89
Lines 90-101 subtest 'CSPNonce' => sub { Link Here
90
92
91
    my $plugin = Koha::Template::Plugin::Koha->new($context);
93
    my $plugin = Koha::Template::Plugin::Koha->new($context);
92
94
93
    my $csp   = Koha::ContentSecurityPolicy->new;
95
    C4::Context->interface('opac');
94
    my $nonce = $csp->get_nonce;
96
    t::lib::Mocks::mock_config(
97
        'content_security_policy',
98
        { 'opac' => { csp_mode => 'enabled', csp_header_value => 'test' } }
99
    );
95
100
96
    my $token = $plugin->CSPNonce;
101
    my $csp = Koha::ContentSecurityPolicy->new;
102
    $csp->set_nonce();
103
    my $nonce = $csp->get_nonce;
97
104
98
    is( $plugin->CSPNonce, $nonce, 'the correct nonce was provided' );
105
    is( $plugin->CSPNonce, $nonce, 'the correct nonce was provided' );
106
    like( $nonce, qr/^\w{22}$/, 'nonce is a random string of 22 characters' );
107
108
    t::lib::Mocks::mock_config(
109
        'content_security_policy',
110
        { 'opac' => { csp_mode => 'disabled', csp_header_value => 'test' } }
111
    );
112
113
    is( $plugin->CSPNonce, undef, 'no nonce was provided because CSP is dsabled' );
99
114
100
    $schema->storage->txn_rollback;
115
    $schema->storage->txn_rollback;
101
116
102
- 

Return to bug 38365