Merge ~cjwatson/launchpad:fix-bpb-librarian-auth-condition into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: ccbf3a5a1fc9690170a319d3b63978c2abb38d21
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:fix-bpb-librarian-auth-condition
Merge into: launchpad:master
Diff against target: 93 lines (+49/-4)
3 files modified
lib/lp/soyuz/model/binarypackagebuildbehaviour.py (+1/-1)
lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py (+43/-2)
lib/lp/testing/factory.py (+5/-1)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+430310@code.launchpad.net

Commit message

Fix the condition for dispatching tokens for private source files

Description of the change

If a librarian request has a token, then the librarian will only serve restricted files. In the case of source package release files, this isn't quite synonymous with files in private archives: source files in private archives may be unrestricted if the same source package is also published in a public archive. Only dispatch tokens for source files that are actually restricted.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/soyuz/model/binarypackagebuildbehaviour.py b/lib/lp/soyuz/model/binarypackagebuildbehaviour.py
2index 15f374d..3878a0f 100644
3--- a/lib/lp/soyuz/model/binarypackagebuildbehaviour.py
4+++ b/lib/lp/soyuz/model/binarypackagebuildbehaviour.py
5@@ -76,7 +76,7 @@ class BinaryPackageBuildBehaviour(BuildFarmJobBehaviourBase):
6 "sha1": lfa.content.sha1,
7 "url": lfa.getURL(),
8 }
9- if self.build.archive.private:
10+ if lfa.restricted:
11 if macaroon_raw is None:
12 macaroon_raw = yield self.issueMacaroon()
13 filemap[lfa.filename].update(
14diff --git a/lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py b/lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py
15index 8f4d199..4d6ca14 100644
16--- a/lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py
17+++ b/lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py
18@@ -141,7 +141,7 @@ class TestBinaryBuildPackageBehaviour(StatsMixin, TestCaseWithFactory):
19
20 uploads = [(chroot.http_url, "", "")]
21 for sprf in files:
22- if build.archive.private:
23+ if sprf.libraryfile.restricted:
24 password = MacaroonVerifies(
25 "binary-package-build", build.archive
26 )
27@@ -323,7 +323,48 @@ class TestBinaryBuildPackageBehaviour(StatsMixin, TestCaseWithFactory):
28 )
29
30 @defer.inlineCallbacks
31- def test_private_source_dispatch(self):
32+ def test_private_source_file_dispatch(self):
33+ self.useFixture(InProcessAuthServerFixture())
34+ self.pushConfig(
35+ "launchpad", internal_macaroon_secret_key="some-secret"
36+ )
37+ archive = self.factory.makeArchive(private=True)
38+ worker = OkWorker()
39+ builder = self.factory.makeBuilder()
40+ builder.setCleanStatus(BuilderCleanStatus.CLEAN)
41+ vitals = extract_vitals_from_db(builder)
42+ build = self.factory.makeBinaryPackageBuild(
43+ builder=builder, archive=archive
44+ )
45+ build.source_package_release.addFile(
46+ self.factory.makeLibraryFileAlias(restricted=True, db_only=True),
47+ filetype=SourcePackageFileType.ORIG_TARBALL,
48+ )
49+ lf = self.factory.makeLibraryFileAlias(db_only=True)
50+ build.distro_arch_series.addOrUpdateChroot(lf)
51+ bq = build.queueBuild()
52+ bq.markAsBuilding(builder)
53+ interactor = BuilderInteractor()
54+ behaviour = interactor.getBuildBehaviour(bq, builder, worker)
55+ yield interactor._startBuild(
56+ bq, vitals, builder, worker, behaviour, BufferLogger()
57+ )
58+ yield self.assertExpectedInteraction(
59+ worker.call_log,
60+ builder,
61+ build,
62+ behaviour,
63+ lf,
64+ archive,
65+ ArchivePurpose.PPA,
66+ )
67+
68+ @defer.inlineCallbacks
69+ def test_public_source_file_in_private_archive_dispatch(self):
70+ # A source file in a private archive might be unrestricted if the
71+ # same source package is also published in a public archive. The
72+ # librarian will only serve restricted files if given a token, so
73+ # make sure that we don't send a token for unrestricted files.
74 self.useFixture(InProcessAuthServerFixture())
75 self.pushConfig(
76 "launchpad", internal_macaroon_secret_key="some-secret"
77diff --git a/lib/lp/testing/factory.py b/lib/lp/testing/factory.py
78index 3ebd99c..96bef5a 100644
79--- a/lib/lp/testing/factory.py
80+++ b/lib/lp/testing/factory.py
81@@ -3255,7 +3255,11 @@ class LaunchpadObjectFactory(ObjectFactory):
82 md5=hashlib.md5(content).hexdigest(),
83 )
84 lfa = LibraryFileAlias(
85- content=lfc, filename=filename, mimetype=content_type
86+ content=lfc,
87+ filename=filename,
88+ mimetype=content_type,
89+ expires=expires,
90+ restricted=restricted,
91 )
92 else:
93 lfa = getUtility(ILibraryFileAliasSet).create(

Subscribers

People subscribed via source and target branches

to status/vote changes: