Google-OAuth

 view release on metacpan or  search on metacpan

t/Google-OAuth.t  view on Meta::CPAN

               }, 'Google::OAuth' );

my $json = <<'eof' ;
{
 "kind": "calendar#calendarList",
 "etag": "\"GZxpEFttRDAOmLHnWRxLHHWPGwk/PlPjmjzcESbTBnWfLUd5E8QtBFI\"",
 "items": [
  {
   "kind": "calendar#calendarListEntry",
   "etag": "\"GZxpEFttRDAOmLHnWRxLHHWPGwk/rlBZV92t2W1zCqj28DRxbmcr5Fs\"",
   "id": "#contacts@group.v.calendar.google.com",
   "summary": "Contacts' birthdays and events",
   "description": "Your contacts' birthdays and anniversaries",
   "timeZone": "America/New_York",
   "colorId": "12",
   "backgroundColor": "#fad165",
   "foregroundColor": "#000000",
   "selected": true,
   "accessRole": "reader"
  },
  {
   "kind": "calendar#calendarListEntry",
   "etag": "\"GZxpEFttRDAOmLHnWRxLHHWPGwk/komAuKJmJeZLAvxlc0nIjOqTkKA\"",
   "id": "en.usa#holiday@group.v.calendar.google.com",
   "summary": "US Holidays",
   "description": "US Holidays",
   "timeZone": "America/New_York",
   "colorId": "15",
   "backgroundColor": "#9fc6e7",
   "foregroundColor": "#000000",
   "selected": true,
   "accessRole": "reader"
  }
 ]
}
eof

my $item = {
               'timeZone' => 'America/New_York',
               'colorId' => '15',
               'description' => 'US Holidays',
               'accessRole' => 'reader',
               'etag' => '"GZxpEFttRDAOmLHnWRxLHHWPGwk/komAuKJmJeZLAvxlc0nIjOqTkKA"',
               'kind' => 'calendar#calendarListEntry',
               'foregroundColor' => '#000000',
               'summary' => 'US Holidays',
               'id' => 'en.usa#holiday@group.v.calendar.google.com',
               'selected' => 'true',
               'backgroundColor' => '#9fc6e7'
             } ;

my $t ;
my $ok ;

is( Google::OAuth->dsn->table, 'googletokens', 'DSN name' ) ;
is( ref Google::OAuth->dsn->db, 'NoSQL::PL2SQL::DBI::Null', 'DSN source' ) ;

$t = Google::OAuth::Client->new->scope(
                'calendar.readonly' 
		)->token_request ;
ok( linkcompare( $t, $test[0] ), 'Default credentials' ) ;

$t = Google::OAuth::Client->new->scope(
		'm8.feeds', 'calendar', 'calendar.readonly', 'drive.readonly', 
		)->token_request ;
ok( linkcompare( $t, $test[1] ), 'Expanded scope' ) ;


my @credentials = qw(
	client_id
	FTNmkFXfh6OZH5jXsW7qLe3bgsnl7ZObPfsuscNy
	client_secret
	Op6MR5gl73VY2yJkrb86dT4iySguvM8HhSqC2dEm
	) ;

is( Google::OAuth->setclient( @credentials ), undef, 'setclient' ) ;

$t = Google::OAuth::Client->new->scope(
                'calendar.readonly' 
		)->token_request ;
ok( linkcompare( $t, $test[2] ), 'Modified credentials' ) ;

$t = Google::OAuth::Client->new(
		'client_id', { foo => 'client_secret' }
		)->scope(
                'calendar.readonly' 
		)->token_request ;
ok( linkcompare( $t, $test[3] ), 'token_request override' ) ;

is( ref $token, 'Google::OAuth', 'Test token found' ) ;
is( $Google::OAuth::Config::test{grantcode}, 
		'1/fk7qwDysHKcwfa2S8ZKWTv2-nwTfxpPva3dzmujc_gQ', 
		'Grant Code found' ) ;

my $event = Google::OAuth::CGI->new( $item )->query_string ;
ok( linkcompare( $event, $test[4] ), 'CGI::Simple object' ) ;

my $tqis = 'http://www.tqis.com/pen/GoogleAuth/test.htm' ;

is( $token->response( GET => $tqis )->code, 200, 'token response GET' ) ;

my $request = $token->request( POST => $tqis, $event ) ;

my @headers = %{ $request->headers } ;
my %headers = map { $_ => 1 } (
  'content-type',
  'application/x-www-form-urlencoded',
  'content-length',
  '319',
  'authorization',
  'Bearer ya29.Et6DoQjLzjpioHPGbMyDeGfUS00SuTlIrIsZE_FIDzXtU0IJ1-AnAg'
  ) ;
map { delete $headers{$_} } @headers ;

is( @headers, 6, 'POST request header keys' ) ;
is( keys %headers, 0, 'POST request header values' ) ;
is( $request->content(), $event, 'POST request content' ) ;

my $response = LWP::UserAgent->new->request( $request ) ;
is( $response->code, 200, 'token request POST' ) ;
my $content = $response->content ;
chomp( $content ) ;
is( $content, $event, 'POST request response content' ) ;

$reponse = $token->response( POST => $tqis, $event ) ;
is( $response->code, 200, 'token response POST' ) ;

$content = $response->content ;
chomp( $content ) ;
is( $content, $event, 'POST response content' ) ;

$content = $token->content( POST => $tqis, $event ) ;
chomp( $content ) ;
is( $content, $event, 'POST content' ) ;

$reponse = $token->response( POST => $tqis, $event ) ;
is( $token->response( GET => $tqis )->code, 200, 'token response GET' ) ;

is( length( $json ), 987, 'json scalar found' ) ;

my $google = Google::OAuth->get_token( 'redirect_uri', 



( run in 1.025 second using v1.01-cache-2.11-cpan-39bf76dae61 )