File: testload.py

package info (click to toggle)
python-odf 1.4.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 28,620 kB
  • sloc: python: 22,659; javascript: 6,623; makefile: 360; xml: 2; sh: 1
file content (582 lines) | stat: -rw-r--r-- 22,727 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2008-2010 Søren Roug, European Environment Agency
#
# This is free software.  You may redistribute it under the terms
# of the Apache license and the GNU General Public License Version
# 2 or at your option any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#
# Contributor(s):
#

import unittest, os, os.path, sys

from io import BytesIO
from zipfile import ZipFile

from odf.opendocument import OpenDocumentText, load
from odf import style, text
from odf.text import P, H, LineBreak
from elementparser import ElementParser

from defusedxml import EntitiesForbidden


if sys.version_info[0]==3:
    unicode=str

class TestSimple(unittest.TestCase):

    def setUp(self):
        textdoc = OpenDocumentText()
        p = P(text="Hello World!")
        textdoc.text.addElement(p)
        textdoc.save(u"TEST.odt")
        self.saved = True

    def tearDown(self):
        if self.saved:
            os.unlink(u"TEST.odt")

    def test_simple(self):
        """ Check that a simple load works """
        d = load(u"TEST.odt")
        result = d.contentxml() # contentxml() is supposed to yeld a bytes
        self.assertNotEqual(-1, result.find(b"""Hello World!"""))


class TestHeadings(unittest.TestCase):

    saved = False

    def tearDown(self):
        if self.saved:
            os.unlink("TEST.odt")

    def test_headings(self):
        """ Create a document, save it and load it """
        textdoc = OpenDocumentText()
        textdoc.text.addElement(H(outlinelevel=1, text=u"Heading 1"))
        textdoc.text.addElement(P(text=u"Hello World!"))
        textdoc.text.addElement(H(outlinelevel=2, text=u"Heading 2"))
        textdoc.save(u"TEST.odt")
        self.saved = True
        d = load(u"TEST.odt")
        result = d.contentxml() # contentxml() is supposed to yeld a bytes
        self.assertNotEqual(-1, result.find(b"""<text:h text:outline-level="1">Heading 1</text:h><text:p>Hello World!</text:p><text:h text:outline-level="2">Heading 2</text:h>"""))

    def test_linebreak(self):
        """ Test that a line break (empty) element show correctly """
        textdoc = OpenDocumentText()
        p = P(text=u"Hello World!")
        textdoc.text.addElement(p)
        p.addElement(LineBreak())
        p.addText(u"Line 2")
        textdoc.save(u"TEST.odt")
        self.saved = True
        d = load(u"TEST.odt")
        result = d.contentxml() # contentxml() is supposed to yeld a bytes
        self.assertNotEqual(-1, result.find(b"""<text:p>Hello World!<text:line-break/>Line 2</text:p>"""))


class BaseXMLVulnerabilities(unittest.TestCase):
    def _modify_zip_file(self, zip_path, filename, replacement_content=None):
        """
        Replace the contents of a file inside a ZIP-container. The original file
        will not be overwritten. A BytesIO() file will be returned containing
        the new ZIP-container with the file replaced.

        :param zip_path The path to the ZIP-File to be modified
        :param filename Filename inside the container to be modified
        :param replacement_content The new container which will be stored in `filename`
        :return BytesIO contain the modified zip file.
        """
        vuln_zipfile = BytesIO()
        zw = ZipFile(vuln_zipfile, 'w')
        zr = ZipFile(zip_path)

        names_to_copy = set(zr.namelist()) - {filename, }
        for name in names_to_copy:
            content = zr.read(name)
            zw.writestr(name, content)

        if replacement_content:
            zw.writestr(filename, replacement_content)

        zw.close()
        vuln_zipfile.seek(0)

        x = ZipFile(vuln_zipfile, 'r')
        self.assertEqual(x.testzip(), None)

        vuln_zipfile.seek(0)

        return vuln_zipfile

    def modify_zip_file(self, zip_path, filename, replacements):
        """
        Performan a list of replacments on `filename` the original file in
        `zip_path` will remain unaffected and a BytesIO object will be returned
        containing the new zip file.

        :param zip_path Path to the zip-file.
        :param filename Filename where the replacements will be performed on
        :param replacements An iterable containing replacements using two-tuples.
                            e.g. [(orig_string, new_string), ]
        :return BytesIO contain the modified zip file.
        """
        zr = ZipFile(zip_path)
        original_content = zr.read(filename).decode('utf-8')
        new_content = original_content

        for old, new in replacements:
            new_content = new_content.replace(old, new)
        new_content = new_content.encode('utf-8')

        return self._modify_zip_file(zip_path, filename, replacement_content=new_content)


