From f3e96380e576bfb698839b09fe5b5418560eecfa Mon Sep 17 00:00:00 2001 From: You-Sheng Yang Date: Thu, 27 Jan 2022 11:12:53 +0800 Subject: [PATCH] system-test: correct python re.MULTILINE usage Python re.M flag extends the matching rules for '^' and '$', but it doesn't mean '.*' will match across the newline char '\n'. For that, re.DOTALL should be used instead. And since the '*', '+', and '?' qualifiers are all greedy, and additional '?' should be appended to prevent it from matching across multiple matches. Signed-off-by: You-Sheng Yang --- system/t02_config/__init__.py | 2 +- system/t03_help/__init__.py | 4 ++-- system/t04_mirror/create.py | 20 +++++++++----------- system/t04_mirror/update.py | 2 +- system/t09_repo/include.py | 2 +- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/system/t02_config/__init__.py b/system/t02_config/__init__.py index 240e59446..2cbe79aba 100644 --- a/system/t02_config/__init__.py +++ b/system/t02_config/__init__.py @@ -46,7 +46,7 @@ class ConfigInFileTest(BaseTest): prepare = BaseTest.prepare_remove_all def outputMatchPrepare(_, s): - return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s, flags=re.MULTILINE) + return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s) class ConfigInMissingFileTest(BaseTest): diff --git a/system/t03_help/__init__.py b/system/t03_help/__init__.py index 07f1f8284..5b4da7694 100644 --- a/system/t03_help/__init__.py +++ b/system/t03_help/__init__.py @@ -14,7 +14,7 @@ class MainTest(BaseTest): runCmd = "aptly" def outputMatchPrepare(_, s): - return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s, flags=re.MULTILINE) + return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s) class MirrorTest(BaseTest): @@ -40,7 +40,7 @@ class MainHelpTest(BaseTest): runCmd = "aptly help" def outputMatchPrepare(_, s): - return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s, flags=re.MULTILINE) + return re.sub(r' -(cpuprofile|memprofile|memstats|meminterval)=.*\n', '', s) class MirrorHelpTest(BaseTest): diff --git a/system/t04_mirror/create.py b/system/t04_mirror/create.py index 88bad819c..90cfd8c82 100644 --- a/system/t04_mirror/create.py +++ b/system/t04_mirror/create.py @@ -116,7 +116,7 @@ class CreateMirror10Test(BaseTest): expectedCode = 1 def outputMatchPrepare(self, s): - return re.sub(r'Signature made .* using|gpgv: keyblock resource .*$|gpgv: Can\'t check signature: .*$', '', s, flags=re.MULTILINE) + return re.sub(r'Signature made .*? using|gpgv: keyblock resource .*?\n|gpgv: Can\'t check signature: .*?\n', '', s, flags=re.DOTALL) class CreateMirror11Test(BaseTest): @@ -127,7 +127,7 @@ class CreateMirror11Test(BaseTest): fixtureGpg = True def outputMatchPrepare(self, s): - return re.sub(r'Signature made .* using', '', s) + return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL) def check(self): self.check_output() @@ -143,7 +143,7 @@ class CreateMirror12Test(BaseTest): expectedCode = 1 def outputMatchPrepare(self, s): - return re.sub(r'Signature made .* using|gpgv: keyblock resource .*$|gpgv: Can\'t check signature: .*$', '', s, flags=re.MULTILINE) + return re.sub(r'Signature made .*? using|gpgv: keyblock resource .*?\n|gpgv: Can\'t check signature: .*?\n', '', s, flags=re.DOTALL) class CreateMirror13Test(BaseTest): @@ -166,7 +166,7 @@ class CreateMirror14Test(BaseTest): fixtureGpg = True def outputMatchPrepare(self, s): - return re.sub(r'Signature made .* using', '', s) + return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL) def check(self): def removeDates(s): @@ -218,7 +218,7 @@ class CreateMirror18Test(BaseTest): runCmd = "aptly mirror create -keyring=aptlytest.gpg mirror18 ppa:gladky-anton/gnuplot" def outputMatchPrepare(self, s): - return re.sub(r'Signature made .* using', '', s) + return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL) def check(self): self.check_output() @@ -234,7 +234,7 @@ class CreateMirror19Test(BaseTest): runCmd = "aptly -architectures='i386' mirror create -keyring=aptlytest.gpg -with-sources mirror19 http://security.debian.org/ stretch/updates main" def outputMatchPrepare(self, s): - return re.sub(r'Signature made .* using', '', s) + return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL) def check(self): def removeDates(s): @@ -276,7 +276,7 @@ class CreateMirror21Test(BaseTest): fixtureGpg = True def outputMatchPrepare(self, s): - return re.sub(r'Signature made .* using', '', s) + return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL) def check(self): def removeSHA512(s): @@ -321,7 +321,7 @@ class CreateMirror24Test(BaseTest): fixtureGpg = True def outputMatchPrepare(self, s): - return re.sub(r'Signature made .* using', '', s) + return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL) configOverride = { "gpgDisableVerify": True @@ -406,9 +406,7 @@ class CreateMirror32Test(BaseTest): requiresGPG2 = True def outputMatchPrepare(self, s): - return \ - re.sub(r'([A-F0-9]{8})[A-F0-9]{8}', r'\1', - re.sub(r'^gpgv: (Signature made .+|.+using RSA key.+)\n', '', s, flags=re.MULTILINE)) + return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL) def check(self): self.check_output() diff --git a/system/t04_mirror/update.py b/system/t04_mirror/update.py index 0c7458e1c..6677ea8e3 100644 --- a/system/t04_mirror/update.py +++ b/system/t04_mirror/update.py @@ -7,7 +7,7 @@ def filterOutSignature(_, s): - return re.sub(r'Signature made .* using', '', s) + return re.sub(r'Signature made .*? using', '', s, flags=re.DOTALL) def filterOutRedirects(_, s): diff --git a/system/t09_repo/include.py b/system/t09_repo/include.py index 2ae6b99a8..3f66b94d2 100644 --- a/system/t09_repo/include.py +++ b/system/t09_repo/include.py @@ -7,7 +7,7 @@ def gpgRemove(_, s): - return re.sub(r'Signature made .* using|gpgv: keyblock resource .*$|gpgv: Can\'t check signature: .*$', '', s, flags=re.MULTILINE) + return re.sub(r'Signature made .*? using|gpgv: keyblock resource .*?\n|gpgv: Can\'t check signature: .*?\n', '', s, flags=re.DOTALL) def changesRemove(_, s):