-
Notifications
You must be signed in to change notification settings - Fork 37
/
14_authenticate.t
54 lines (40 loc) · 1.67 KB
/
14_authenticate.t
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
#!perl
use warnings;
use strict;
use Test::More;
use Test::Exception;
use lib qw(t/lib);
use Net::Twitter;
eval 'use TestUA';
plan skip_all => 'LWP::UserAgent 5.819 required' if $@;
plan tests => 13;
my $nt = Net::Twitter->new(legacy => 1);
isa_ok $nt, 'Net::Twitter';
$nt = Net::Twitter->new(legacy => 0);
my $t = TestUA->new($nt->ua);
lives_ok { $nt->user_timeline } "lives without credentials";
ok !$t->request->header('Authorization'), "no auth header without credentials";
$nt->credentials(homer => 'doh!');
lives_ok { $nt->user_timeline } "lives with credentials";
like $t->request->header('Authorization'), qr/Basic/, "has Basic Auth header";
$nt->public_timeline;
ok $t->request->header('Authorization'), "public timeline auths by default";
$nt->public_timeline({ authenticate => 0 });
ok !$t->request->header('Authorization'), "public timeline can auth";
$nt->public_timeline({ authenticate => 1 });
ok $t->request->header('Authorization'), "can force authentication";
$nt->rate_limit_status({ authenticate => 0 });
ok !$t->request->header('Authorization'), "rate_limit_status allows no-auth";
$nt->rate_limit_status;
ok $t->request->header('Authorization'), "rate_limit_status defaults to auth";
$nt = Net::Twitter->new(
traits => [qw/API::REST OAuth/],
consumer_key => 'com key',
consumer_secret => 'com secret',
);
$t = TestUA->new($nt->ua);
lives_ok { $nt->user_timeline } "lives without oauth tokens";
ok !$t->request->header('Authorization'), "no auth header without access tokens";
$nt->access_token('1234');
$nt->access_token_secret('5678');
lives_ok { $nt->user_timeline } "lives with access tokens";