From c1c6112afcb2b62f8b2683af85cc11f4dd2e7b26 Mon Sep 17 00:00:00 2001 From: GreatBahram Date: Tue, 3 Aug 2021 09:19:08 +0430 Subject: [PATCH] Add 25 seconds wait time (at most) for clamd.ctl + Update EICAR signature name --- .github/workflows/tests.yml | 10 ++++++++++ src/tests/test_api.py | 11 ++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e8bd356..9627b6b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -42,5 +42,15 @@ jobs: sudo freshclam --verbose sudo systemctl restart clamav-daemon.service + - name: Wait for 25 seconds until clamd socket becomes available + run: | + secs=25 + while [[ $secs -gt 0 ]] && ! [[ -f "/var/run/clamav/clamd.ctl" ]]; + do + echo -ne "$secs\033[0K\r" + sleep 1 + : $((secs--)) + done + - name: Run unit tests run: pytest diff --git a/src/tests/test_api.py b/src/tests/test_api.py index 0c3b083..04049f5 100644 --- a/src/tests/test_api.py +++ b/src/tests/test_api.py @@ -11,6 +11,7 @@ mine = (stat.S_IREAD | stat.S_IWRITE) other = stat.S_IROTH execute = (stat.S_IEXEC | stat.S_IXOTH) +EICAR_SIG_NAME = "Win.Test.EICAR_HDB-1" @contextmanager @@ -42,7 +43,7 @@ def test_scan(self): f.write(clamd.EICAR) f.flush() os.fchmod(f.fileno(), (mine | other)) - expected = {f.name: ('FOUND', 'Eicar-Test-Signature')} + expected = {f.name: ('FOUND', EICAR_SIG_NAME)} assert self.cd.scan(f.name) == expected @@ -51,7 +52,7 @@ def test_unicode_scan(self): f.write(clamd.EICAR) f.flush() os.fchmod(f.fileno(), (mine | other)) - expected = {f.name: ('FOUND', 'Eicar-Test-Signature')} + expected = {f.name: ('FOUND', EICAR_SIG_NAME)} assert self.cd.scan(f.name) == expected @@ -62,13 +63,13 @@ def test_multiscan(self): with open(os.path.join(d, "file" + str(i)), 'wb') as f: f.write(clamd.EICAR) os.fchmod(f.fileno(), (mine | other)) - expected[f.name] = ('FOUND', 'Eicar-Test-Signature') + expected[f.name] = ('FOUND', EICAR_SIG_NAME) os.chmod(d, (mine | other | execute)) assert self.cd.multiscan(d) == expected def test_instream(self): - expected = {'stream': ('FOUND', 'Eicar-Test-Signature')} + expected = {'stream': ('FOUND', EICAR_SIG_NAME)} assert self.cd.instream(BytesIO(clamd.EICAR)) == expected def test_insteam_success(self): @@ -79,7 +80,7 @@ def test_fdscan(self): f.write(clamd.EICAR) f.flush() os.fchmod(f.fileno(), (mine | other)) - expected = {f.name: ('FOUND', 'Eicar-Test-Signature')} + expected = {f.name: ('FOUND', EICAR_SIG_NAME)} assert self.cd.fdscan(f.name) == expected