CatalystX-OAuth2
view release on metacpan or search on metacpan
t/unit/700-client.t view on Meta::CPAN
use strictures 1;
use Test::More;
use Test::MockObject;
use HTTP::Request::Common;
use JSON::Any;
use lib 't/lib';
use AuthServer;
use ClientApp;
use Catalyst::Authentication::Credential::OAuth2;
# can't use Test::Mock::Object here because mocked methods aren't recognized
# by the requires 'method'; role application constraint
package Test::Mock::Store;
use Moose;
sub for_session { }
package Test::Mock::Realm;
use Moose;
use URI;
our $user;
our $store = Test::Mock::Store->new;
our @called;
sub find_user { push @called, [ 'find_user', [@_] ]; $user }
sub restore_user { push @called, [ 'restore_user', [@_] ]; $user }
sub persist_user { push @called, [ 'persist_user', [@_] ]; $user }
sub store { push @called, [ 'store', [@_] ]; $store }
package main;
use Catalyst::Test 'ClientApp';
{
my ($res2, $c) = ctx_request('/');
my $realm = Test::Mock::Realm->new;
my $cred = Catalyst::Authentication::Credential::OAuth2->new(
{ grant_uri => 'http://server.foo/grant',
token_uri => 'http://server.foo/token',
client_id => 42,
client_secret => 'foosecret'
},
ClientApp => $realm
);
is_deeply( [ map { $_->name } $realm->meta->calculate_all_roles ],
[qw(CatalystX::OAuth2::ClientInjector)] );
ok( !$cred->authenticate( $c, $realm, {} ) );
# we should have called ->store at this point
is( @Test::Mock::Realm::called + 0, 1 );
{
my ( $name, $args ) = @{ pop @Test::Mock::Realm::called };
is($name => 'store');
is_deeply($args, [$realm])
}
is( $c->res->status, 302 );
my $callback_uri = $cred->_build_callback_uri($c);
is( $callback_uri, 'http://localhost/' );
my $extend_perms_uri = $cred->extend_permissions($callback_uri);
( run in 0.849 second using v1.01-cache-2.11-cpan-437f7b0c052 )