-
-
Notifications
You must be signed in to change notification settings - Fork 142
Tests for containers #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
spiderxm
wants to merge
3
commits into
OWASP:development
Choose a base branch
from
spiderxm:tests-for-containers
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Tests for containers #363
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
addopts = --ignore=tests/test_module_killing.py --ignore=tests/test_module_shutting.py | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import os | ||
import sys | ||
import unittest | ||
import subprocess | ||
import signal | ||
from os.path import dirname, abspath | ||
from time import time | ||
|
||
from core.messages import load_messages | ||
|
||
messages = load_messages().message_contents | ||
|
||
|
||
def run_container_in_sub_process(command, kill_container_command): | ||
is_network_traffic_capture_started = False | ||
parent_directory = str(dirname(dirname(abspath(__file__)))) | ||
output = str() | ||
expected_result = False | ||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=False, | ||
cwd=parent_directory) | ||
start_time = time() | ||
for c in iter(lambda: process.stdout.read(1), b""): | ||
if time() - start_time > 300: | ||
os.kill(process.pid, signal.SIGINT) | ||
break | ||
sys.stdout.buffer.write(c) | ||
output += c.decode("utf-8") | ||
if messages["network_traffic_capture_start"] in output and is_network_traffic_capture_started is False: | ||
is_network_traffic_capture_started = True | ||
os.system(kill_container_command) | ||
elif is_network_traffic_capture_started is True and "finished." in output: | ||
expected_result = True | ||
break | ||
assert True is expected_result | ||
|
||
|
||
class TestModules(unittest.TestCase): | ||
|
||
def test_module_ftp_weak_password(self): | ||
kill_container_command = "docker kill ohp_ftpserver_weak_password" | ||
command = ["python3", "ohp.py", "-m", "ftp/weak_password"] | ||
run_container_in_sub_process(command, kill_container_command) | ||
|
||
def test_module_ftp_strong_password(self): | ||
kill_container_command = "docker kill ohp_ftpserver_strong_password" | ||
command = ["python3", "ohp.py", "-m", "ftp/strong_password"] | ||
run_container_in_sub_process(command, kill_container_command) | ||
|
||
def test_module_http_basic_auth_strong_password(self): | ||
kill_container_command = "docker kill ohp_httpserver_basic_auth_strong_password" | ||
command = ["python3", "ohp.py", "-m", "http/basic_auth_strong_password"] | ||
run_container_in_sub_process(command, kill_container_command) | ||
|
||
def test_module_http_basic_auth_weak_password(self): | ||
kill_container_command = "docker kill ohp_httpserver_basic_auth_weak_password" | ||
command = ["python3", "ohp.py", "-m", "http/basic_auth_weak_password"] | ||
run_container_in_sub_process(command, kill_container_command) | ||
|
||
def test_module_http_ics_veeder_root_guardian_ast(self): | ||
kill_container_command = "docker kill ohp_icsserver_veeder_root_guardian_ast" | ||
command = ["python3", "ohp.py", "-m", "ics/veeder_root_guardian_ast"] | ||
run_container_in_sub_process(command, kill_container_command) | ||
|
||
def test_module_smtp_strong_password(self): | ||
kill_container_command = "docker kill ohp_smtpserver_strong_password" | ||
command = ["python3", "ohp.py", "-m", "smtp/strong_password"] | ||
run_container_in_sub_process(command, kill_container_command) | ||
|
||
def test_module_ssh_weak_password(self): | ||
kill_container_command = "docker kill ohp_sshserver_weak_password" | ||
command = ["python3", "ohp.py", "-m", "ssh/weak_password"] | ||
run_container_in_sub_process(command, kill_container_command) | ||
|
||
def test_module_ssh_strong_password(self): | ||
kill_container_command = "docker kill ohp_sshserver_strong_password" | ||
command = ["python3", "ohp.py", "-m", "ssh/strong_password"] | ||
run_container_in_sub_process(command, kill_container_command) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import os | ||
import sys | ||
import unittest | ||
import subprocess | ||
import signal | ||
from os.path import dirname, abspath | ||
from time import time | ||
|
||
from core.messages import load_messages | ||
|
||
messages = load_messages().message_contents | ||
|
||
|
||
def run_container_in_sub_process(command): | ||
is_network_traffic_capture_started = False | ||
parent_directory = str(dirname(dirname(abspath(__file__)))) | ||
output = str() | ||
expected_result = False | ||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=False, | ||
cwd=parent_directory) | ||
start_time = time() | ||
for c in iter(lambda: process.stdout.read(1), b""): | ||
if time() - start_time > 300: | ||
os.kill(process.pid, signal.SIGINT) | ||
break | ||
sys.stdout.buffer.write(c) | ||
output += c.decode("utf-8") | ||
if messages["network_traffic_capture_start"] in output and is_network_traffic_capture_started is False: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for variables lets use = operator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for output we cant use |
||
is_network_traffic_capture_started = True | ||
os.kill(process.pid, signal.SIGINT) | ||
elif is_network_traffic_capture_started is True and "finished." in output: | ||
spiderxm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expected_result = True | ||
break | ||
assert True is expected_result | ||
|
||
|
||
class TestModules(unittest.TestCase): | ||
|
||
def test_module_ftp_weak_password(self): | ||
command = ["python3", "ohp.py", "-m", "ftp/weak_password"] | ||
run_container_in_sub_process(command) | ||
|
||
def test_module_ftp_strong_password(self): | ||
command = ["python3", "ohp.py", "-m", "ftp/strong_password"] | ||
run_container_in_sub_process(command) | ||
|
||
def test_module_http_basic_auth_strong_password(self): | ||
command = ["python3", "ohp.py", "-m", "http/basic_auth_strong_password"] | ||
run_container_in_sub_process(command) | ||
|
||
def test_module_http_basic_auth_weak_password(self): | ||
command = ["python3", "ohp.py", "-m", "http/basic_auth_weak_password"] | ||
run_container_in_sub_process(command) | ||
|
||
def test_module_http_ics_veeder_root_guardian_ast(self): | ||
command = ["python3", "ohp.py", "-m", "ics/veeder_root_guardian_ast"] | ||
run_container_in_sub_process(command) | ||
|
||
def test_module_smtp_strong_password(self): | ||
command = ["python3", "ohp.py", "-m", "smtp/strong_password"] | ||
run_container_in_sub_process(command) | ||
|
||
def test_module_ssh_weak_password(self): | ||
command = ["python3", "ohp.py", "-m", "ssh/weak_password"] | ||
run_container_in_sub_process(command) | ||
|
||
def test_module_ssh_strong_password(self): | ||
command = ["python3", "ohp.py", "-m", "ssh/strong_password"] | ||
run_container_in_sub_process(command) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.