~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/archiveuploader/tests/nascentuploadfile.txt

  • Committer: Steve Kowalik
  • Date: 2011-08-07 04:05:52 UTC
  • mto: This revision was merged to the branch mainline in revision 13626.
  • Revision ID: stevenk@ubuntu.com-20110807040552-mwnxo0flmhvl35e8
Correct the notification based on review comments, and remove request{,ed}
from the function names, switching to create{,d}.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
NascentUploadFiles
2
 
==================
 
1
= NascentUploadFiles =
3
2
 
4
3
Files related with an Soyuz upload are modelled as:
5
4
 
14
13
 
15
14
Import the test keys so we have them ready for verification
16
15
 
17
 
    >>> from lp.testing.gpgkeys import import_public_test_keys
 
16
    >>> from canonical.launchpad.ftests import import_public_test_keys
18
17
    >>> import_public_test_keys()
19
18
 
20
19
We need to be logged into the security model in order to get any further
23
22
    >>> from lp.archiveuploader.tests import datadir, getPolicy
24
23
 
25
24
 
26
 
NascentUploadFile base class
27
 
----------------------------
 
25
== NascentUploadFile base class ==
28
26
 
29
27
(This base class has many checks in it that are not yet documented here.)
30
28
 
31
 
Forbidden character check
32
 
.........................
 
29
=== Forbidden character check ===
33
30
Some characters are forbidden in filenames as per Debian packaging policy, and
34
31
this check is performed by the checkNameIsTaintFree() method.  It raises an
35
32
UploadError if there is an invalid character found.
58
55
    >>> upload_file.checkNameIsTaintFree()
59
56
 
60
57
 
61
 
ChangesFile
62
 
-----------
 
58
== ChangesFile  ==
63
59
 
64
60
A changesfile contains manifest of what is included (ou should be
65
61
considered) for the upload in question.
163
159
    >>> os.unlink(copyp)
164
160
 
165
161
 
166
 
CustomUploadFile identification
167
 
...............................
 
162
=== CustomUploadFile identification ===
168
163
 
169
164
A custom upload is essentially a tarball, so it matches the is_source
170
165
regexp, even though it isn't actually a source file:
217
212
uploads.
218
213
 
219
214
 
220
 
ChangesFile Parsing Addresses
221
 
.............................
 
215
=== ChangesFile Parsing Addresses ===
222
216
 
223
217
Address parsing is implemented by the SignableTagFile class, which
224
218
is base for ChangesFile and DSCFile.
270
264
    >>> addr['person'].creation_comment
271
265
    u'when the some-source_6.6.6 package was uploaded to hoary/RELEASE'
272
266
 
273
 
If the email address is registered but not associated with a person it will be
274
 
associated with a new Person. This involves updating the email address,
275
 
something for which the uploader must have explicit permissions (bug 589073).
 
267
If the email address is registered but not associated with a person it will be 
 
268
associated with a new Person. This involves updating the email address, something 
 
269
for which the uploader must have explicit permissions (bug 589073).
276
270
 
277
271
    >>> sig_file.policy.create_people
278
272
    True
279
273
 
280
 
    >>> from lp.services.database.sqlbase import commit
281
 
    >>> from lp.services.identity.interfaces.account import IAccountSet
 
274
    >>> from canonical.database.sqlbase import commit
 
275
    >>> from canonical.launchpad.interfaces.account import IAccountSet
282
276
    >>> from lp.registry.interfaces.person import (
283
277
    ...      PersonCreationRationale, IPersonSet)
284
278
    >>> (acct, email) = getUtility(IAccountSet).createAccountAndEmail(
286
280
    ...          "fo", "secr1t")
287
281
    >>> person = getUtility(IPersonSet).createPersonWithoutEmail("fo",
288
282
    ...          rationale=PersonCreationRationale.UNKNOWN)
289
 
    >>> person.account = acct
 
283
        >>> person.account = acct
