File: 04-attach.t

package info (click to toggle)
libsoap-lite-perl 1.27-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 1,680 kB
  • sloc: perl: 8,908; makefile: 23; cs: 16
file content (299 lines) | stat: -rw-r--r-- 9,486 bytes parent folder | download | duplicates (2)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/usr/bin/env perl

BEGIN {
    unless ( grep /blib/, @INC ) {
        chdir 't' if -d 't';
        unshift @INC, '../lib' if -d '../lib';
    }
}

use strict;
use Test;

BEGIN {
    use SOAP::Lite;
    eval { SOAP::Packager::MIME->new->initialize_parser; 1 };
    if ($@) {
        $@ =~ s/ at .+//;
        print "1..0 # Skip: $@";
        exit;
    }
}

BEGIN { plan tests => 18 }

my ( $a, $soap, $d, $s, $r, $serialized, $deserialized );

{    # check attachment deserialization
    $soap = SOAP::Lite->new();
    $soap->init_context();

    ##############################################################################
    print "Attachment deserialization (Content-ID) test(s)...\n";
    $a = $soap->deserializer->deserialize(<<'EOX');
Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<claim061400a.xml@claiming-it.com>"
SOAPAction: http://schemas.risky-stuff.com/Auto-Claim
Content-Description: This is the optional message description.

--MIME_boundary
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <claim061400a.xml@claiming-it.com>

<?xml version='1.0' ?>
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <claim:insurance_claim_auto
          id="insurance_claim_document_id"
          xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim">
      <theSignedForm href="cid:claim061400a.tiff@claiming-it.com" />
      <theCrashPhoto href="cid:claim061400a.jpeg@claiming-it.com" />
      <somexml href="cid:claim061400a.somexml@claiming-it.com" />
      <realxml href="cid:claim061400a.realxml@claiming-it.com" />
      <!-- ... more claim details go here... -->
    </claim:insurance_claim_auto>
  </soap:Body>
</soap:Envelope>

--MIME_boundary
Content-Type: image/tiff
Content-Transfer-Encoding: base64
Content-ID: <claim061400a.tiff@claiming-it.com>

AAECAyAgIAQFBg==
--MIME_boundary
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
Content-ID: <claim061400a.jpeg@claiming-it.com>

...Raw JPEG image..
--MIME_boundary
Content-Type: text/plain
Content-Transfer-Encoding: binary
Content-ID: <claim061400a.somexml@claiming-it.com>

<a><b>c</b></a>
--MIME_boundary
Content-Type: text/xml
Content-Transfer-Encoding: binary
Content-ID: <claim061400a.realxml@claiming-it.com>

<a><b>c</b></a>
--MIME_boundary--

EOX

    ok( ref $a );
    ok(      ref $a
          && ref $a->valueof('//insurance_claim_auto')
          && $a->valueof('//insurance_claim_auto')->{theCrashPhoto} =~ /JPEG/ );
    ok( ref $a && $a->valueof('//theCrashPhoto') =~ /Raw JPEG image/ );
    ok( ref $a && $a->valueof('//theSignedForm') eq "\0\1\2\3   \4\5\6" );
    ok( ref $a && $a->valueof('//somexml') =~ m!<a><b>c</b></a>! );
    ok( ref $a && $a->valueof('//realxml')->{b} eq 'c' );

    ##############################################################################
    print
"Attachment deserialization (Content-ID and Content-Location) test(s)...\n";
    $a = $soap->deserializer->deserialize(<<'EOX');
MIME-Version: 1.0
Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<http://claiming-it.com/claim061400a.xml>"
Content-Description: This is the optional message description.

--MIME_boundary
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <http://claiming-it.com/claim061400a.xml>
Content-Location: http://claiming-it.com/claim061400a.xml

<?xml version='1.0' ?>
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <claim:insurance_claim_auto
          id="insurance_claim_document_id"
          xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim">
      <theSignedForm href="http://claiming-it.com/claim061400a.tiff" />
    </claim:insurance_claim_auto>
  </soap:Body>
</soap:Envelope>

--MIME_boundary
Content-Type: image/tiff
Content-Transfer-Encoding: binary
Content-ID: <http://claiming-it.com/claim061400a.tiff>
Content-Location: http://claiming-it.com/claim061400a.tiff

...binary TIFF image...
--MIME_boundary--

EOX

    ok( ref $a );
    ok(      ref $a
          && ref $a->valueof('//insurance_claim_auto')
          && $a->valueof('//insurance_claim_auto')->{theSignedForm} =~ /TIFF/ );
    ok( ref $a && $a->valueof('//theSignedForm') =~ /binary TIFF image/ );

    ##############################################################################
    print "Attachment deserialization (relative Content-Location) test(s)...\n";

# TODO - this unit test breaks - it does not seem to be picking up a base location
#        from outer Content-Location
    eval {
        $a = $soap->deserializer->deserialize(<<'EOX'); };
MIME-Version: 1.0
Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<http://claiming-it.com/claim061400a.xml>"
Content-Description: This is the optional message description.
Content-Location: http://claiming-it.com/

--MIME_boundary
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <http://claiming-it.com/claim061400a.xml>
Content-Location: claim061400a.xml

<?xml version='1.0' ?>
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <claim:insurance_claim_auto
          id="insurance_claim_document_id"
          xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim">
      <theSignedForm href="cid:claim061400a.tiff" />
    </claim:insurance_claim_auto>
  </soap:Body>
</soap:Envelope>

--MIME_boundary
Content-Type: image/tiff
Content-Transfer-Encoding: binary
Content-Id: <claim061400a.tiff>
Content-Location: claim061400a.tiff

...binary TIFF image...
--MIME_boundary--

EOX
    ok( ref $a );
    ok(      ref $a
          && ref $a->valueof('//insurance_claim_auto')
          && $a->valueof('//insurance_claim_auto')->{theSignedForm} =~ /TIFF/ );
    ok( ref $a && $a->valueof('//theSignedForm') =~ /binary TIFF image/ );

    ##############################################################################
    print
      "Attachment deserialization (no default Content-Location) test(s)...\n";
    $a = $soap->deserializer->deserialize(<<'EOX');
MIME-Version: 1.0
Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<b6f4ccrt@15.4.9.92/s445>"
Content-Description: This is the optional message description.

--MIME_boundary
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <b6f4ccrt@15.4.9.92/s445>
Content-Location: claim061400a.xml

<?xml version='1.0' ?>
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <claim:insurance_claim_auto
          id="insurance_claim_document_id"
          xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim">
      <theSignedForm href="cid:a34ccrt@15.4.9.92/s445" />
    </claim:insurance_claim_auto>
  </soap:Body>
</soap:Envelope>

--MIME_boundary
Content-Type: image/tiff
Content-Transfer-Encoding: binary
Content-ID: <a34ccrt@15.4.9.92/s445>
Content-Location: the_signed_form.tiff

...binary TIFF image...
--MIME_boundary-

EOX

    #      <theSignedForm href="cid:the_signed_form.tiff"/>

    ok( ref $a );
    ok(      ref $a
          && ref $a->valueof('//insurance_claim_auto')
          && $a->valueof('//insurance_claim_auto')->{theSignedForm} =~ /TIFF/ );
    ok( ref $a && $a->valueof('//theSignedForm') =~ /binary TIFF image/ );

    # check attachment of composite element
    $soap = SOAP::Lite->new();
    $soap->init_context();

    ##############################################################################
    print "Attachment deserialization (Nested Attachment) test(s)...\n";
    $a = $soap->deserializer->deserialize(<<'EOX');
Content-Type: Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<claimstart.xml@claiming-it.com>"
SOAPAction: http://schemas.risky-stuff.com/Auto-Claim
Content-Description: This is the optional message description.

--MIME_boundary
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <claimstart.xml@claiming-it.com>

<?xml version='1.0' ?>
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <claim:insurance_claim_auto
          id="insurance_claim_document_id"
          xmlns:claim="http://schemas.risky-stuff.com/Auto-Claim">
      <email href="cid:email.eml@claiming-it.com" />
    </claim:insurance_claim_auto>
  </soap:Body>
</soap:Envelope>

--MIME_boundary
Content-Type: message/rfc822
Content-Transfer-Encoding: binary
Content-ID: <email.eml@claiming-it.com>

MIME-Version: 1.0
X-Mailer: MIME::Lite 3.01 (F2.74; T1.24; A1.74; B3.07; Q3.07)
Date: Thu, 30 Apr 2009 15:59:49 -0400
To: foo@bar.com
Subject: multipart message
Content-Transfer-Encoding: binary
Content-Type: multipart/related; boundary="_----------=_1241121589160890"

This is a multi-part message in MIME format.

--_----------=_1241121589160890
Content-Disposition: inline
Content-Length: 35
Content-Transfer-Encoding: binary
Content-Type: text/html

<body>Here's <i>my</i> text</body>
--_----------=_1241121589160890
Content-Disposition: inline
Content-Length: 15
Content-Transfer-Encoding: binary
Content-Type: text/plain

Here's my text
--_----------=_1241121589160890--

--MIME_boundary--

EOX

    ok( ref $a );
    ok(      ref $a
          && ref $a->valueof('//insurance_claim_auto')
          && $a->valueof('//insurance_claim_auto')->{email} =~
          m{my(</i>)? text} );
    ok( ref $a && $a->valueof('//email') =~ m{my(</i>)? text} );
}