summaryrefslogtreecommitdiff
path: root/t/Helper.pm
blob: 086d9c6490155a3a34f853b15758eea18a422f2e (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package t::Helper;
use Mojo::Base -strict;
use Mojolicious;
use Test::Mojo;
use Test::More;

sub make_app {
  my $app = Mojolicious->new;

  $app->plugin(
    OAuth2 => {
      test => {
        authorize_url => '/oauth/authorize',
        token_url     => '/oauth/token',
        key           => 'fake_key',
        secret        => 'fake_secret',
        scope         => 'a,b,c',
      }
    }
  );

  $app->routes->get(
    '/oauth/authorize' => sub {
      my $c = shift;
      if ($c->param('client_id') and $c->param('redirect_uri') and $c->param('scope')) {
        my $return = Mojo::URL->new($c->param('redirect_uri'));
        $return->query->append(code => 'fake_code');
        $c->redirect_to($return);
      }
      else {
        $c->render(status => 404, text => 'REJECTED');
      }
    }
  );

  $app->routes->post(
    '/oauth/token' => sub {
      my $c = shift;
      if ($c->param('client_secret') and $c->param('redirect_uri') and $c->param('code')) {
        my $qp = Mojo::Parameters->new(access_token => 'fake_token', lifetime => 3600);
        $c->render(text => $qp->to_string);
      }
      else {
        $c->render(status => 404, text => 'FAIL OVERFLOW');
      }
    }
  );

  return $app;
}

sub import {
  my $class  = shift;
  my $caller = caller;

  strict->import;
  warnings->import;

  eval <<"HERE" or die;
package $caller;
use Test::Mojo;
use Test::More;
1;
HERE

}

1;