290
284
 
291
 
    Commit the changes so the emailaddress will have to be updated later
 
285
    Commit the changes so the emailaddress will have to be updated later 
292
286
    rather than inserted.
293
287
 
294
288
    >>> commit()
341
335
    <Person ...>
342
336
 
343
337
 
344
 
Signature Traces
345
 
................
 
338
=== Signature Traces ===
346
339
 
347
340
Changes file can be optionally GPG-signed, so ChangesFile has
348
341
infrastructure to record this information for later checks with policy
360
353
    u'1024D/5D147547'
361
354
 
362
355
 
363
 
DSCFile
364
 
-------
 
356
== DSCFile ==
365
357
 
366
358
DSCFile class models the operations and checks needed for processing
367
359
and storing a DSC file in the LP system.
438
430
 
439
431
    >>> errors = ed_broken_dsc.verify()
440
432
    >>> [str(err) for err in errors]
441
 
    ['File ed_0.2-20.dsc mentioned in the changes has a checksum mismatch.
442
 
    de8b206f8fc57bd931f6226feac6644a != e31eeb0b6b3b87e1ea79378df864ffff']
 
433
    ['File ed_0.2-20.dsc mentioned in the changes has a checksum mismatch. de8b206f8fc57bd931f6226feac6644a != e31eeb0b6b3b87e1ea79378df864ffff']
443
434
 
444
435
It also verifies the file size when the checksum matches.
445
436
 
451
442
 
452
443
    >>> errors = ed_broken_dsc.verify()
453
444
    >>> [str(err) for err in errors]
454
 
    ['File ed_0.2-20.dsc mentioned in the changes has a size mismatch.
455
 
    578 != 500']
456
 
 
457
 
 
458
 
Sub-DSC files or DSCUploadedFiles
459
 
.................................
 
445
    ['File ed_0.2-20.dsc mentioned in the changes has a size mismatch. 578 != 500']
 
446
 
 
447
 
 
448
=== Sub-DSC files or DSCUploadedFiles ===
460
449
 
461
450
Sub-DSCFiles are DSCUploadedFile objects.
462
451
 
478
467
    ...     modified_insecure_policy, DevNullLogger())
479
468
    >>> errors = ed_broken_dsc_file.verify()
480
469
    >>> [str(err) for err in errors]
481
 
    ['File ed_0.2-20.diff.gz mentioned in the changes has a checksum mismatch.
482
 
    8343836094fb01ee9b9a1067b23365f1 != f9e1e5f13725f581919e9bfd6227ffff']
483
 
 
484
 
 
485
 
DebBinaryUploadFile
486
 
-------------------
487
 
 
488
 
DebBinaryUploadFile models a binary .deb file.
489
 
 
490
 
    >>> from lp.archiveuploader.nascentuploadfile import (
491
 
    ...    DebBinaryUploadFile)
492
 
    >>> ed_deb_path = datadir('ed_0.2-20_i386.deb')
493
 
    >>> ed_binary_deb = DebBinaryUploadFile(
494
 
    ...     ed_deb_path, 'e31eeb0b6b3b87e1ea79378df864ffff', 15,
495
 
    ...     'main/editors', 'important', 'foo', '1.2', ed_binary_changes,
496
 
    ...     modified_insecure_policy, DevNullLogger())
 
470
    ['File ed_0.2-20.diff.gz mentioned in the changes has a checksum mismatch. 8343836094fb01ee9b9a1067b23365f1 != f9e1e5f13725f581919e9bfd6227ffff']
 
471
 
 
472
 
 
473
=== Sub-DSC file lookup ===
 
474
 
 
475
 
 
476
== SourceUploadFile ==
 
477
 
 
478
 
 
479
== DebBinaryUploadFile ==
 
480
 
 
481
DebBinaryUploadFile models a binary .deb file. 
 
482
 
 
483
   >>> from lp.archiveuploader.nascentuploadfile import (
 
484
   ...    DebBinaryUploadFile)
 
485
   >>> ed_deb_path = datadir('ed_0.2-20_i386.deb')
 
486
   >>> ed_binary_deb = DebBinaryUploadFile(ed_deb_path,
 
487
   ...                     'e31eeb0b6b3b87e1ea79378df864ffff',
 
488
   ...                     15, 'main/editors', 'important', 'foo', '1.2',
 
489
   ...                     ed_binary_changes, modified_insecure_policy,
 
490
   ...                     DevNullLogger())
497
491
 
498
492
Like the other files it can be verified:
499
493
 
500
 
    >>> list(ed_binary_deb.verify())
501
 
    []
 
494
   >>> list(ed_binary_deb.verify())
 
495
   []
502
496
 
503
497
Verification checks that the specified section matches the section in the
504
498
changes file:
505
499
 
506
 
    >>> ed_binary_deb = DebBinaryUploadFile(
507
 
    ...     ed_deb_path, 'e31eeb0b6b3b87e1ea79378df864ffff', 15, 'main/net',
508
 
    ...     'important', 'foo', '1.2', ed_binary_changes,
509
 
    ...     modified_insecure_policy, DevNullLogger())
510
 
    >>> list(ed_binary_deb.verify())
511
 
    [UploadError('ed_0.2-20_i386.deb
512
 
    control file lists section as main/editors but changes file has
513
 
    main/net.',)]
 
500
   >>> ed_binary_deb = DebBinaryUploadFile(ed_deb_path,
 
501
   ...                     'e31eeb0b6b3b87e1ea79378df864ffff',
 
502
   ...                     15, 'main/net', 'important', 'foo', '1.2',
 
503
   ...                     ed_binary_changes, modified_insecure_policy,
 
504
   ...                     DevNullLogger())
 
505
   >>> list(ed_binary_deb.verify())
 
506
   [UploadError('ed_0.2-20_i386.deb control file lists section as 
 
507
                main/editors but changes file has main/net.',)]
514
508
 
515
509
It also checks the priority against the changes file:
516
510
 
517
 
    >>> ed_binary_deb = DebBinaryUploadFile(
518
 
    ...     ed_deb_path, 'e31eeb0b6b3b87e1ea79378df864ffff', 15,
519
 
    ...     'main/editors', 'extra', 'foo', '1.2', ed_binary_changes,
520
 
    ...     modified_insecure_policy, DevNullLogger())
521
 
    >>> list(ed_binary_deb.verify())
522
 
    [UploadError('ed_0.2-20_i386.deb
523
 
    control file lists priority as important but changes file has extra.',)]
524
 
 
525
 
The timestamp of the files in the .deb are tested against the policy for
526
 
being too new:
527
 
 
528
 
    >>> from lp.archiveuploader.uploadpolicy import ArchiveUploadType
529
 
    >>> old_only_policy = getPolicy(
530
 
    ...     name='insecure', distro='ubuntu', distroseries='hoary')
531
 
    >>> old_only_policy.accepted_type = ArchiveUploadType.BINARY_ONLY
532
 
    >>> old_only_policy.future_time_grace = -5 * 365 * 24 * 60 * 60
533
 
 
534
 
    >>> ed_binary_deb = DebBinaryUploadFile(
535
 
    ...     ed_deb_path, 'e31eeb0b6b3b87e1ea79378df864ffff', 15,
536
 
    ...     'main/editors', 'important', 'foo', '1.2', ed_binary_changes,
537
 
    ...     old_only_policy, DevNullLogger())
538
 
    >>> list(ed_binary_deb.verifyDebTimestamp())
539
 
    [UploadError('ed_0.2-20_i386.deb:
540
 
    has 26 file(s) with a time stamp too far into the future
541
 
    (e.g. control [Thu Jan  3 19:29:01 2008]).',)]
 
511
   >>> ed_binary_deb = DebBinaryUploadFile(ed_deb_path,
 
512
   ...                     'e31eeb0b6b3b87e1ea79378df864ffff',
 
513
   ...                     15, 'main/editors', 'extra', 'foo', '1.2',
 
514
   ...                     ed_binary_changes, modified_insecure_policy,
 
515
   ...                     DevNullLogger())
 
516
   >>> list(ed_binary_deb.verify())
 
517
   [UploadError('ed_0.2-20_i386.deb control file lists priority as important 
 
518
                 but changes file has extra.',)]
 
519
 
 
520
The timestamp of the files in the .deb are tested against the policy for being 
 
521
too new:
 
522
 
 
523
   >>> from lp.archiveuploader.uploadpolicy import ArchiveUploadType
 
524
   >>> old_only_policy = getPolicy(
 
525
   ...     name='insecure', distro='ubuntu', distroseries='hoary')
 
526
   >>> old_only_policy.accepted_type = ArchiveUploadType.BINARY_ONLY
 
527
   >>> old_only_policy.future_time_grace = -5 * 365 * 24 * 60 * 60
 
528
 
 
529
   >>> ed_binary_deb = DebBinaryUploadFile(ed_deb_path,
 
530
   ...                     'e31eeb0b6b3b87e1ea79378df864ffff',
 
531
   ...                     15, 'main/editors', 'important', 'foo', '1.2',
 
532
   ...                     ed_binary_changes, old_only_policy,
 
533
   ...                     DevNullLogger())
 
534
   >>> list(ed_binary_deb.verifyDebTimestamp())
 
535
   [UploadError('ed_0.2-20_i386.deb: has 26 file(s) with a time stamp too 
 
536
        far into the future (e.g. control [Thu Jan  3 19:29:01 2008]).',)]
542
537
 
543
538
... as well as for being too old:
544
539
 
545
 
    >>> new_only_policy = getPolicy(
546
 
    ...     name='insecure', distro='ubuntu', distroseries='hoary')
547
 
    >>> new_only_policy.accepted_type = ArchiveUploadType.BINARY_ONLY
548
 
    >>> new_only_policy.earliest_year = 2010
549
 
    >>> ed_binary_deb = DebBinaryUploadFile(
550
 
    ...     ed_deb_path, 'e31eeb0b6b3b87e1ea79378df864ffff', 15,
551
 
    ...     'main/editors', 'important', 'foo', '1.2', ed_binary_changes,
552
 
    ...     new_only_policy, DevNullLogger())
553
 
    >>> list(ed_binary_deb.verify())
554
 
    [UploadError('ed_0.2-20_i386.deb:
555
 
    has 26 file(s) with a time stamp too far in the past
556
 
    (e.g. control [Thu Jan  3 19:29:01 2008]).',)]
 
540
   >>> new_only_policy = getPolicy(
 
541
   ...     name='insecure', distro='ubuntu', distroseries='hoary')
 
542
   >>> new_only_policy.accepted_type = ArchiveUploadType.BINARY_ONLY
 
543
   >>> new_only_policy.earliest_year = 2010
 
544
   >>> ed_binary_deb = DebBinaryUploadFile(ed_deb_path,
 
545
   ...                     'e31eeb0b6b3b87e1ea79378df864ffff',
 
546
   ...                     15, 'main/editors', 'important', 'foo', '1.2',
 
547
   ...                     ed_binary_changes, new_only_policy,
 
548
   ...                     DevNullLogger())
 
549
   >>> list(ed_binary_deb.verify())
 
550
   [UploadError('ed_0.2-20_i386.deb: has 26 file(s) with a time stamp too
 
551
                 far in the past (e.g. control [Thu Jan  3 19:29:01 2008]).',)]
 
552
 
 
553
 
 
554
== UDebBinaryUploadFile ==
 
555
 
 
556
 
 
557
== CustomUploadFile ==
 
558
 
 
559