#1 vsftpd: Add to CI
Opened 5 years ago by ssahani. Modified 2 years ago
rpms/ ssahani/vsftpd tests  into  rawhide

vsftpd: Add to CI
Susant Sahani • 5 years ago  
@@ -0,0 +1,54 @@ 

+ #!/bin/bash

+ # SPDX-License-Identifier: LGPL-2.1+

+ # ~~~

+ #   runtest.sh of vsftpd

+ #   Description: vsftpd - Secure, fast FTP server for UNIX-like systems.

+ #

+ #   Author: Susant Sahani <susant@redhat.com>

+ #   Copyright (c) 2018 Red Hat, Inc.

+ # ~~~

+ 

+ # Include Beaker environment

+ . /usr/share/beakerlib/beakerlib.sh || exit 1

+ 

+ PACKAGE="vsftpd"

+ VSFTPD_CONFIG_FILE="/etc/vsftpd/vsftpd.conf"

+ VSFTPD_USER_LIST="/etc/vsftpd/user_list"

+ 

+ rlJournalStart

+     rlPhaseStartSetup

+         rlAssertRpm $PACKAGE

+         rlRun "systemctl stop firewalld" 0,5

+         rlRun "setenforce 0" 0,1

+ 

+         rlFileBackup "$VSFTPD_CONFIG_FILE"

+         rlFileBackup "$VSFTPD_USER_LIST"

+ 

+         rlRun "useradd fedora-ci"

+         rlRun "echo \"test\" | passwd --stdin fedora-ci"

+ 

+         rlRun "cp vsftpd-tests.py /usr/bin/"

+         rlRun "cp test_get test_list /home/fedora-ci"

+         rlRun "cp test_place /var/run/"

+         rlRun "systemctl restart vsftpd"

+       rlPhaseEnd

+ 

+     rlPhaseStartTest

+         rlLog "Starting vsftpd tests ..."

+         rlRun "/usr/bin/python3 /usr/bin/vsftpd-tests.py"

+     rlPhaseEnd

+ 

+     rlPhaseStartCleanup

+         rlRun "rm /usr/bin/vsftpd-tests.py"

+ 

+         rlRun "userdel fedora-ci"

+         rlRun "rm -rf /home/fedora-ci /var/run/test_get /var/run/test_place"

+ 

+         rlFileRestore

+         rlRun "setenforce 1" 0,1

+         rlLog "vsftpd tests done"

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

+ 

+ rlGetTestState

@@ -0,0 +1,1 @@ 

+ test

@@ -0,0 +1,1 @@ 

+ test

@@ -0,0 +1,1 @@ 

+ test

@@ -0,0 +1,21 @@ 

+ # vsftpd userlist

+ # If userlist_deny=NO, only allow users in this file

+ # If userlist_deny=YES (default), never allow users in this file, and

+ # do not even prompt for a password.

+ # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers

+ # for users that are denied.

+ root

+ bin

+ daemon

+ adm

+ lp

+ sync

+ shutdown

+ halt

+ mail

+ news

+ uucp

+ operator

+ games

+ nobody

+ fedora_ci

@@ -0,0 +1,98 @@ 

+ #!/usr/bin/env python3

+ # SPDX-License-Identifier: LGPL-2.1+

+ # ~~~

+ #   runtest.sh of /CoreOS/vsftpd/Sanity/vsftpd-tests.py

+ #   Description: Test basic vsftpd funcionality

+ #

+ #   Author: Susant Sahani <susant@redhat.com>

+ #   Copyright (c) 2018 Red Hat, Inc.

+ # ~~~

+ 

+ import errno

+ import os

+ import sys

+ import time

+ import unittest

+ import subprocess

+ import signal

+ import shutil

+ import ftplib

+ import socket

+ from ftplib import FTP

+ 

+ def setUpModule():

+ 

+     if shutil.which('vsftpd') is None:

+         raise OSError(errno.ENOENT, 'vsftpd not found')

+ 

+     os.chdir("/var/run")

+ 

+ class VsFTPdTests(unittest.TestCase):

