Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 1 | use Mojo::Base -strict; |
| 2 | use Test::More; |
| 3 | use Test::Mojo; |
| 4 | use Mojo::File qw/path/; |
| 5 | use Data::Dumper; |
| 6 | |
| 7 | |
| 8 | ##################### |
| 9 | # Start Fake server # |
| 10 | ##################### |
| 11 | my $mount_point = '/realapi/'; |
| 12 | $ENV{KALAMAR_API} = $mount_point; |
| 13 | |
| 14 | my $t = Test::Mojo->new('Kalamar' => { |
| 15 | Kalamar => { |
| 16 | plugins => ['Auth'] |
| 17 | } |
| 18 | }); |
| 19 | |
| 20 | # Mount fake backend |
| 21 | # Get the fixture path |
| 22 | my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'server'); |
| 23 | my $fake_backend = $t->app->plugin( |
| 24 | Mount => { |
| 25 | $mount_point => |
| 26 | $fixtures_path->child('mock.pl') |
| 27 | } |
| 28 | ); |
| 29 | # Configure fake backend |
| 30 | $fake_backend->pattern->defaults->{app}->log($t->app->log); |
| 31 | |
| 32 | # Globally set server |
| 33 | $t->app->ua->server->app($t->app); |
| 34 | |
| 35 | my $r = $t->app->routes; |
| 36 | |
| 37 | # API proxy route |
| 38 | $r->any('/api/v#apiv' => [apiv => ['1.0']])->to('Proxy#pass'); |
| 39 | $r->any('/api/v#apiv/*path' => [apiv => ['1.0']])->to('Proxy#pass'); |
| 40 | |
| 41 | $t->get_ok('/realapi/v1.0') |
| 42 | ->status_is(200) |
| 43 | ->content_is('Fake server available') |
| 44 | ; |
| 45 | |
| 46 | $t->get_ok('/api/v1.0/') |
| 47 | ->status_is(200) |
| 48 | ->content_is('Fake server available') |
| 49 | ; |
| 50 | |
| 51 | $t->get_ok('/api/v1.0/search?ql=cosmas3') |
| 52 | ->status_is(400) |
| 53 | ->json_is('/errors/0/0','307') |
Akron | 56b3d0d | 2019-07-10 17:13:31 +0200 | [diff] [blame^] | 54 | ->header_is('connection', 'close') |
Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 55 | ; |
| 56 | |
| 57 | $t->post_ok('/api/v1.0/oauth2/token' => {} => form => { |
| 58 | username => 'test', |
| 59 | password => 'pass' |
| 60 | }) |
| 61 | ->status_is(400) |
| 62 | ->json_is('/errors/0/1','Grant Type unknown') |
| 63 | ; |
| 64 | |
| 65 | $t->post_ok('/api/v1.0/oauth2/token' => {} => form => { |
| 66 | grant_type => 'password', |
| 67 | client_id => 2, |
| 68 | client_secret => 'k414m4r-s3cr3t', |
| 69 | username => 'test', |
| 70 | password => 'pass' |
| 71 | }) |
| 72 | ->status_is(200) |
| 73 | ->json_is('/token_type', 'Bearer') |
| 74 | ; |
| 75 | |
| 76 | |
| 77 | done_testing; |
| 78 | __END__ |