Skip to content

Commit

Permalink
better embedding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 5, 2012
1 parent 5e0f449 commit bcc4b48
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
3 changes: 1 addition & 2 deletions lib/Mojo/Template.pm
Expand Up @@ -128,8 +128,7 @@ sub compile {
->trace->verbose(1)
if $@;

$self->compiled($compiled);
return;
$self->compiled($compiled) and return;
}

sub interpret {
Expand Down
6 changes: 1 addition & 5 deletions lib/Mojolicious/Plugin/EPRenderer.pm
Expand Up @@ -10,12 +10,8 @@ use Mojo::Util qw/encode md5_sum/;
sub register {
my ($self, $app, $conf) = @_;

# Custom sandbox
my $template = $conf->{template} || {};
$template->{namespace} //= 'Mojo::Template::SandBox::'
. md5_sum(($ENV{MOJO_EXE} || ref $app) . $$);

# Auto escape by default to prevent XSS attacks
my $template = $conf->{template} || {};
$template->{auto_escape} //= 1;

# Add "ep" handler
Expand Down
3 changes: 0 additions & 3 deletions lib/Mojolicious/Plugin/HeaderCondition.pm
@@ -1,9 +1,6 @@
package Mojolicious::Plugin::HeaderCondition;
use Mojo::Base 'Mojolicious::Plugin';

# "You may have to "metaphorically" make a deal with the "devil".
# And by "devil", I mean Robot Devil.
# And by "metaphorically", I mean get your coat."
sub register {
my ($self, $app) = @_;

Expand Down
15 changes: 12 additions & 3 deletions t/mojolicious/embedded_lite_app.t
Expand Up @@ -9,7 +9,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 133;
use Test::More tests => 139;

use FindBin;
use lib "$FindBin::Bin/lib";
Expand Down Expand Up @@ -90,9 +90,12 @@ app->routes->namespace('MyTestApp');
my $external = "$FindBin::Bin/external/myapp.pl";
plugin Mount => {'/x/1' => $external};
plugin(Mount => ('/x/♥' => $external))->to(message => 'works 2!');
plugin Mount => {'/y/1' => "$FindBin::Bin/external/myapp2.pl"};
plugin Mount => {'mojolicious.org' => $external};
plugin Mount => {'MOJOLICIO.US/' => $external};
plugin Mount => {'*.kraih.com' => $external};
plugin(Mount => ('/y/♥' => "$FindBin::Bin/external/myapp2.pl"))
->to(message => 'works 3!');
plugin Mount => {'MOJOLICIO.US/' => $external};
plugin Mount => {'*.kraih.com' => $external};
plugin(Mount => ('*.foo-bar.de/♥/123' => $external))
->to(message => 'works 3!');

Expand Down Expand Up @@ -233,6 +236,12 @@ $t->get_ok('/x/♥/stream')->status_is(200)->content_is('hello!');
$t->get_ok('/x/♥/url/☃')->status_is(200)
->content_is('/x/%E2%99%A5/url/%E2%98%83 -> /x/%E2%99%A5/%E2%98%83/stream!');

# GET /y/1 (full secondary external application)
$t->get_ok('/y/1')->status_is(200)->content_is("works 4!\nInsecure too!");

# GET /y/♥ (full secondary external application)
$t->get_ok('/y/♥')->status_is(200)->content_is("works 3!\nInsecure too!");

# GET /host (main application)
$t->get_ok('/host')->status_is(200)->content_is('main application!');

Expand Down
21 changes: 21 additions & 0 deletions t/mojolicious/external/myapp2.pl
@@ -0,0 +1,21 @@
#!/usr/bin/env perl

# "You may have to "metaphorically" make a deal with the "devil".
# And by "devil", I mean Robot Devil.
# And by "metaphorically", I mean get your coat."
use Mojolicious::Lite;

# Secret for config file tests
app->secret('Insecure too!');

# GET /
get '/' => sub {
my $self = shift;
$self->render_text($self->render_partial('menubar') . app->secret);
};

app->start;
__DATA__
@@ menubar.html.ep
%= stash('message') || 'works 4!'

0 comments on commit bcc4b48

Please sign in to comment.