Refactor & centralize mapping of incoming libpurple presence codes.
[thrasher.git] / perl / tests / pep_avatar.pl
blob0997c496d346779b523134cdb089faa000a51683
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 # Test that avatar publishing works as expected, especially as it
7 # tends to have a lot of corner cases w.r.t. image integrity.
9 use Test::More 'no_plan';
10 use Data::Dumper;
12 use MIME::Base64 qw(encode_base64 decode_base64);
14 BEGIN {
15 use_ok 'Thrasher::Test', qw(:all);
16 use_ok 'Thrasher', qw(:all);
17 use_ok 'Thrasher::Component';
18 use_ok 'Thrasher::Plugin', qw(:all);
19 use_ok 'Thrasher::Plugin::PEPAvatar';
20 use_ok 'Thrasher::Backend::Test';
21 use_ok 'Thrasher::Callbacks', qw(:all);
22 use_ok 'Thrasher::Avatar', qw(:all);
25 my $JID = transport_jid;
27 # Lie that we detected PEP, so this stuff actually comes out in XML
28 succeeded('pep_detected');
30 # The user wishes to set a good PNG avatar; ensure the correct XML
31 # goes out, and that when the server replies with the expected
32 # packets, the component correctly ignores it.
33 GOOD_PNG_AVATAR: {
34 my $comp = logged_in_comp;
36 set_avatar($comp, 'romeo@montague.lit', 'juliet@' . $JID, $small_png);
38 my $expected_xml = clean_xml(<<EXPECTED);
39 <iq from='juliet\@test.transport'
40 id='id3'
41 type='set'>
42 <pubsub xmlns='http://jabber.org/protocol/pubsub'>
43 <publish xmlns='urn:xmpp:avatar:metadata'>
44 <info>
45 <item id='0765a59164829a0fe4eb243ffb14bdd64a3d8f5d'>
46 <metadata>
47 <info bytes='741'
48 height='16'
49 id='0765a59164829a0fe4eb243ffb14bdd64a3d8f5d'
50 type='image/png'
51 width='16'/>
52 </metadata>
53 </item>
54 </info>
55 </publish>
56 </pubsub>
57 </iq>
58 <iq from='juliet\@test.transport'
59 id='id4'
60 type='set'>
61 <pubsub xmlns='http://jabber.org/protocol/pubsub'>
62 <publish xmlns='urn:xmpp:avatar:data'>
63 <items>
64 <item id='0765a59164829a0fe4eb243ffb14bdd64a3d8f5d'>
65 <data>$small_png_base64</data>
66 </item>
67 </items>
68 </publish>
69 </pubsub>
70 </iq>
71 EXPECTED
73 is(clean_xml(output), $expected_xml,
74 'expected pub_sub output on setting a PNG avatar');
77 GOOD_GIF_AVATAR: {
78 my $comp = logged_in_comp;
80 set_avatar($comp, 'romeo@montague.lit', "juliet\@$JID", $small_gif);
82 my $expected = clean_xml(<<EXPECTED);
83 <iq from='juliet\@test.transport'
84 id='id7'
85 type='set'>
86 <pubsub xmlns='http://jabber.org/protocol/pubsub'>
87 <publish xmlns='urn:xmpp:avatar:metadata'>
88 <info>
89 <item id='$small_gif_png_sha1'>
90 <metadata>
91 <info bytes='$small_gif_png_len'
92 height='55'
93 id='$small_gif_png_sha1'
94 type='image/png'
95 width='44'/>
96 </metadata>
97 </item>
98 </info>
99 </publish>
100 </pubsub>
101 </iq>
102 <iq from='juliet\@test.transport'
103 id='id8'
104 type='set'>
105 <pubsub xmlns='http://jabber.org/protocol/pubsub'>
106 <publish xmlns='urn:xmpp:avatar:data'>
107 <items>
108 <item id='$small_gif_png_sha1'>
109 <data>$small_gif_png_base64</data>
110 </item>
111 </items>
112 </publish>
113 </pubsub>
114 </iq>
115 EXPECTED
117 is(clean_xml(output), $expected,
118 'proper handling of the GIF case; converted to PNG');
121 BAD_DATA: {
122 my $comp = logged_in_comp;
124 set_avatar($comp, 'romeo@montague.lit', "juliet\@$JID", $binary_garbage);
126 is(output, '', 'no XML output');
127 logged("failed to determine a type for the image",
128 'correct error message output by the PEP plugin');