File: auth_url.t

package info (click to toggle)
libmojolicious-plugin-oauth2-perl 2.02-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 192 kB
  • sloc: perl: 448; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 1,432 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use Mojo::Base -strict;
use Test::Mojo;
use Test::More;

my $authorize_args = {};

use Mojolicious::Lite;
plugin 'OAuth2' => {facebook => {key => 'KEY'}};
get '/test123', sub { $_[0]->render(text => $_[0]->oauth2->auth_url('facebook', $authorize_args)); };

my $t = Test::Mojo->new;

eval { $t->app->oauth2->auth_url };
like $@, qr{Invalid provider}, 'provider_id is required';

$t->get_ok('/test123')->status_is(200);
my $url = Mojo::URL->new($t->tx->res->body);
like $url, qr{^https://graph\.facebook\.com/oauth/authorize}, 'base url';
is $url->query->param('client_id'),      'KEY',         'client_id';
like $url->query->param('redirect_uri'), qr{/test123$}, 'redirect_uri';

$authorize_args = {
  scope           => 'email,age',
  redirect_uri    => 'https://example.com',
  host            => 'oauth2.example.com',
  state           => '42',
  authorize_query => {foo => 123},
};

$t->get_ok('/test123')->status_is(200);
$url = Mojo::URL->new($t->tx->res->body);
like $url, qr{^https://oauth2\.example\.com/oauth/authorize}, 'custom.host';
is $url->query->param('foo'),          '123',                 'foo';
is $url->query->param('client_id'),    'KEY',                 'client_id';
is $url->query->param('redirect_uri'), 'https://example.com', 'custom.redirect_uri';
is $url->query->param('scope'),        'email,age',           'scope';
is $url->query->param('state'),        '42',                  'state';

done_testing;