forked from lyokato/p5-oauth-lite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
03_signature_method_hmac_sha1.t
44 lines (31 loc) · 1.18 KB
/
03_signature_method_hmac_sha1.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
use Test::More tests => 8;
use OAuth::Lite::SignatureMethod::HMAC_SHA1;
is(OAuth::Lite::SignatureMethod::HMAC_SHA1->method_name, 'HMAC-SHA1');
is(OAuth::Lite::SignatureMethod::HMAC_SHA1->build_body_hash(qq{Hello World!}), q{Lve95gjOVATpfV8EL5X4nxwjKHE=});
my $base = "hogehogehoge";
my $signer = OAuth::Lite::SignatureMethod::HMAC_SHA1->new(
consumer_secret => 'foo',
token_secret => 'bar',
);
my $signature = $signer->sign($base);
is($signature, q{TdSY8Tl5G/ihzaO8aRnIIdc7Wkc=});
my $verifier = OAuth::Lite::SignatureMethod::HMAC_SHA1->new(
consumer_secret => 'foo',
token_secret => 'bar',
);
my $invalid_verifier = OAuth::Lite::SignatureMethod::HMAC_SHA1->new(
consumer_secret => 'foo',
token_secret => 'invalid',
);
ok($verifier->verify($base, $signature));
ok(!$invalid_verifier->verify($base, $signature));
my $signer2 = OAuth::Lite::SignatureMethod::HMAC_SHA1->new(
consumer_secret => 'foo',
);
my $signature2 = $signer2->sign($base);
is($signature2, q{ietxdwnHDniD+idyuFYk7MVQxHY=});
my $verifier2 = OAuth::Lite::SignatureMethod::HMAC_SHA1->new(
consumer_secret => 'foo',
);
ok($verifier2->verify($base, $signature2));
ok(!$invalid_verifier->verify($base, $signature2));