class TestQuadraticBlowup(BaseXMLVulnerabilities):
    attack_entity = (
        '<?xml version="1.0" encoding="UTF-8"?>'
        '<!DOCTYPE bomb ['
        '<!ENTITY a "{loads_of_bs}">'
        ']>'
    ).format(loads_of_bs="B" * 100000)
    simple_ods = os.path.join(os.path.dirname(__file__), "examples", "empty.ods")
    loads_of_as = '&a;' * 1000

    def test_manifest_xml(self):
        """
        N.B. Haven't actually triggered this attack.
        """
        attack_file = 'META-INF/manifest.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('manifest:full-path="/" manifest:version="1.2"',
             'manifest:full-path="/" manifest:version="{loads_of_as}"'.format(loads_of_as=self.loads_of_as)),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

    def test_settings_xml(self):
        attack_file = 'settings.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('"VerticalSplitMode" config:type="short">0</config:config-item>',
             '"VerticalSplitMode" config:type="short">{loads_of_as}</config:config-item>'.format(
                 loads_of_as=self.loads_of_as
             )),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

        # To trigger:
        # d = load(new_zipfile)
        # print(d.settingsxml())

    def test_meta_xml(self):
        attack_file = 'meta.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('<meta:creation-date>', '<meta:creation-date>{loads_of_as}'.format(
                loads_of_as=self.loads_of_as)),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

        # To trigger:
        # d = load(new_zipfile)
        # print(d.metaxml())

    def test_content_xml(self):
        """
        N.B. Haven't actually triggered this attack.
        """
        attack_file = 'content.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('style:name="Liberation Sans"', 'style:name="Liberation Sans {loads_of_as}"'.format(
                loads_of_as=self.loads_of_as)),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

        # To trigger:
        # d = load(new_zipfile)
        # print(d.metaxml())

    def test_styles_xml(self):
        attack_file = 'styles.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('<text:time>00:00:00</text:time>', '<text:time>{loads_of_as}; 00:00:00</text:time>'.format(
                loads_of_as=self.loads_of_as)),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

        # To trigger:
        # d = load(new_zipfile)
        # print(d.stylesxml())


class TestXMLBomb(BaseXMLVulnerabilities):
    """
    Tests various XML files inside the ODS container
    for the Billion laughs attack.
    """
    attack_entity = (
        '<?xml version="1.0" encoding="UTF-8"?>'
        '<!DOCTYPE xmlbomb ['
        '<!ENTITY a "1234567890" >'
        '<!ENTITY b "&a;&a;&a;&a;&a;&a;&a;&a;">'
        '<!ENTITY c "&b;&b;&b;&b;&b;&b;&b;&b;">'
        '<!ENTITY d "&c;&c;&c;&c;&c;&c;&c;&c;">'
        '<!ENTITY e "&d;&d;&d;&d;&d;&d;&d;&d;">'
        '<!ENTITY f "&e;&e;&e;&e;&e;&e;&e;&e;">'
        '<!ENTITY g "&f;&f;&f;&f;&f;&f;&f;&f;">'
        ']>'
    )
    simple_ods = os.path.join(os.path.dirname(__file__), "examples", "empty.ods")

    def test_manifest_xml(self):
        """
        N.B. Haven't actually triggered this attack.
        """
        attack_file = 'META-INF/manifest.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('manifest:full-path="/" manifest:version="1.2"',
             'manifest:full-path="/" manifest:version="&g;"'),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

    def test_settings_xml(self):
        attack_file = 'settings.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('<config:config-item config:name="VerticalSplitMode" config:type="short">0</config:config-item>',
             '<config:config-item config:name="VerticalSplitMode" config:type="short">&g;</config:config-item>'),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

        # To trigger:
        # d = load(new_zipfile)
        # print(d.settingsxml())

    def test_meta_xml(self):
        attack_file = 'meta.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('<meta:creation-date>', '<meta:creation-date>xx&g;'),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

        # To trigger:
        # d = load(new_zipfile)
        # print(d.metaxml())

    def test_content_xml(self):
        """
        N.B. Haven't actually triggered this attack.
        """
        attack_file = 'content.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('style:name="Liberation Sans"', 'style:name="Liberation Sans &g;"'),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

    def test_styles_xml(self):
        """
        N.B. Haven't actually triggered this attack.
        """
        attack_file = 'styles.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('<text:time>00:00:00</text:time>', '<text:time>&g; 00:00:00</text:time>'),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

        # To trigger:
        # d = load(new_zipfile)
        # print(d.stylesxml())


