|
Lines 36-42
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
Link Here
|
| 36 |
|
36 |
|
| 37 |
subtest 'add() tests' => sub { |
37 |
subtest 'add() tests' => sub { |
| 38 |
|
38 |
|
| 39 |
plan tests => 7; |
39 |
plan tests => 15; |
| 40 |
|
40 |
|
| 41 |
$schema->storage->txn_begin; |
41 |
$schema->storage->txn_begin; |
| 42 |
|
42 |
|
|
Lines 52-62
subtest 'add() tests' => sub {
Link Here
|
| 52 |
'blocked-uri' => 'inline', |
52 |
'blocked-uri' => 'inline', |
| 53 |
'line-number' => 42, |
53 |
'line-number' => 42, |
| 54 |
'column-number' => 10, |
54 |
'column-number' => 10, |
| 55 |
'source-file' => 'https://library.example.org/cgi-bin/koha/opac-main.pl', |
55 |
'source-file' => 'https://library.example.org/cgi-bin/koah/opac-main.pl', |
| 56 |
'status-code' => 200, |
56 |
'status-code' => 200, |
| 57 |
} |
57 |
} |
| 58 |
}; |
58 |
}; |
| 59 |
|
59 |
|
|
|
60 |
$csp_report->{'csp-report'}->{'line-number'} = 99999999999999999; |
| 61 |
|
| 62 |
# Too large integers should be rejected |
| 63 |
$t->post_ok( '/api/v1/public/csp-reports' => { 'Content-Type' => 'application/csp-report' } => json => $csp_report ) |
| 64 |
->status_is( 400, 'CSP report rejected (400) because of line-number exceeding maximum value' ); |
| 65 |
|
| 66 |
$csp_report->{'csp-report'}->{'line-number'} = -1; |
| 67 |
|
| 68 |
# Too small integers should be rejected |
| 69 |
$t->post_ok( '/api/v1/public/csp-reports' => { 'Content-Type' => 'application/csp-report' } => json => $csp_report ) |
| 70 |
->status_is( 400, 'CSP report rejected (400) because of line-number not reaching minimum value' ); |
| 71 |
$csp_report->{'csp-report'}->{'line-number'} = 42; |
| 72 |
|
| 73 |
$csp_report->{'csp-report'}->{'disposition'} = 'this is not okay'; |
| 74 |
|
| 75 |
# Enum values should be confirmed |
| 76 |
$t->post_ok( '/api/v1/public/csp-reports' => { 'Content-Type' => 'application/csp-report' } => json => $csp_report ) |
| 77 |
->status_is( 400, 'CSP report rejected (400) because of disposition is not either "enforce" nor "report"' ); |
| 78 |
$csp_report->{'csp-report'}->{'disposition'} = 'enforce'; |
| 79 |
|
| 80 |
$csp_report->{'csp-report'}->{'script-sample'} = |
| 81 |
'this is way too long script sample. a maximum of only 40 characters is allowed'; |
| 82 |
|
| 83 |
# Too long strings should be rejected |
| 84 |
$t->post_ok( '/api/v1/public/csp-reports' => { 'Content-Type' => 'application/csp-report' } => json => $csp_report ) |
| 85 |
->status_is( 400, 'CSP report rejected (400) because of script-sample exceeding maximum length' ); |
| 86 |
$csp_report->{'csp-report'}->{'script-sample'} = 'console.log("hi");'; |
| 87 |
|
| 60 |
# Anonymous request should work (browsers send these without auth) |
88 |
# Anonymous request should work (browsers send these without auth) |
| 61 |
$t->post_ok( '/api/v1/public/csp-reports' => { 'Content-Type' => 'application/csp-report' } => json => $csp_report ) |
89 |
$t->post_ok( '/api/v1/public/csp-reports' => { 'Content-Type' => 'application/csp-report' } => json => $csp_report ) |
| 62 |
->status_is( 204, 'CSP report accepted' ); |
90 |
->status_is( 204, 'CSP report accepted' ); |
| 63 |
- |
|
|