Skip to content

Instantly share code, notes, and snippets.

@jberger
Created May 26, 2016 15:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jberger/145e996feed64914d7802efd460bf48d to your computer and use it in GitHub Desktop.
Save jberger/145e996feed64914d7802efd460bf48d to your computer and use it in GitHub Desktop.
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