|
| 1 | +import inspect |
| 2 | +import os |
| 3 | +import shutil |
| 4 | +import tempfile |
| 5 | + |
1 | 6 | from api_lib import APITest |
| 7 | +from lib import BaseTest |
2 | 8 |
|
3 | 9 |
|
4 | 10 | class FilesAPITestUpload(APITest): |
@@ -97,3 +103,76 @@ def check(self): |
97 | 103 | self.check_equal(self.delete("/api/files/../.").status_code, 404) |
98 | 104 | self.check_equal(self.delete("/api/files/./..").status_code, 404) |
99 | 105 | self.check_equal(self.delete("/api/files/dir/..").status_code, 404) |
| 106 | + |
| 107 | + |
| 108 | +class FilesAPITestDputUpload(APITest): |
| 109 | + """ |
| 110 | + PUT /api/files/:dir/:file via dput, then POST /api/repos/:name/include/:dir |
| 111 | +
|
| 112 | + Uses the real dput binary to upload a .changes file and all its referenced |
| 113 | + files to the aptly API, then imports them into a local repo via include. |
| 114 | + Skipped if dput is not installed. |
| 115 | + """ |
| 116 | + |
| 117 | + def fixture_available(self): |
| 118 | + return super().fixture_available() and shutil.which("dput") is not None |
| 119 | + |
| 120 | + def check(self): |
| 121 | + d = self.random_name() |
| 122 | + repo_name = self.random_name() |
| 123 | + |
| 124 | + # Create target repo |
| 125 | + self.check_equal( |
| 126 | + self.post("/api/repos", json={"Name": repo_name}).status_code, 201) |
| 127 | + |
| 128 | + changes_dir = os.path.join( |
| 129 | + os.path.dirname(inspect.getsourcefile(BaseTest)), "changes") |
| 130 | + changes_file = os.path.join(changes_dir, "hardlink_0.2.1_amd64.changes") |
| 131 | + |
| 132 | + # dput strips leading/trailing slashes from 'incoming' then prepends /, |
| 133 | + # producing: PUT http://{fqdn}/api/files/{d}/{filename} |
| 134 | + # fqdn includes host:port so dput connects directly to the test API server. |
| 135 | + dput_cf = ( |
| 136 | + "[aptly]\n" |
| 137 | + f"fqdn = {self.base_url}\n" |
| 138 | + "method = http\n" |
| 139 | + f"incoming = api/files/{d}\n" |
| 140 | + "login = *\n" |
| 141 | + "allow_unsigned_uploads = 1\n" |
| 142 | + "allow_dcut = 0\n" |
| 143 | + ) |
| 144 | + |
| 145 | + tmpdir = tempfile.mkdtemp() |
| 146 | + try: |
| 147 | + dput_cf_path = os.path.join(tmpdir, "dput.cf") |
| 148 | + with open(dput_cf_path, "w") as f: |
| 149 | + f.write(dput_cf) |
| 150 | + |
| 151 | + # dput -U: allow unsigned uploads (skip local GPG check) |
| 152 | + # dput reads the .changes and PUTs every file listed in Files: + the .changes itself |
| 153 | + self.run_cmd(["dput", "-c", dput_cf_path, "-U", "aptly", changes_file]) |
| 154 | + finally: |
| 155 | + shutil.rmtree(tmpdir) |
| 156 | + |
| 157 | + # All files referenced in the .changes must now be present in the upload dir |
| 158 | + self.check_exists(f"upload/{d}/hardlink_0.2.1_amd64.changes") |
| 159 | + self.check_exists(f"upload/{d}/hardlink_0.2.1.dsc") |
| 160 | + self.check_exists(f"upload/{d}/hardlink_0.2.1.tar.gz") |
| 161 | + self.check_exists(f"upload/{d}/hardlink_0.2.1_amd64.deb") |
| 162 | + |
| 163 | + # Import via the .changes file into the repo |
| 164 | + resp = self.post_task( |
| 165 | + f"/api/repos/{repo_name}/include/{d}", |
| 166 | + params={"ignoreSignature": 1}) |
| 167 | + self.check_task(resp) |
| 168 | + |
| 169 | + output = self.get(f"/api/tasks/{resp.json()['ID']}/output") |
| 170 | + self.check_in(b"Added: hardlink_0.2.1_source added, hardlink_0.2.1_amd64 added", output.content) |
| 171 | + |
| 172 | + # Packages must be in the repo |
| 173 | + self.check_equal( |
| 174 | + sorted(self.get(f"/api/repos/{repo_name}/packages").json()), |
| 175 | + ["Pamd64 hardlink 0.2.1 daf8fcecbf8210ad", "Psource hardlink 0.2.1 8f72df429d7166e5"]) |
| 176 | + |
| 177 | + # include cleans up the upload dir |
| 178 | + self.check_not_exists(f"upload/{d}") |
0 commit comments