class TestXXEFile(BaseXMLVulnerabilities):
    attack_entity = (
        '<?xml version="1.0" encoding="UTF-8"?>'
        '<!DOCTYPE external ['
        '<!ENTITY ee SYSTEM "/etc/passwd">'
        ']>'
    )
    simple_ods = os.path.join(os.path.dirname(__file__), "examples", "empty.ods")

    def test_manifest_xml(self):
        """
        N.B. Haven't actually triggered this attack.
        """
        attack_file = 'META-INF/manifest.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('manifest:full-path="/" manifest:version="1.2"',
             'manifest:full-path="/" manifest:version="&ee;"')
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

    def test_settings_xml(self):
        """
        N.B. Haven't actually triggered this attack.
        """
        attack_file = 'settings.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('config:name="ActiveTable" config:type="string">',
             'config:name="ActiveTable" config:type="string">&xxe;')
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

        # To trigger:
        # d = load(new_zipfile)
        # print(d.settingsxml())

    def test_meta_xml(self):
        """
        N.B. Haven't actually triggered this attack.
        """
        attack_file = 'meta.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('<meta:creation-date>', '<meta:creation-date>&xxe;')
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

        # To trigger:
        # d = load(new_zipfile)
        # print(d.metaxml())

    def test_content_xml(self):
        """
        N.B. Haven't actually triggered this attack.
        """
        attack_file = 'content.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('style:name="Liberation Sans"', 'style:name="Liberation Sans &g;"'),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

        # To trigger:
        # d = load(new_zipfile)
        # print(d.metaxml())

    def test_styles_xml(self):
        """
        N.B. Haven't actually triggered this attack.
        """
        attack_file = 'styles.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
            ('<text:time>00:00:00</text:time>', '<text:time>&ee; 00:00:00</text:time>'),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

        # To trigger:
        # d = load(new_zipfile)
        # print(d.stylesxml())


class TestXXE(BaseXMLVulnerabilities):
    attack_entity = (
        '<?xml version="1.0" encoding="UTF-8"?>'
        '<!DOCTYPE test [ '
        '<!ENTITY % one SYSTEM "http://127.0.0.1:8100/x.xml" >'
        '%one;'
        ']>'
    )
    simple_ods = os.path.join(os.path.dirname(__file__), "examples", "empty.ods")

    def test_manifest_xml(self):
        attack_file = 'META-INF/manifest.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)

        self.assertRaises(EntitiesForbidden, load, new_zipfile)

    def test_settings_xml(self):
        """
        Was caught by
            parser.setFeature(handler.feature_external_ges, 0)
        """
        attack_file = 'settings.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

    def test_meta_xml(self):
        """
        Was caught by
            parser.setFeature(handler.feature_external_ges, 0)
        """
        attack_file = 'meta.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)

    def test_content_xml(self):
        """
        Was caught by
            parser.setFeature(handler.feature_external_ges, 0)
        """
        attack_file = 'content.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)

        self.assertRaises(EntitiesForbidden, load, new_zipfile)

    def test_styles_xml(self):
        """
        Was caught by
            parser.setFeature(handler.feature_external_ges, 0)
        """
        attack_file = 'styles.xml'
        replacements = (
            ('<?xml version="1.0" encoding="UTF-8"?>', self.attack_entity),
        )
        new_zipfile = self.modify_zip_file(self.simple_ods, attack_file, replacements)
        self.assertRaises(EntitiesForbidden, load, new_zipfile)


class TestExampleDocs(unittest.TestCase):

    def test_metagenerator(self):
        """
        Check that meta:generator is the original one.
        Check that spaces in meta.xml is processed correctly.
        """
        parastyles_odt = os.path.join(
            os.path.dirname(__file__), "examples", "parastyles.odt")
        d = load(parastyles_odt)
        meta = d.metaxml()
        self.assertEqual(-1, meta.find(u"""<meta:generator>OpenOffice.org/2.3$Linux OpenOffice.org_project/680m6$Build-9226"""),"Must use the original generator string")

    def test_metagenerator_odp(self):
        """ Check that meta:generator is the original one """
        parastyles_odt = os.path.join(
            os.path.dirname(__file__), u"examples", u"emb_spreadsheet.odp")
        d = load(parastyles_odt)
        meta = d.metaxml()
        self.assertNotEqual(-1, meta.find(u"""<meta:generator>ODFPY"""), "Must not use the original generator string")


    def test_simplelist(self):
        """ Check that lists are loaded correctly """
        simplelist_odt = os.path.join(
            os.path.dirname(__file__), "examples", "simplelist.odt")
        d = load(simplelist_odt)
        result = unicode(d.contentxml(),'utf-8')
        self.assertNotEqual(-1, result.find(u"""<text:list text:style-name="L1"><text:list-item><text:p text:style-name="P1">Item A</text:p></text:list-item><text:list-item>"""))


    def test_simpletable(self):
        """ Load a document containing tables """
        simpletable_odt = os.path.join(
            os.path.dirname(__file__), "examples", "simpletable.odt")
        d = load(simpletable_odt)
        result = unicode(d.contentxml(),'utf-8')
        e = ElementParser(result,'text:sequence-decl')
        self.assertTrue(e.has_value("text:name","Drawing")) # Last sequence
        self.assertTrue(e.has_value("text:display-outline-level","0"))

        e = ElementParser(result,'table:table-column')
        self.assertTrue(e.has_value("table:number-columns-repeated","2"))
        self.assertTrue(e.has_value("table:style-name","Tabel1.A"))

    def test_headerfooter(self):
        """ Test that styles referenced from master pages are renamed in OOo 2.x documents """
        simplelist_odt = os.path.join(
            os.path.dirname(__file__), "examples", "headerfooter.odt")
        d = load(simplelist_odt)
        result = d.stylesxml()
        self.assertNotEqual(-1, result.find(u'''style:name="MP1"'''))
        self.assertNotEqual(-1, result.find(u'''style:name="MP2"'''))
        self.assertNotEqual(-1, result.find(u"""<style:header><text:p text:style-name="MP1">Header<text:tab/>"""))
        self.assertNotEqual(-1, result.find(u"""<style:footer><text:p text:style-name="MP2">Footer<text:tab/>"""))

    def test_formulas_ooo(self):
        """ Check that formula prefixes are preserved """
        pythagoras_odt = os.path.join(
            os.path.dirname(__file__), "examples", "pythagoras.ods")
        d = load(pythagoras_odt)
        result = unicode(d.contentxml(),'utf-8')
        self.assertNotEqual(-1, result.find(u'''xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"'''))
        self.assertNotEqual(-1, result.find(u'''table:formula="of:=SQRT([.A1]*[.A1]+[.A2]*[.A2])"'''))
        self.assertNotEqual(-1, result.find(u'''table:formula="of:=SUM([.A1:.A2])"'''))

    def test_formulas_ooo(self):
        """ Check that formulas are understood when there are no prefixes"""
        pythagoras_odt = os.path.join(
            os.path.dirname(__file__), "examples", "pythagoras-kspread.ods")
        d = load(pythagoras_odt)
        result = unicode(d.contentxml(),'utf-8')
        self.assertNotEqual(-1, result.find(u'''table:formula="=SQRT([.A1]*[.A1]+[.A2]*[.A2])"'''))
        self.assertNotEqual(-1, result.find(u'''table:formula="=SUM([.A1]:[.A2])"'''))

    def test_externalent(self):
        """ Check that external entities are not loaded """
        simplelist_odt = os.path.join(
            os.path.dirname(__file__), "examples", "nasty.odt")
        self.assertRaises(EntitiesForbidden, load, simplelist_odt)

    def test_spreadsheet(self):
        """ Load a document containing subobjects """
        spreadsheet_odt = os.path.join(
            os.path.dirname(__file__), u"examples", u"emb_spreadsheet.odp")
        d = load(spreadsheet_odt)
        self.assertEqual(1, len(d.childobjects))
#       for s in d.childobjects:
#           print (s.folder)
#       mani = unicode(d.manifestxml(),'utf-8')
#       self.assertNotEqual(-1, mani.find(u''' manifest:full-path="Object 1/"'''), "Must contain the subobject")
#       self.assertNotEqual(-1, mani.find(u''' manifest:full-path="Object 1/settings.xml"'''), "Must contain the subobject settings.xml")

#        d.save("subobject.odp")

    def test_chinese(self):
        """ Load a document containing Chinese content"""
        chinese_spreadsheet = os.path.join(
            os.path.dirname(__file__), u"examples", u"chinese_spreadsheet.ods")
        d = load(chinese_spreadsheet)
        result = unicode(d.contentxml(),'utf-8')
        self.assertNotEqual(-1, result.find(u'''工作表1'''))

if __name__ == '__main__':
    unittest.main()