Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an error if non-existing service is used in a VHOST line #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ t/45-buffereduploads.t
t/50-plugins.t
t/52-chunked-upload.t
t/60-child-httpd.t
t/74-plugin-vhosts.t
t/75-plugin-include.t
t/76-plugin-redirect.t
t/77-plugin-throttle.t
Expand Down
10 changes: 9 additions & 1 deletion lib/Perlbal/Plugin/Vhosts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,15 @@ sub vhost_selector {
my ($match_on, $force) = @_;

my $map_name = $maps->{$match_on};
my $svc = $map_name ? Perlbal->service($map_name) : undef;
my $svc;
if ($map_name) {
$svc = Perlbal->service($map_name);
if (!$svc) {
Perlbal::log("warning", "The service name '$map_name' does not exist (configured for the vhost match '$match_on')");
$cb->_simple_response(404, "Not Found (no configured vhost)");
return 1;
}
}

return 0 unless $svc || $force;

Expand Down
54 changes: 54 additions & 0 deletions t/74-plugin-vhosts.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/perl

use strict;
use Perlbal::Test;
use Perlbal::Test::WebServer;
use Perlbal::Test::WebClient;
use Test::More 'no_plan';

my $port = new_port();

my $web_port = start_webserver();
ok($web_port, 'webserver started');

my $conf = qq{
LOAD Vhosts

CREATE POOL a
POOL a ADD 127.0.0.1:$web_port

CREATE SERVICE ss
SET role = selector
SET listen = 127.0.0.1:$port
SET persist_client = 1
SET plugins = Vhosts
VHOST doesnotexist.example.com = doesnotexist
VHOST * = test
ENABLE ss

CREATE SERVICE test
SET role = reverse_proxy
SET pool = a
ENABLE test
};

my $msock = start_server($conf);
ok($msock, 'perlbal started');

# make first web client
my $wc = Perlbal::Test::WebClient->new;
$wc->server("127.0.0.1:$port");
$wc->http_version('1.0');
$wc->keepalive(1);

{
my $resp = $wc->request({ host => "example.com", }, "test");
ok($resp->is_success, "Got a successful response");
}

{
my $resp = $wc->request({ host => "doesnotexist.example.com", }, "test");
is($resp->code, 404, "Got a 404 for non-existing service");
}

1;