File: stringent-encoding.t

package info (click to toggle)
libnet-twitter-perl 4.01005-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 760 kB
  • ctags: 107
  • sloc: perl: 6,441; makefile: 13
file content (44 lines) | stat: -rw-r--r-- 1,087 bytes parent folder | download | duplicates (3)
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
#!perl
use warnings;
use strict;
use URI;
use Net::Twitter;
use Net::OAuth::Message;
use Test::More;

plan tests => 2;

# Ensure post args are encoded per the OAuth spec
#
# We assume Net::OAuth does the right thing, here.
#
# Bug reported by Nick Andrew (@elronxenu) 2013-02-27

my $nt = Net::Twitter->new(
    ssl                 => 0,
    traits              => [qw/API::RESTv1_1/],
    consumer_key        => 'mykey',
    consumer_secret     => 'mysecret',
    access_token        => 'mytoken',
    access_token_secret => 'mytokensecret',
);

my $req;
$nt->ua->add_handler(request_send => sub {
    $req = shift;
    my $res = HTTP::Response->new(200, 'OK');
    $res->content('{}');

    return $res;
});

my $text = q[Bob's your !@##$%^&*(){}} uncle!];
$nt->new_direct_message({ screen_name => 'perl_api', text => $text });

my $encoded_text = Net::OAuth::Message::encode($text);
like $req->content, qr/\E$encoded_text/, 'properly encoded';

my $uri = URI->new($req->uri);
$uri->query($req->content);
my %params = $uri->query_form;
is $params{text}, $text, 'decoded text matches';