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
b3f6ef3c
Commit
b3f6ef3c
authored
Oct 02, 2019
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slaprunner: test for web services
parent
e98e8e2f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
0 deletions
+77
-0
software/slaprunner/test/setup.py
software/slaprunner/test/setup.py
+1
-0
software/slaprunner/test/test.py
software/slaprunner/test/test.py
+76
-0
No files found.
software/slaprunner/test/setup.py
View file @
b3f6ef3c
...
@@ -49,6 +49,7 @@ setup(name=name,
...
@@ -49,6 +49,7 @@ setup(name=name,
'psutil'
,
'psutil'
,
'paramiko'
,
'paramiko'
,
'six'
,
'six'
,
'requests'
,
],
],
zip_safe
=
True
,
zip_safe
=
True
,
test_suite
=
'test'
,
test_suite
=
'test'
,
...
...
software/slaprunner/test/test.py
View file @
b3f6ef3c
...
@@ -26,14 +26,18 @@
...
@@ -26,14 +26,18 @@
##############################################################################
##############################################################################
import
os
import
os
import
unittest
import
paramiko
import
paramiko
import
contextlib
import
contextlib
import
base64
import
base64
import
hashlib
import
hashlib
import
subprocess
import
subprocess
from
six.moves.urllib.parse
import
urlparse
from
six.moves.urllib.parse
import
urlparse
from
six.moves.urllib.parse
import
quote
from
six.moves.urllib.parse
import
quote
from
six.moves.urllib.parse
import
urljoin
from
six.moves.configparser
import
ConfigParser
from
six.moves.configparser
import
ConfigParser
import
requests
from
slapos.recipe.librecipe
import
generateHashFromFiles
from
slapos.recipe.librecipe
import
generateHashFromFiles
from
slapos.testing.testcase
import
makeModuleSetUpAndTestCaseClass
from
slapos.testing.testcase
import
makeModuleSetUpAndTestCaseClass
...
@@ -48,6 +52,78 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
...
@@ -48,6 +52,78 @@ class SlaprunnerTestCase(SlapOSInstanceTestCase):
__partition_reference__
=
's'
__partition_reference__
=
's'
class
TestWeb
(
SlaprunnerTestCase
):
def
test_slaprunner
(
self
):
# slaprunner main interface is password protected
parameter_dict
=
self
.
computer_partition
.
getConnectionParameterDict
()
url
=
parameter_dict
[
'url'
]
resp
=
requests
.
get
(
url
,
verify
=
False
)
self
.
assertEqual
(
requests
.
codes
.
unauthorized
,
resp
.
status_code
)
resp
=
requests
.
get
(
url
,
verify
=
False
,
auth
=
(
parameter_dict
[
'init-user'
],
parameter_dict
[
'init-password'
]))
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
self
.
assertIn
(
'SlapOS'
,
resp
.
text
)
def
test_shellinabox
(
self
):
# shellinabox exists at /shellinabox and is password protected
parameter_dict
=
self
.
computer_partition
.
getConnectionParameterDict
()
url
=
urljoin
(
parameter_dict
[
'url'
],
'/shellinabox'
)
resp
=
requests
.
get
(
url
,
verify
=
False
)
self
.
assertEqual
(
requests
.
codes
.
unauthorized
,
resp
.
status_code
)
resp
=
requests
.
get
(
url
,
verify
=
False
,
auth
=
(
parameter_dict
[
'init-user'
],
parameter_dict
[
'init-password'
]))
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
self
.
assertIn
(
'ShellInABox'
,
resp
.
text
)
self
.
assertNotIn
(
'SlapOS'
,
resp
.
text
)
def
test_public_url
(
self
):
# ~/srv/runner/public/ is served over http
parameter_dict
=
self
.
computer_partition
.
getConnectionParameterDict
()
public_url
=
parameter_dict
[
'public-url'
]
hello_file
=
os
.
path
.
join
(
self
.
computer_partition_root_path
,
'srv'
,
'runner'
,
'public'
,
'hello.html'
)
self
.
addCleanup
(
os
.
remove
,
hello_file
)
with
open
(
hello_file
,
'w'
)
as
f
:
f
.
write
(
'<b>Hello</b>'
)
index
=
requests
.
get
(
public_url
,
verify
=
False
)
self
.
assertEqual
(
requests
.
codes
.
ok
,
index
.
status_code
)
self
.
assertIn
(
'hello.html'
,
index
.
text
)
hello
=
requests
.
get
(
urljoin
(
public_url
,
'hello.html'
),
verify
=
False
)
self
.
assertEqual
(
requests
.
codes
.
ok
,
hello
.
status_code
)
self
.
assertIn
(
'<b>Hello</b>'
,
hello
.
text
)
# git seems broken, these are 404 now...
@
unittest
.
expectedFailure
def
test_git_private
(
self
):
parameter_dict
=
self
.
computer_partition
.
getConnectionParameterDict
()
url
=
parameter_dict
[
'git-private'
]
resp
=
requests
.
get
(
url
,
verify
=
False
)
self
.
assertEqual
(
requests
.
codes
.
unauthorized
,
resp
.
status_code
)
resp
=
requests
.
get
(
url
,
verify
=
False
,
auth
=
(
parameter_dict
[
'init-user'
],
parameter_dict
[
'init-password'
]))
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
@
unittest
.
expectedFailure
def
test_git_public
(
self
):
parameter_dict
=
self
.
computer_partition
.
getConnectionParameterDict
()
url
=
parameter_dict
[
'git-public'
]
resp
=
requests
.
get
(
url
,
verify
=
False
)
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
class
TestSSH
(
SlaprunnerTestCase
):
class
TestSSH
(
SlaprunnerTestCase
):
@
classmethod
@
classmethod
def
getInstanceParameterDict
(
cls
):
def
getInstanceParameterDict
(
cls
):
...
...
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