-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/e2e with karton services + other test fixes (#572)
Co-authored-by: Paweł Srokosz <[email protected]>
- Loading branch information
Showing
7 changed files
with
298 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -11,12 +11,23 @@ services: | |
- redis | ||
image: certpl/mwdb | ||
restart: on-failure | ||
env_file: | ||
# NOTE: use gen_vars.sh in order to generate this file | ||
- mwdb-vars.env | ||
environment: | ||
MWDB_ENABLE_KARTON: 1 | ||
MWDB_REDIS_URI: redis://redis/ | ||
MWDB_POSTGRES_URI: postgresql://mwdb:e2e-postgres-password@postgres/mwdb | ||
# Hardcoded secret key for consistent JWT testing | ||
- MWDB_SECRET_KEY=e2e-testing-key | ||
MWDB_SECRET_KEY: e2e-testing-key | ||
MWDB_ADMIN_LOGIN: admin | ||
MWDB_ADMIN_EMAIL: admin@localhost | ||
MWDB_ADMIN_PASSWORD: e2e-mwdb-admin-password | ||
MWDB_BASE_URL: http://127.0.0.1 | ||
MWDB_ENABLE_RATE_LIMIT: 0 | ||
MWDB_ENABLE_REGISTRATION: 1 | ||
UWSGI_PROCESSES: 4 | ||
MWDB_MAIL_SMTP: "mailhog:1025" | ||
MWDB_MAIL_FROM: "[email protected]" | ||
volumes: | ||
- "./dev/karton.ini:/etc/karton/karton.ini" | ||
mwdb-web: | ||
depends_on: | ||
- mwdb | ||
|
@@ -30,23 +41,100 @@ services: | |
postgres: | ||
image: postgres | ||
restart: always | ||
env_file: | ||
# NOTE: use gen_vars.sh in order to generate this file | ||
- postgres-vars.env | ||
environment: | ||
POSTGRES_USER: mwdb | ||
POSTGRES_DB: mwdb | ||
POSTGRES_PASSWORD: e2e-postgres-password | ||
mwdb-tests: | ||
build: tests/backend | ||
depends_on: | ||
- mwdb | ||
- mwdb-web | ||
- mailhog | ||
- karton-system | ||
- karton-classifier | ||
- karton-dashboard | ||
- karton-mwdb-reporter | ||
image: certpl/mwdb-tests | ||
env_file: | ||
- mwdb-vars.env | ||
environment: | ||
MWDB_ADMIN_LOGIN: admin | ||
MWDB_ADMIN_PASSWORD: e2e-mwdb-admin-password | ||
MWDB_URL: http://mwdb-web./api | ||
web-tests: | ||
build: tests/frontend | ||
depends_on: | ||
- mwdb | ||
- mwdb-web | ||
- mailhog | ||
- karton-system | ||
- karton-classifier | ||
- karton-dashboard | ||
- karton-mwdb-reporter | ||
image: certpl/mwdb-web-tests | ||
env_file: | ||
- mwdb-vars.env | ||
environment: | ||
MWDB_ADMIN_LOGIN: admin | ||
MWDB_ADMIN_PASSWORD: e2e-mwdb-admin-password | ||
redis: | ||
image: redis:alpine | ||
minio: | ||
image: minio/minio | ||
command: server /data | ||
volumes: | ||
- /tmp/minio:/data | ||
ports: | ||
- "127.0.0.1:9000:9000" | ||
environment: | ||
- MINIO_ACCESS_KEY=mwdb-test-access | ||
- MINIO_SECRET_KEY=mwdb-test-key | ||
mailhog: | ||
image: mailhog/mailhog:latest | ||
ports: | ||
- "127.0.0.1:8025:8025" | ||
karton-system: | ||
image: certpl/karton-system:79ffabd3607406f1cc494b024b44f4dd1a753095 | ||
depends_on: | ||
- redis | ||
- minio | ||
volumes: | ||
- "./dev/karton.ini:/etc/karton/karton.ini" | ||
entrypoint: karton-system | ||
command: --setup-bucket | ||
environment: | ||
KARTON_MWDB_API_URL: http://mwdb-web.:80/api/ | ||
KARTON_MWDB_USERNAME: admin | ||
KARTON_MWDB_PASSWORD: e2e-mwdb-admin-password | ||
karton-classifier: | ||
image: certpl/karton-classifier:8f02c6e5188414f28d37515d903ce2b6955bc768 | ||
depends_on: | ||
- redis | ||
- minio | ||
volumes: | ||
- "./dev/karton.ini:/etc/karton/karton.ini" | ||
environment: | ||
KARTON_MWDB_API_URL: http://mwdb-web.:80/api/ | ||
KARTON_MWDB_USERNAME: admin | ||
KARTON_MWDB_PASSWORD: e2e-mwdb-admin-password | ||
karton-dashboard: | ||
image: certpl/karton-dashboard:7b8ec871c4902cc7236eaa4782d9f7acdbc8809c | ||
depends_on: | ||
- redis | ||
- minio | ||
volumes: | ||
- "./dev/karton.ini:/etc/karton/karton.ini" | ||
ports: | ||
- "127.0.0.1:8030:5000" | ||
environment: | ||
KARTON_MWDB_API_URL: http://mwdb-web.:80/api/ | ||
KARTON_MWDB_USERNAME: admin | ||
KARTON_MWDB_PASSWORD: e2e-mwdb-admin-password | ||
karton-mwdb-reporter: | ||
image: certpl/karton-mwdb-reporter:6f935f6dfbf459e278a496586b581b4ba0d4cbad | ||
depends_on: | ||
- redis | ||
- minio | ||
volumes: | ||
- "./dev/karton.ini:/etc/karton/karton.ini" | ||
environment: | ||
KARTON_MWDB_API_URL: http://mwdb-web.:80/api/ | ||
KARTON_MWDB_USERNAME: admin | ||
KARTON_MWDB_PASSWORD: e2e-mwdb-admin-password |
This file contains 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
FROM python:3.6 | ||
ENV MWDB_URL http://mwdb.:8080/api | ||
COPY requirements.txt /app/requirements.txt | ||
RUN pip3 install -r /app/requirements.txt | ||
COPY *.py /app/ | ||
WORKDIR /app | ||
CMD ["pytest", "-v"] | ||
CMD ["pytest", "-v", "--reruns", "3", "--only-rerun", "ConnectionError"] |
This file contains 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
python-dateutil==2.7.0 | ||
pyJWT==2.3.0 | ||
pytest | ||
pytest-rerunfailures | ||
requests | ||
python-baseconv |
This file contains 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 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,162 @@ | ||
from .utils import random_name, rand_string, ShouldRaise | ||
|
||
|
||
def test_karton_analyses_after_adding_blob(admin_session): | ||
test = admin_session | ||
blob_name = rand_string(15) | ||
blob = test.add_blob(None, blobname=blob_name, blobtype="inject", content=""" | ||
Binary junk: \x00\x01\x02\x03\x04\x05\x07 | ||
HELLO WORLD! | ||
========""" + random_name()) | ||
blob_dhash = blob["id"] | ||
analyses = test.get_analyses(blob_dhash)["analyses"] | ||
assert len(analyses) == 1 | ||
|
||
|
||
def test_karton_analysis_after_adding_config(admin_session): | ||
test = admin_session | ||
blob_name = rand_string(15) | ||
content = rand_string(15) | ||
config_json = { | ||
"cnc": [1, 2, 3], | ||
"raw_cfg": { | ||
"in-blob": { | ||
"blob_name": blob_name, | ||
"blob_type": "Blob type", | ||
"content": content | ||
} | ||
} | ||
} | ||
config = test.add_config(None, "malwarex", config_json) | ||
config_dhash = config["id"] | ||
analyses = test.get_analyses(config_dhash)["analyses"] | ||
assert len(analyses) == 1 | ||
|
||
|
||
def test_karton_analysis_after_adding_sample(admin_session): | ||
test = admin_session | ||
file_name = rand_string(15) | ||
file_content = rand_string() | ||
sample = test.add_sample(file_name, file_content) | ||
sample_dhash = sample["id"] | ||
analyses = test.get_analyses(sample_dhash)["analyses"] | ||
assert len(analyses) == 1 | ||
|
||
|
||
def test_karton_reanalyze_object_with_args(admin_session): | ||
test = admin_session | ||
blob_name = rand_string(15) | ||
argument_key = rand_string(5) | ||
argument_value = rand_string(5) | ||
blob = test.add_blob(None, blobname=blob_name, blobtype="inject", content=""" | ||
Binary junk: \x00\x01\x02\x03\x04\x05\x07 | ||
HELLO WORLD! | ||
========""" + random_name()) | ||
blob_dhash = blob["id"] | ||
new_analysis = test.reanalyze_object(blob_dhash, arguments={argument_key: argument_value}) | ||
analyses = test.get_analyses(blob_dhash)["analyses"] | ||
assert new_analysis["arguments"] == {argument_key: argument_value} | ||
assert len(analyses) == 2 | ||
|
||
incorrect_object_dhash = "abcdefghi" | ||
with ShouldRaise(status_code=404): | ||
test.reanalyze_object(incorrect_object_dhash) | ||
|
||
|
||
def test_karton_reanalyze_object_without_args(admin_session): | ||
test = admin_session | ||
file_name = rand_string(15) | ||
file_content = rand_string() | ||
sample = test.add_sample(file_name, file_content) | ||
sample_dhash = sample["id"] | ||
test.reanalyze_object(sample_dhash) | ||
analyses = test.get_analyses(sample_dhash)["analyses"] | ||
assert len(analyses) == 2 | ||
|
||
|
||
def test_get_karton_analysis_info(admin_session): | ||
test = admin_session | ||
blob_name = rand_string(15) | ||
argument_key = rand_string(5) | ||
argument_value = rand_string(5) | ||
blob = test.add_blob(None, blobname=blob_name, blobtype="inject", content=""" | ||
Binary junk: \x00\x01\x02\x03\x04\x05\x07 | ||
HELLO WORLD! | ||
========""" + random_name()) | ||
blob_dhash = blob["id"] | ||
new_analysis = test.reanalyze_object(blob_dhash, arguments={argument_key: argument_value}) | ||
analysis_id = new_analysis["id"] | ||
analysis_info = test.get_analysis_info(blob_dhash, analysis_id) | ||
assert analysis_id == analysis_info["id"] | ||
assert analysis_info["arguments"] == {argument_key: argument_value} | ||
|
||
|
||
def test_assign_analysis_to_object(admin_session): | ||
test = admin_session | ||
file_name = rand_string(15) | ||
file_content = rand_string() | ||
sample = test.add_sample(file_name, file_content) | ||
sample_dhash = sample["id"] | ||
new_analysis = test.reanalyze_object(sample_dhash) | ||
analysis_id = new_analysis["id"] | ||
|
||
blob_name = rand_string(15) | ||
blob = test.add_blob(None, blobname=blob_name, blobtype="inject", content=""" | ||
Binary junk: \x00\x01\x02\x03\x04\x05\x07 | ||
HELLO WORLD! | ||
========""" + random_name()) | ||
blob_dhash = blob["id"] | ||
|
||
test.assign_analysis_to_object(blob_dhash, analysis_id) | ||
analyses_ids = [analysis["id"] for analysis in test.get_analyses(blob_dhash)["analyses"]] | ||
assert analysis_id in analyses_ids | ||
|
||
incorrect_analysis_id = "b99249a0-ff33-4c93-a9f9-d854ab0ecb0" | ||
with ShouldRaise(status_code=400): | ||
test.assign_analysis_to_object(blob_dhash, incorrect_analysis_id) | ||
|
||
|
||
def test_unassign_analysis_from_object(admin_session): | ||
test = admin_session | ||
blob_name = rand_string(15) | ||
blob = test.add_blob(None, blobname=blob_name, blobtype="inject", content=""" | ||
Binary junk: \x00\x01\x02\x03\x04\x05\x07 | ||
HELLO WORLD! | ||
========""" + random_name()) | ||
blob_dhash = blob["id"] | ||
|
||
new_analysis_id = test.reanalyze_object(blob_dhash)["id"] | ||
|
||
all_object_analyses = test.get_analyses(blob_dhash)["analyses"] | ||
assert len(all_object_analyses) == 2 | ||
|
||
test.unassign_analysis_from_object(blob_dhash, new_analysis_id) | ||
all_object_analyses = test.get_analyses(blob_dhash)["analyses"] | ||
assert len(all_object_analyses) == 1 | ||
|
||
analyses_ids = [analysis["id"] for analysis in all_object_analyses] | ||
assert new_analysis_id not in analyses_ids | ||
|
||
incorrect_analysis_id = "b99249a0-ff33-4c93-a9f9-d854ab0ecb0" | ||
with ShouldRaise(status_code=400): | ||
test.unassign_analysis_from_object(blob_dhash, incorrect_analysis_id) | ||
|
||
|
||
def test_unassign_analysis_not_assigned_to_object(admin_session): | ||
test = admin_session | ||
file_name = rand_string(15) | ||
file_content = rand_string() | ||
sample = test.add_sample(file_name, file_content) | ||
sample_dhash = sample["id"] | ||
sample_analysis = test.reanalyze_object(sample_dhash) | ||
sample_analysis_id = sample_analysis["id"] | ||
|
||
blob_name = rand_string(15) | ||
blob = test.add_blob(None, blobname=blob_name, blobtype="inject", content=""" | ||
Binary junk: \x00\x01\x02\x03\x04\x05\x07 | ||
HELLO WORLD! | ||
========""" + random_name()) | ||
blob_dhash = blob["id"] | ||
|
||
with ShouldRaise(status_code=404): | ||
test.unassign_analysis_from_object(blob_dhash, sample_analysis_id) |
This file contains 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
Oops, something went wrong.