1#!/usr/binperl
2
3#BEGIN {
4#  unless(grep /blib/, @INC) {
5#    chdir 't' if -d 't';
6#    unshift @INC, '../lib' if -d '../lib';
7#  }
8#}
9
10use strict;
11use warnings;
12
13use Test::More;
14
15BEGIN {
16  require SOAP::Lite;
17  eval { SOAP::Packager::MIME->new->initialize_parser; 1 };
18  if ($@) {
19    $@ =~ s/ at .+//;
20    print "1..0 # Skip: $@"; exit;
21  }
22}
23
24BEGIN { plan tests => 15 }
25
26my($a, $soap, $d, $s, $r, $serialized, $deserialized);
27
28{ # check attachment deserialization
29  $soap = SOAP::Lite->new();
30  $soap->init_context();
31
32  ##############################################################################
33  print "Attachment deserialization (Content-ID) test(s)...\n";
34  $a = $soap->deserializer->deserialize(<<'EOX');
35Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<claim061400a.xml@claiming-it.com>"
36SOAPAction: http://schemas.risky-stuff.com/Auto-Claim
37Content-Description: This is the optional message description.
38
39--MIME_boundary
40Content-Type: text/xml; charset=UTF-8
41Content-Transfer-Encoding: 8bit
42Content-ID: <claim061400a.xml@claiming-it.com>
43
44<?xml version='1.0' ?>
45<soap:Envelope
46    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
47  <soap:Body>
48    <claim:insurance_claim_auto
49          id="insurance_claim_document_id"
50          xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim">
51      <theSignedForm href="cid:claim061400a.tiff%40claiming-it.com" />
52      <theCrashPhoto href="cid:claim061400a.jpeg%40claiming-it.com" />
53      <somexml href="cid:claim061400a.somexml%40claiming-it.com" />
54      <realxml href="cid:claim061400a.realxml%40claiming-it.com" />
55      <!-- ... more claim details go here... -->
56    </claim:insurance_claim_auto>
57  </soap:Body>
58</soap:Envelope>
59
60--MIME_boundary
61Content-Type: image/tiff
62Content-Transfer-Encoding: base64
63Content-ID: <claim061400a.tiff@claiming-it.com>
64
65AAECAyAgIAQFBg==
66--MIME_boundary
67Content-Type: image/jpeg
68Content-Transfer-Encoding: binary
69Content-ID: <claim061400a.jpeg@claiming-it.com>
70
71...Raw JPEG image..
72--MIME_boundary
73Content-Type: text/plain
74Content-Transfer-Encoding: binary
75Content-ID: <claim061400a.somexml@claiming-it.com>
76
77<a><b>c</b></a>
78--MIME_boundary
79Content-Type: text/xml
80Content-Transfer-Encoding: binary
81Content-ID: <claim061400a.realxml@claiming-it.com>
82
83<a><b>c</b></a>
84--MIME_boundary--
85
86EOX
87
88  ok(ref $a);
89  ok(ref $a && ref $a->valueof('//insurance_claim_auto') &&
90                   $a->valueof('//insurance_claim_auto')->{theCrashPhoto} =~ /JPEG/);
91  ok(ref $a && $a->valueof('//theCrashPhoto') =~ /Raw JPEG image/);
92  ok(ref $a && $a->valueof('//theSignedForm') eq "\0\1\2\3   \4\5\6");
93  ok(ref $a && $a->valueof('//somexml') =~ m!<a><b>c</b></a>!);
94  ok(ref $a && $a->valueof('//realxml')->{b} eq 'c');
95
96  ##############################################################################
97  print "Attachment deserialization (Content-ID and Content-Location) test(s)...\n";
98  $a = $soap->deserializer->deserialize(<<'EOX');
99MIME-Version: 1.0
100Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<http://claiming-it.com/claim061400a.xml>"
101Content-Description: This is the optional message description.
102
103--MIME_boundary
104Content-Type: text/xml; charset=UTF-8
105Content-Transfer-Encoding: 8bit
106Content-ID: <http://claiming-it.com/claim061400a.xml>
107Content-Location: http://claiming-it.com/claim061400a.xml
108
109<?xml version='1.0' ?>
110<soap:Envelope
111    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
112  <soap:Body>
113    <claim:insurance_claim_auto
114          id="insurance_claim_document_id"
115          xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim">
116      <theSignedForm href="http://claiming-it.com/claim061400a.tiff" />
117    </claim:insurance_claim_auto>
118  </soap:Body>
119</soap:Envelope>
120
121--MIME_boundary
122Content-Type: image/tiff
123Content-Transfer-Encoding: binary
124Content-ID: <http://claiming-it.com/claim061400a.tiff>
125Content-Location: http://claiming-it.com/claim061400a.tiff
126
127...binary TIFF image...
128--MIME_boundary--
129
130EOX
131
132  ok(ref $a);
133  ok(ref $a && ref $a->valueof('//insurance_claim_auto') &&
134                   $a->valueof('//insurance_claim_auto')->{theSignedForm} =~ /TIFF/);
135  ok(ref $a && $a->valueof('//theSignedForm') =~ /binary TIFF image/);
136
137  ##############################################################################
138  print "Attachment deserialization (relative Content-Location) test(s)...\n";
139  # TODO - this unit test breaks - it does not seem to be picking up a base location
140  #        from outer Content-Location
141  eval { $a = $soap->deserializer->deserialize(<<'EOX'); };
142MIME-Version: 1.0
143Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<http://claiming-it.com/claim061400a.xml>"
144Content-Description: This is the optional message description.
145Content-Location: http://claiming-it.com/
146
147--MIME_boundary
148Content-Type: text/xml; charset=UTF-8
149Content-Transfer-Encoding: 8bit
150Content-ID: <http://claiming-it.com/claim061400a.xml>
151Content-Location: claim061400a.xml
152
153<?xml version='1.0' ?>
154<soap:Envelope
155    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
156  <soap:Body>
157    <claim:insurance_claim_auto
158          id="insurance_claim_document_id"
159          xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim">
160      <theSignedForm href="cid:claim061400a.tiff" />
161    </claim:insurance_claim_auto>
162  </soap:Body>
163</soap:Envelope>
164
165--MIME_boundary
166Content-Type: image/tiff
167Content-Transfer-Encoding: binary
168Content-Id: <claim061400a.tiff>
169Content-Location: claim061400a.tiff
170
171...binary TIFF image...
172--MIME_boundary--
173
174EOX
175  ok(ref $a);
176  ok(ref $a && ref $a->valueof('//insurance_claim_auto') &&
177                   $a->valueof('//insurance_claim_auto')->{theSignedForm} =~ /TIFF/);
178  ok(ref $a && $a->valueof('//theSignedForm') =~ /binary TIFF image/);
179
180  ##############################################################################
181  print "Attachment deserialization (no default Content-Location) test(s)...\n";
182  $a = $soap->deserializer->deserialize(<<'EOX');
183MIME-Version: 1.0
184Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<b6f4ccrt@15.4.9.92/s445>"
185Content-Description: This is the optional message description.
186
187--MIME_boundary
188Content-Type: text/xml; charset=UTF-8
189Content-Transfer-Encoding: 8bit
190Content-ID: <b6f4ccrt@15.4.9.92/s445>
191Content-Location: claim061400a.xml
192
193<?xml version='1.0' ?>
194<soap:Envelope
195    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
196  <soap:Body>
197    <claim:insurance_claim_auto
198          id="insurance_claim_document_id"
199          xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim">
200      <theSignedForm href="cid:a34ccrt%4015.4.9.92/s445" />
201    </claim:insurance_claim_auto>
202  </soap:Body>
203</soap:Envelope>
204
205--MIME_boundary
206Content-Type: image/tiff
207Content-Transfer-Encoding: binary
208Content-ID: <a34ccrt@15.4.9.92/s445>
209Content-Location: the_signed_form.tiff
210
211...binary TIFF image...
212--MIME_boundary-
213
214EOX
215#      <theSignedForm href="cid:the_signed_form.tiff"/>
216
217  ok(ref $a);
218  ok(ref $a && ref $a->valueof('//insurance_claim_auto') &&
219                   $a->valueof('//insurance_claim_auto')->{theSignedForm} =~ /TIFF/);
220  ok(ref $a && $a->valueof('//theSignedForm') =~ /binary TIFF image/);
221}
222