Skip to content

Commit 673c3c0

Browse files
committed
test(dput): add system test for PUT /api/files/:dir/:file via dput
1 parent 24f63c6 commit 673c3c0

4 files changed

Lines changed: 84 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
- name: "Install Test Packages"
5858
run: |
5959
sudo apt-get update
60-
sudo apt-get install -y --no-install-recommends graphviz gnupg2 gpgv2 git gcc make devscripts python3 python3-requests-unixsocket python3-termcolor python3-swiftclient python3-boto python3-azure-storage python3-etcd3 python3-plyvel flake8 faketime
60+
sudo apt-get install -y --no-install-recommends graphviz gnupg2 gpgv2 git gcc make devscripts python3 python3-requests-unixsocket python3-termcolor python3-swiftclient python3-boto python3-azure-storage python3-etcd3 python3-plyvel flake8 faketime dput-ng
6161
6262
- name: "Checkout Repository"
6363
uses: actions/checkout@v4

docker/test.Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM aptly-dev
22

3+
RUN apt-get update -y && apt-get install -y --no-install-recommends dput-ng && \
4+
apt-get clean && rm -rf /var/lib/apt/lists/*
5+
36
ADD --chown=aptly:aptly . /work/src/
47

58
# Pre-populate the Go module cache so go mod verify works offline

system/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends curl gnupg b
77
binutils-arm-linux-gnueabihf bash-completion zip ruby-dev lintian npm \
88
libc6-dev-i386-cross libc6-dev-armhf-cross libc6-dev-arm64-cross \
99
gcc-i686-linux-gnu gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu \
10-
faketime && \
10+
faketime dput-ng && \
1111
apt-get clean && rm -rf /var/lib/apt/lists/*
1212

1313
RUN useradd -m --shell /bin/bash --home-dir /var/lib/aptly aptly

system/t12_api/files.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
import inspect
2+
import os
3+
import shutil
4+
import tempfile
5+
16
from api_lib import APITest
7+
from lib import BaseTest
28

39

410
class FilesAPITestUpload(APITest):
@@ -97,3 +103,76 @@ def check(self):
97103
self.check_equal(self.delete("/api/files/../.").status_code, 404)
98104
self.check_equal(self.delete("/api/files/./..").status_code, 404)
99105
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

Comments
 (0)