Created
May 26, 2016 15:37
-
-
Save jberger/145e996feed64914d7802efd460bf48d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojolicious::Lite; | |
use Test::More; | |
use Test::Mojo; | |
under '/auth' => sub { | |
my $c = shift; | |
my $auth = $c->param('auth'); | |
unless ($auth eq 'passw0rd') { | |
$c->render(text => 'Not Authorized', status => 403); | |
return 0; | |
} | |
return 1; | |
}; | |
# remember that websocket is just a specialized get requeset | |
get '/echo' => sub { | |
my $c = shift; | |
$c->on(text => sub { | |
my ($c, $payload) = @_; | |
$c->send("got $payload"); | |
}); | |
}; | |
my $t = Test::Mojo->new; | |
$t->get_ok('/auth/echo') | |
->status_is(403); | |
$t->websocket_ok('/auth/echo?auth=passw0rd') | |
->send_ok('hi') | |
->message_ok | |
->message_is('got hi') | |
->finish_ok; | |
done_testing; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment