Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
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
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos
Commits
e0118fd0
Commit
e0118fd0
authored
Apr 12, 2018
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
1cafb98e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
19 deletions
+30
-19
software/proftpd/test/test.py
software/proftpd/test/test.py
+26
-15
software/proftpd/test/utils.py
software/proftpd/test/utils.py
+4
-4
No files found.
software/proftpd/test/test.py
View file @
e0118fd0
...
...
@@ -30,8 +30,11 @@ import shutil
import
urlparse
import
tempfile
import
StringIO
import
subprocess
import
pysftp
from
paramiko.ssh_exception
import
SSHException
from
paramiko.ssh_exception
import
AuthenticationException
import
utils
...
...
@@ -67,7 +70,7 @@ class ProFTPdTestCase(utils.SlapOSInstanceTestCase):
hostname
or
sftp_url
.
hostname
,
port
=
sftp_url
.
port
,
cnopts
=
cnopts
,
username
=
username
or
parameter_dict
[
'user
'
],
# XXX
username
=
username
or
parameter_dict
[
'user
name'
],
password
=
password
or
parameter_dict
[
'password'
])
...
...
@@ -76,10 +79,8 @@ class TestSFTPListen(ProFTPdTestCase):
self
.
assertTrue
(
self
.
_getConnection
(
hostname
=
self
.
config
[
'ipv4_address'
]))
def
test_does_not_listen_on_all_ip
(
self
):
from
paramiko.ssh_exception
import
SSHException
import
pdb
;
pdb
.
set_trace
()
with
self
.
assertRaises
(
SSHException
):
self
.
_getConnection
(
hostname
=
'
127.0.0.1
'
)
self
.
_getConnection
(
hostname
=
'
0.0.0.0
'
)
class
TestSFTPOperations
(
ProFTPdTestCase
):
...
...
@@ -108,7 +109,10 @@ class TestSFTPOperations(ProFTPdTestCase):
# it's visible in listdir()
self
.
assertEqual
([
'testfile'
],
sftp
.
listdir
())
# download it, it should have same content
# and also in the server filesystem
self
.
assertEqual
([
'testfile'
],
os
.
listdir
(
self
.
upload_dir
))
# download the file again, it should have same content
tempdir
=
tempfile
.
mkdtemp
()
self
.
addCleanup
(
lambda
:
shutil
.
rmtree
(
tempdir
))
local_file
=
os
.
path
.
join
(
tempdir
,
'testfile'
)
...
...
@@ -133,31 +137,40 @@ class TestSFTPOperations(ProFTPdTestCase):
self
.
assertEqual
([
'destination'
],
os
.
listdir
(
self
.
upload_dir
))
def
test_partial_upload_are_deleted
(
self
):
test_self
=
self
with
self
.
_getConnection
()
as
sftp
:
class
ErrorFile
(
StringIO
.
StringIO
):
def
read
(
self
,
*
args
):
raise
IOError
(
"Something bad happened"
)
with
self
.
_getConnection
()
as
sftp
:
# at this point, file is already created on server
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"
with
self
.
assertRaises
(
IOError
):
sftp
.
sftp_client
.
putfo
(
ErrorFile
(),
"destination"
)
# no half uploaded file is kept
self
.
assertEqual
([],
os
.
listdir
(
self
.
upload_dir
))
class
TestUserManagement
(
ProFTPdTestCase
):
def
test_user_can_be_added_from_script
(
self
):
raise
NotImplementedError
()
with
self
.
assertRaisesRegexp
(
AuthenticationException
,
'Authentication failed'
):
self
.
_getConnection
(
username
=
'bob'
,
password
=
'secret'
)
subprocess
.
check_call
(
'echo secret | %s/bin/ftpasswd --name=bob --stdin'
%
self
.
computer_partition_root_path
,
shell
=
True
)
self
.
assertTrue
(
self
.
_getConnection
(
username
=
'bob'
,
password
=
'secret'
))
class
TestBan
(
ProFTPdTestCase
):
def
test_client_are_banned_after_5_wrong_passwords
(
self
):
# Simulate failed 5 login attempts
from
paramiko.ssh_exception
import
AuthenticationException
for
i
in
range
(
5
):
with
self
.
assertRaisesRegexp
(
AuthenticationException
,
'Authentication failed'
):
self
.
_getConnection
(
password
=
'wrong'
)
# after that, even with a valid password we cannot connect
from
paramiko.ssh_exception
import
SSHException
with
self
.
assertRaisesRegexp
(
SSHException
,
'Connection reset by peer'
):
self
.
_getConnection
()
...
...
@@ -173,9 +186,7 @@ class TestInstanceParameterPort(ProFTPdTestCase):
@
classmethod
def
getInstanceParmeterDict
(
cls
):
cls
.
free_port
=
utils
.
findFreeTCPPort
(
cls
.
config
[
'ipv4_address'
])
import
json
import
pdb
;
pdb
.
set_trace
()
return
{
'port'
:
cls
.
free_port
,
'_'
:
json
.
dumps
({
'port'
:
cls
.
free_port
})}
return
{
'port'
:
cls
.
free_port
}
def
test_instance_parameter_port
(
self
):
parameter_dict
=
self
.
computer_partition
.
getConnectionParameterDict
()
...
...
software/proftpd/test/utils.py
View file @
e0118fd0
...
...
@@ -87,7 +87,9 @@ class SlapOSInstanceTestCase(unittest.TestCase):
}
# TODO: read from environment / guess ipv4 from buildout file
ipv4_address
=
'127.0.0.1'
# note that by default we don't use 127.0.0.1, because some tests want to
# check that we don't mess with 127.0.0.1
ipv4_address
=
'127.0.1.1'
config
[
'proxy_host'
]
=
config
[
'ipv4_address'
]
=
ipv4_address
config
[
'ipv6_address'
]
=
'2001:67c:1254:26::3318'
config
[
'proxy_port'
]
=
findFreeTCPPort
(
ipv4_address
)
...
...
@@ -124,7 +126,7 @@ class SlapOSInstanceTestCase(unittest.TestCase):
cluster_configuration
=
instance_parameter_dict
,
environment
=
os
.
environ
)
# TODO: log more details in this case
assert
softwar
e_status_dict
[
'status_code'
]
==
0
assert
instanc
e_status_dict
[
'status_code'
]
==
0
# FIXME: similar to test node, only one (root) partition is really supported for now.
computer_partition_list
=
[]
...
...
@@ -136,8 +138,6 @@ class SlapOSInstanceTestCase(unittest.TestCase):
partition_reference
=
'testing partition {i}'
.
format
(
i
=
i
,
**
config
),
partition_parameter_kw
=
instance_parameter_dict
))
if
instance_parameter_dict
:
import
pdb
;
pdb
.
set_trace
()
# expose some class attributes so that tests can use them:
# the ComputerPartition instances, to getInstanceParmeterDict
cls
.
computer_partition
=
computer_partition_list
[
0
]
...
...
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