+ 

+     def test_login(self):

+         ftp = FTP('localhost')

+         self.assertTrue(ftp.login(user='fedora-ci', passwd = 'test'))

+ 

+         ftp.quit()

+ 

+     def test_login_anonymous_fails(self):

+         ftp = FTP('localhost')

+ 

+         try:

+             ftp.login()

+             self.assertFalse(0)

+         except ftplib.all_errors:

+             self.assertTrue(1)

It seems to me this test will always pass.

+ 

+     def test_get_file(self):

+         filename = 'test_get'

+ 

+         ftp = FTP('localhost')

+         ftp.login(user='fedora-ci', passwd = 'test')

+ 

+         localfile = open(filename, 'wb')

+         ftp.retrbinary('RETR ' + filename, localfile.write, 1024)

+ 

+         ftp.quit()

+         localfile.close()

+ 

+         self.assertTrue(os.path.exists("/var/run/test_get"))

+ 

+     def test_place_file(self):

+         filename = 'test_place'

+ 

+         ftp = FTP('localhost')

+         ftp.login(user='fedora-ci', passwd = 'test')

+ 

+         ftp.storbinary('STOR '+ filename, open('/var/run/' + filename, 'rb'))

+         ftp.quit()

+ 

+         self.assertTrue(os.path.exists("/home/fedora-ci/test_place"))

+ 

+     def test_list_dir(self):

+         data = []

+ 

+         ftp = FTP('localhost')

+         ftp.login(user='fedora-ci', passwd = 'test')

+ 

+         ftp.dir(data.append)

+         ftp.quit()

+ 

+         line = 'test_list'

+         if line not in data:

+             self.assertFalse(0)

Again, assertFalse(0) is a true assertion. And why not use assertIn()?

+ 

+     def test_ipv6_port_open(self):

+ 

+         client = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)

+         r = client.connect(('::1', 21))

+ 

+         if r is None:

+             self.assertTrue(1)

+         else:

+             self.assertFalse(0)

Here as well.

+ 

+ 

+ if __name__ == '__main__':

+     unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout,

+                                                      verbosity=2))

@@ -0,0 +1,12 @@ 

+ anonymous_enable=NO

+ local_enable=YES

+ write_enable=YES

+ local_umask=022

+ dirmessage_enable=YES

+ xferlog_enable=YES

+ connect_from_port_20=YES

+ xferlog_std_format=YES

+ listen=NO

+ listen_ipv6=YES

+ pam_service_name=vsftpd

+ userlist_enable=YES

file added
+12
@@ -0,0 +1,12 @@ 

+ - hosts: localhost

+   roles:

+     - role: standard-test-beakerlib

+       tags:

+         - classic

+       tests:

+         - tests-sanity

+       required_packages:

+         - python3

+         - systemd

+         - iproute

+         - vsftpd

