Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ekaterina
slapos
Commits
7c0a8377
Commit
7c0a8377
authored
Feb 06, 2020
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
software/proftpd/test: support python3
parent
a7ec7c12
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
26 deletions
+43
-26
software/proftpd/test/setup.py
software/proftpd/test/setup.py
+1
-0
software/proftpd/test/test.py
software/proftpd/test/test.py
+41
-25
software/slapos-sr-testing/software.cfg
software/slapos-sr-testing/software.cfg
+1
-1
No files found.
software/proftpd/test/setup.py
View file @
7c0a8377
...
...
@@ -48,6 +48,7 @@ setup(
'pysftp'
,
'supervisor'
,
'psutil'
,
'six'
,
],
zip_safe
=
True
,
test_suite
=
'test'
,
...
...
software/proftpd/test/test.py
View file @
7c0a8377
...
...
@@ -25,12 +25,14 @@
#
##############################################################################
from
__future__
import
unicode_literals
import
os
import
shutil
import
urlparse
import
six.moves.urllib.parse
as
urlparse
import
tempfile
import
StringIO
import
io
import
subprocess
import
six
import
pysftp
import
psutil
...
...
@@ -95,7 +97,7 @@ class TestSFTPOperations(ProFTPdTestCase):
def
test_simple_sftp_session
(
self
):
with
self
.
_getConnection
()
as
sftp
:
# put a file
with
tempfile
.
NamedTemporaryFile
()
as
f
:
with
tempfile
.
NamedTemporaryFile
(
mode
=
"w"
)
as
f
:
f
.
write
(
"Hello FTP !"
)
f
.
flush
()
sftp
.
put
(
f
.
name
,
remotepath
=
'testfile'
)
...
...
@@ -117,14 +119,14 @@ class TestSFTPOperations(ProFTPdTestCase):
def
test_uploaded_file_not_visible_until_fully_uploaded
(
self
):
test_self
=
self
class
PartialFile
(
StringIO
.
StringIO
):
class
PartialFile
(
io
.
StringIO
):
def
read
(
self
,
*
args
):
# file is not visible yet
test_self
.
assertNotIn
(
'destination'
,
os
.
listdir
(
test_self
.
upload_dir
))
# it's just a hidden file
test_self
.
assertEqual
(
[
'.in.destination.'
],
os
.
listdir
(
test_self
.
upload_dir
))
return
StringIO
.
StringIO
.
read
(
self
,
*
args
)
test_self
.
assertEqual
(
[
'.in.destination.'
],
os
.
listdir
(
test_self
.
upload_dir
))
return
io
.
StringIO
.
read
(
self
,
*
args
)
with
self
.
_getConnection
()
as
sftp
:
sftp
.
sftp_client
.
putfo
(
PartialFile
(
"content"
),
"destination"
)
...
...
@@ -136,11 +138,11 @@ class TestSFTPOperations(ProFTPdTestCase):
test_self
=
self
with
self
.
_getConnection
()
as
sftp
:
class
ErrorFile
(
StringIO
.
StringIO
):
class
ErrorFile
(
io
.
StringIO
):
def
read
(
self
,
*
args
):
# at this point, file is already created on server
test_self
.
assertEqual
(
[
'.in.destination.'
],
os
.
listdir
(
test_self
.
upload_dir
))
test_self
.
assertEqual
(
[
'.in.destination.'
],
os
.
listdir
(
test_self
.
upload_dir
))
# simulate a connection closed
sftp
.
sftp_client
.
close
()
return
"something that will not be sent to server"
...
...
@@ -152,18 +154,21 @@ class TestSFTPOperations(ProFTPdTestCase):
def
test_user_cannot_escape_home
(
self
):
with
self
.
_getConnection
()
as
sftp
:
with
s
elf
.
assertRaisesRegexp
(
IOError
,
'Permission denied'
):
with
s
ix
.
assertRaisesRegex
(
self
,
IOError
,
'Permission denied'
):
sftp
.
listdir
(
'..'
)
with
s
elf
.
assertRaisesRegexp
(
IOError
,
'Permission denied'
):
with
s
ix
.
assertRaisesRegex
(
self
,
IOError
,
'Permission denied'
):
sftp
.
listdir
(
'/'
)
with
s
elf
.
assertRaisesRegexp
(
IOError
,
'Permission denied'
):
with
s
ix
.
assertRaisesRegex
(
self
,
IOError
,
'Permission denied'
):
sftp
.
listdir
(
'/tmp/'
)
class
TestUserManagement
(
ProFTPdTestCase
):
def
test_user_can_be_added_from_script
(
self
):
with
self
.
assertRaisesRegexp
(
AuthenticationException
,
'Authentication failed'
):
with
six
.
assertRaisesRegex
(
self
,
AuthenticationException
,
'Authentication failed'
,
):
self
.
_getConnection
(
username
=
'bob'
,
password
=
'secret'
)
subprocess
.
check_call
(
...
...
@@ -176,23 +181,34 @@ class TestUserManagement(ProFTPdTestCase):
class
TestBan
(
ProFTPdTestCase
):
def
test_client_are_banned_after_5_wrong_passwords
(
self
):
# Simulate failed 5 login attempts
for
i
in
range
(
5
):
with
self
.
assertRaisesRegexp
(
AuthenticationException
,
'Authentication failed'
):
for
_
in
range
(
5
):
with
six
.
assertRaisesRegex
(
self
,
AuthenticationException
,
'Authentication failed'
,
):
self
.
_getConnection
(
password
=
'wrong'
)
# after that, even with a valid password we cannot connect
with
self
.
assertRaisesRegexp
(
SSHException
,
'Connection reset by peer'
):
with
six
.
assertRaisesRegex
(
self
,
SSHException
,
'Connection reset by peer'
,
):
self
.
_getConnection
()
# ban event is logged
with
open
(
os
.
path
.
join
(
self
.
computer_partition_root_path
,
with
open
(
os
.
path
.
join
(
self
.
computer_partition_root_path
,
'var'
,
'log'
,
'proftpd-ban.log'
))
as
ban_log_file
:
self
.
assertRegexpMatches
(
'proftpd-ban.log'
,
))
as
ban_log_file
:
six
.
assertRegex
(
self
,
ban_log_file
.
readlines
()[
-
1
],
'login from host .* denied due to host ban'
)
'login from host .* denied due to host ban'
,
)
class
TestInstanceParameterPort
(
ProFTPdTestCase
):
...
...
software/slapos-sr-testing/software.cfg
View file @
7c0a8377
...
...
@@ -223,6 +223,7 @@ context =
tests =
${slapos.test.kvm-setup:setup}
${slapos.test.slaprunner-setup:setup}
${slapos.test.proftpd-setup:setup}
${:extra}
extra =
${slapos.cookbook-setup:setup}
...
...
@@ -233,7 +234,6 @@ extra =
${slapos.test.slapos-master-setup:setup}
${slapos.test.plantuml-setup:setup}
${slapos.test.powerdns-setup:setup}
${slapos.test.proftpd-setup:setup}
${slapos.test.re6stnet-setup:setup}
${slapos.test.seleniumserver-setup:setup}
${slapos.test.helloworld-setup:setup}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment