~duncan-bayne/halp

83bc716b4101c3d5385e2989ba6887363dbc51ae — Duncan Bayne 1 year, 1 month ago 9913fb2
Make sure we can never run Halp with a relative Web path
3 files changed, 16 insertions(+), 1 deletions(-)

M freebsd/install-prereqs.sh
M lib/Halp/WebServer.pm
M t/Halp/web_server_test.t
M freebsd/install-prereqs.sh => freebsd/install-prereqs.sh +1 -0
@@ 13,6 13,7 @@ pkg install -y \
    p5-File-Slurp \
    p5-HTTP-Server-Simple \
    p5-Mojolicious \
    p5-Test-Exception \
    p5-Test-LWP-UserAgent \
    p5-Text-Template \
    p5-Try-Tiny \

M lib/Halp/WebServer.pm => lib/Halp/WebServer.pm +2 -0
@@ 18,6 18,8 @@ sub new {
    my ($class, %args) = @_;
    my $self = $class->SUPER::new();

    die "web_path $args{web_path} must be absolute" unless File::Spec->file_name_is_absolute($args{web_path});

    $self->{author} = $args{author};
    $self->{domain} = $args{domain};
    $self->{web_path} = $args{web_path};

M t/Halp/web_server_test.t => t/Halp/web_server_test.t +13 -1
@@ 8,6 8,7 @@ use File::Spec::Functions 'rel2abs';
use Halp::WebServer;
use LWP::UserAgent;
use Mojo::DOM;
use Test::Exception;
use Test::More;
use Time::HiRes qw(time);



@@ 33,6 34,16 @@ sub run_404_tests {
    like($dom->at('title')->text, qr/^Page not found$/, '404 page has a title');
}

sub run_constructor_tests {
    dies_ok {
	my $web_server = Halp::WebServer->new(
	    domain => 'example.com',
	    port => 8088,
	    web_path => './t/fixtures/www'
	    );
    } 'Constructor should fail when given a relative web path.';
}

sub run_directory_tests {
    my $response = $ua->get('http://localhost:8088/blog');
    my $dom = Mojo::DOM->new($response->content);


@@ 189,8 200,9 @@ if ($web_pid == 0) {
	);
    $web_server->run();
} else {
    use Test::More tests => 57;
    use Test::More tests => 58;
    run_404_tests();
    run_constructor_tests();
    run_directory_tests();
    run_feed_tests();
    run_performance_tests();