```

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Setup
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

vsftpd-3.0.3-28.fc28.x86_64
:: [ 21:03:58 ] :: [ PASS ] :: Checking for the presence of vsftpd rpm
:: [ 21:03:58 ] :: [ LOG ] :: Package versions:
:: [ 21:03:58 ] :: [ LOG ] :: vsftpd-3.0.3-28.fc28.x86_64
:: [ 21:03:58 ] :: [ BEGIN ] :: Running 'systemctl stop firewalld'
:: [ 21:03:58 ] :: [ PASS ] :: Command 'systemctl stop firewalld' (Expected 0,5, got 0)
:: [ 21:03:58 ] :: [ BEGIN ] :: Running 'setenforce 0'
:: [ 21:03:58 ] :: [ PASS ] :: Command 'setenforce 0' (Expected 0,1, got 0)
:: [ 21:03:58 ] :: [ INFO ] :: using '/var/tmp/beakerlib-WkeNe2h/backup' as backup destination
:: [ 21:03:58 ] :: [ INFO ] :: using '/var/tmp/beakerlib-WkeNe2h/backup' as backup destination
:: [ 21:03:58 ] :: [ BEGIN ] :: Running 'useradd fedora-ci'
Creating mailbox file: File exists
:: [ 21:03:59 ] :: [ PASS ] :: Command 'useradd fedora-ci' (Expected 0, got 0)
:: [ 21:03:59 ] :: [ BEGIN ] :: Running 'echo "test" | passwd --stdin fedora-ci'
Changing password for user fedora-ci.
passwd: all authentication tokens updated successfully.
:: [ 21:03:59 ] :: [ PASS ] :: Command 'echo "test" | passwd --stdin fedora-ci' (Expected 0, got 0)
:: [ 21:03:59 ] :: [ BEGIN ] :: Running 'cp vsftpd-tests.py /usr/bin/'
:: [ 21:03:59 ] :: [ PASS ] :: Command 'cp vsftpd-tests.py /usr/bin/' (Expected 0, got 0)
:: [ 21:03:59 ] :: [ BEGIN ] :: Running 'cp test_get test_list /home/fedora-ci'
:: [ 21:03:59 ] :: [ PASS ] :: Command 'cp test_get test_list /home/fedora-ci' (Expected 0, got 0)
:: [ 21:03:59 ] :: [ BEGIN ] :: Running 'cp test_place /var/run/'
:: [ 21:03:59 ] :: [ PASS ] :: Command 'cp test_place /var/run/' (Expected 0, got 0)
:: [ 21:03:59 ] :: [ BEGIN ] :: Running 'systemctl restart vsftpd'
:: [ 21:03:59 ] :: [ PASS ] :: Command 'systemctl restart vsftpd' (Expected 0, got 0)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Duration: 1s
:: Assertions: 9 good, 0 bad
:: RESULT: PASS

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Test
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 21:03:59 ] :: [ LOG ] :: Starting vsftpd tests ...
:: [ 21:03:59 ] :: [ BEGIN ] :: Running '/usr/bin/python3 /usr/bin/vsftpd-tests.py'
test_get_file (main.VsFTPdTests) ... ok
test_ipv6_port_open (main.VsFTPdTests) ... ok
test_list_dir (main.VsFTPdTests) ... ok
test_login (main.VsFTPdTests) ... ok
test_login_anonymous_fails (main.VsFTPdTests) ... ok
test_place_file (main.VsFTPdTests) ... ok


Ran 6 tests in 3.251s

OK
:: [ 21:04:02 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/vsftpd-tests.py' (Expected 0, got 0)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Duration: 3s
:: Assertions: 1 good, 0 bad
:: RESULT: PASS

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Cleanup
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 21:04:02 ] :: [ BEGIN ] :: Running 'rm /usr/bin/vsftpd-tests.py'
:: [ 21:04:02 ] :: [ PASS ] :: Command 'rm /usr/bin/vsftpd-tests.py' (Expected 0, got 0)
:: [ 21:04:02 ] :: [ BEGIN ] :: Running 'userdel fedora-ci'
:: [ 21:04:02 ] :: [ PASS ] :: Command 'userdel fedora-ci' (Expected 0, got 0)
:: [ 21:04:02 ] :: [ BEGIN ] :: Running 'rm -rf /home/fedora-ci /var/run/test_get /var/run/test_place'
:: [ 21:04:02 ] :: [ PASS ] :: Command 'rm -rf /home/fedora-ci /var/run/test_get /var/run/test_place' (Expected 0, got 0)
:: [ 21:04:02 ] :: [ BEGIN ] :: Running 'setenforce 1'
:: [ 21:04:02 ] :: [ PASS ] :: Command 'setenforce 1' (Expected 0,1, got 0)
:: [ 21:04:02 ] :: [ LOG ] :: vsftpd tests done
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Duration: 0s
:: Assertions: 4 good, 0 bad
:: RESULT: PASS

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: TEST PROTOCOL
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Package       : vsftpd
Installed     : vsftpd-3.0.3-28.fc28.x86_64
beakerlib RPM : beakerlib-1.17-13.fc28.noarch
Test started  : 2018-08-23 21:03:58 IST
Test finished : 2018-08-23 21:04:03 IST (still running)
Test duration : 5 seconds
Test name     : unknown
Distro        : Fedora release 28 (Twenty Eight)
Hostname      : Zeus
Architecture  : x86_64
CPUs          : 8 x Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
RAM size      : 31542 MB
HDD size      : 452.94 GB

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Setup
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 21:03:58 ] :: [ PASS ] :: Checking for the presence of vsftpd rpm
:: [ 21:03:58 ] :: [ LOG ] :: Package versions:
:: [ 21:03:58 ] :: [ LOG ] :: vsftpd-3.0.3-28.fc28.x86_64
:: [ 21:03:58 ] :: [ PASS ] :: Command 'systemctl stop firewalld' (Expected 0,5, got 0)
:: [ 21:03:58 ] :: [ PASS ] :: Command 'setenforce 0' (Expected 0,1, got 0)
:: [ 21:03:58 ] :: [ INFO ] :: using '/var/tmp/beakerlib-WkeNe2h/backup' as backup destination
:: [ 21:03:58 ] :: [ INFO ] :: using '/var/tmp/beakerlib-WkeNe2h/backup' as backup destination
:: [ 21:03:59 ] :: [ PASS ] :: Command 'useradd fedora-ci' (Expected 0, got 0)
:: [ 21:03:59 ] :: [ PASS ] :: Command 'echo "test" | passwd --stdin fedora-ci' (Expected 0, got 0)
:: [ 21:03:59 ] :: [ PASS ] :: Command 'cp vsftpd-tests.py /usr/bin/' (Expected 0, got 0)
:: [ 21:03:59 ] :: [ PASS ] :: Command 'cp test_get test_list /home/fedora-ci' (Expected 0, got 0)
:: [ 21:03:59 ] :: [ PASS ] :: Command 'cp test_place /var/run/' (Expected 0, got 0)
:: [ 21:03:59 ] :: [ PASS ] :: Command 'systemctl restart vsftpd' (Expected 0, got 0)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Duration: 1s
:: Assertions: 9 good, 0 bad
:: RESULT: PASS

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Test
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 21:03:59 ] :: [ LOG ] :: Starting vsftpd tests ...
:: [ 21:04:02 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/vsftpd-tests.py' (Expected 0, got 0)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Duration: 3s
:: Assertions: 1 good, 0 bad
:: RESULT: PASS

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Cleanup
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 21:04:02 ] :: [ PASS ] :: Command 'rm /usr/bin/vsftpd-tests.py' (Expected 0, got 0)
:: [ 21:04:02 ] :: [ PASS ] :: Command 'userdel fedora-ci' (Expected 0, got 0)
:: [ 21:04:02 ] :: [ PASS ] :: Command 'rm -rf /home/fedora-ci /var/run/test_get /var/run/test_place' (Expected 0, got 0)
:: [ 21:04:02 ] :: [ PASS ] :: Command 'setenforce 1' (Expected 0,1, got 0)
:: [ 21:04:02 ] :: [ LOG ] :: vsftpd tests done
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Duration: 0s
:: Assertions: 4 good, 0 bad
:: RESULT: PASS

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: unknown
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 21:04:03 ] :: [ LOG ] :: JOURNAL XML: /var/tmp/beakerlib-WkeNe2h/journal.xml
:: [ 21:04:03 ] :: [ LOG ] :: JOURNAL TXT: /var/tmp/beakerlib-WkeNe2h/journal.txt
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Duration: 5s
:: Phases: 3 good, 0 bad
:: OVERALL RESULT: PASS

``

It seems to me this test will always pass.

Again, assertFalse(0) is a true assertion. And why not use assertIn()?

Please fix the tests I commented on. Otherwise this looks good to me, thanks!

Currently it's not possible to have both STI and TMT tests [1]. We've decided to go with TMT tests in fedora tests repo. These are already configured to run upon new PR and build. @aegorenk you can close this PR.

  1. https://pagure.io/fedora-ci/general/issue/206
  2. https://src.fedoraproject.org/tests/vsftpd/tree/main