Merge ~xypron/ppa-dev-tools:urldecode into ppa-dev-tools:main

Proposed by Heinrich Schuchardt
Status: Needs review
Proposed branch: ~xypron/ppa-dev-tools:urldecode
Merge into: ppa-dev-tools:main
Diff against target: 73 lines (+20/-10)
2 files modified
ppa/job.py (+7/-6)
tests/test_job.py (+13/-4)
Reviewer Review Type Date Requested Status
Bryce Harrington Approve
Review via email: mp+458522@code.launchpad.net

This proposal supersedes a proposal from 2024-01-11.

Commit message

Job.request_url: urlencode parameter strings

Triggering autopkgtests for a package with a version number like 8.2313.0-2ubuntu1+ppa1 fail due to missing urlencoding (LP: #2049105).

Update the corresponding test.

To post a comment you must log in.
Revision history for this message
Bryce Harrington (bryce) wrote : Posted in a previous version of this proposal

Hi Heinrich,

Big thanks for proposing a fix along with the bug. Yes, this looks like a very good way to solve the problem and I agree with your approach.

Can you also include a unit test case along with this fix? It should fail without your fix applied, and pass with it (usual TDD stuff).

Thanks again for implementing the fix!

review: Needs Information
Revision history for this message
Bryce Harrington (bryce) wrote :

Thanks for adding the thorough set of tests! I marked them as xfail in the first commit to make pytest happy, and have pushed to main:

Enumerating objects: 15, done.
Counting objects: 100% (15/15), done.
Delta compression using up to 12 threads
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 1.57 KiB | 1.57 MiB/s, done.
Total 10 (delta 8), reused 0 (delta 0), pack-reused 0
To git+ssh://git.launchpad.net/ppa-dev-tools
   55e2df3..8a46dc9 main -> main

review: Approve

Unmerged commits

9f4b2da... by Heinrich Schuchardt

Job.request_url: urlencode parameter strings

Triggering autopkgtests for a package with a version number like
8.2313.0-2ubuntu1+ppa1 fail due to missing urlencoding.
(LP: #2049105)

Signed-off-by: Heinrich Schuchardt <email address hidden>

6da4220... by Heinrich Schuchardt

test_request_url: provide more test cases

Parameterize test_request_url() and provide more test cases.
Expect parameters in a URL to be URL encoded.

Signed-off-by: Heinrich Schuchardt <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/ppa/job.py b/ppa/job.py
2index 669fe48..ec675e0 100755
3--- a/ppa/job.py
4+++ b/ppa/job.py
5@@ -14,6 +14,7 @@
6 import json
7 from functools import lru_cache
8 from typing import Iterator
9+import urllib
10
11 from .constants import URL_AUTOPKGTEST
12
13@@ -82,13 +83,13 @@ class Job:
14 :rtype: str
15 :returns: Full URL for invoking the test.
16 """
17- rel_str = f"release={self.series}"
18- arch_str = f"&arch={self.arch}"
19- pkg_str = f"&package={self.source_package}"
20- trigger_str = ''
21+ parameter_str = urllib.parse.urlencode({
22+ 'release' : self.series,
23+ 'arch' : self.arch,
24+ 'package' : self.source_package})
25 for trigger in self.triggers:
26- trigger_str += f"&trigger={trigger}"
27- return f"{URL_AUTOPKGTEST}/request.cgi?{rel_str}{arch_str}{pkg_str}{trigger_str}"
28+ parameter_str += "&" + urllib.parse.urlencode({"trigger" : trigger})
29+ return f"{URL_AUTOPKGTEST}/request.cgi?{parameter_str}"
30
31
32 def get_running(response, releases=None, ppa=None) -> Iterator[Job]:
33diff --git a/tests/test_job.py b/tests/test_job.py
34index 852e04e..b33d299 100644
35--- a/tests/test_job.py
36+++ b/tests/test_job.py
37@@ -14,6 +14,7 @@ import os
38 import sys
39
40 import json
41+import pytest
42
43 sys.path.insert(0, os.path.realpath(
44 os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")))
45@@ -89,16 +90,24 @@ def test_ppas():
46 job = Job(0, '', '', '', '', ppas=['ppa:a/b', 'ppa:c/d'])
47 assert job.ppas == ['ppa:a/b', 'ppa:c/d']
48
49-
50-def test_request_url():
51+@pytest.mark.parametrize('triggers, endswith', [
52+ ( ['t/1'], '?release=c&arch=d&package=b&trigger=t%2F1' ),
53+ ( ['t/2.3'], '?release=c&arch=d&package=b&trigger=t%2F2.3' ),
54+ ( ['t/2.3-1'], '?release=c&arch=d&package=b&trigger=t%2F2.3-1' ),
55+ ( ['t/2.3-1ubuntu2'], '?release=c&arch=d&package=b&trigger=t%2F2.3-1ubuntu2' ),
56+ ( ['t/2.3-1ubuntu2~ppa1'], '?release=c&arch=d&package=b&trigger=t%2F2.3-1ubuntu2~ppa1' ),
57+ ( ['t/2.3-1ubuntu2+ppa2'], '?release=c&arch=d&package=b&trigger=t%2F2.3-1ubuntu2%2Bppa2' ),
58+ ( ['t/1', 'u/2'], '?release=c&arch=d&package=b&trigger=t%2F1&trigger=u%2F2' ),
59+ ])
60+def test_request_url(triggers, endswith):
61 """Checks Job object textual presentation."""
62 jobinfo = {
63- 'triggers': ['t/1'],
64+ 'triggers': triggers,
65 'ppas': ['ppa:a/b', 'ppa:c/d']
66 }
67 job = Job(0, 'a', 'b', 'c', 'd', jobinfo['triggers'], jobinfo['ppas'])
68 assert job.request_url.startswith("https://autopkgtest.ubuntu.com/request.cgi")
69- assert job.request_url.endswith("?release=c&arch=d&package=b&trigger=t/1")
70+ assert job.request_url.endswith(endswith)
71
72
73 def test_get_running():

Subscribers

People subscribed via source and target branches