Skip to content

Commit 44f335b

Browse files
committed
Return 404 if controls are accessed without writes
1 parent 27ad535 commit 44f335b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/RDF/LinkedData.pm

+8
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,14 @@ sub response {
479479
}
480480

481481
my $type = $self->type;
482+
483+
if (($type eq 'controls') && (!$self->writes_enabled)) {
484+
$response->status(404);
485+
$response->headers->content_type('text/plain');
486+
$response->body('HTTP 404: Controls are only available in read-enabled applications');
487+
return $response;
488+
}
489+
482490
$self->type('');
483491
my $node = $self->my_node($uri);
484492
$self->log->info("Try rendering '$type' page for subject node: " . $node->as_string);

t/20-psgi-basic.t

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use strict;
44
use warnings;
55

6-
use Test::More tests => 60 ;
6+
use Test::More tests => 61 ;
77
use Test::RDF;
88
use Test::WWW::Mechanize::PSGI;
99
use Module::Load::Conditional qw[can_load];
@@ -47,6 +47,13 @@ foreach my $accept_header (('text/html',
4747
is($res->header('Location'), 'http://en.wikipedia.org/wiki/Foo', "Location is Wikipedia page");
4848
}
4949

50+
{
51+
note "Get /foo/controls, no redirects";
52+
my $mech = Test::WWW::Mechanize::PSGI->new(app => $tester, requests_redirectable => []);
53+
my $res = $mech->get("/foo/controls");
54+
is($mech->status, 404, "Returns 404");
55+
}
56+
5057
{
5158
note "Get /foo, no redirects, ask for RDF/XML";
5259
my $mech = Test::WWW::Mechanize::PSGI->new(app => $tester, requests_redirectable => []);

0 commit comments

Comments
 (0)