diff --git a/.gitignore b/.gitignore index 4b2b419..4f69bb6 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,7 @@ nosetests.xml coverage.xml *,cover .hypothesis/ +.pytest_cache/ # Translations *.mo diff --git a/.travis.yml b/.travis.yml index 15da16f..3ff356a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: python python: + - "3.4" - "3.6" cache: pip before_install: @@ -15,12 +16,11 @@ before_install: install: - pip install -r requirements.txt - pip install flake8 - - python -W ignore::UserWarning:distutils.dist setup.py build script: - cat aws_ir/_version.py - flake8 aws_ir - flake8 tests - - pytest tests/ + - python setup.py test deploy: - provider: pypi @@ -28,6 +28,7 @@ deploy: user: threatresponse password: secure: 0j3uJew5G/+06gQnKRYDdWfwKYfWuXBFSQXob1T6Q8aFsY7Ats+4HjQE1gC1igU/6XwPCBPUBHVuVC1YCfXQFLbqTAJng8F28Z+ULZLkO78+0qTUbqWXqclKT7ES2VaMRhAyNuxPg76WJ0W5cDq+q9nJ05jJjxdfmPhlEgJNHKpc0W1l5RtXKwTyHawAdxZxhBcuNtopMBuSgB7EN/jy4S5xyKAdNNITLUoVD9HwS9pMWIv5t2crvFZXxyoIDR4ga4bCGCAz1NSdFsSguTQb/EeClItw/BEUuFyv6KkMbkfiCcLJZBdEXEUyshrMIo2smenblK4iYFNS7c25BqMuXsdxe39fgkRFkC41W/JB2WtBvMpMESi7+b18KKR9Y+8Hh+3i+BjiNl2RN8Um8vMaRh6B9jt8+dI7zc6QIohviPeDLif1L7jkU8NpCIGgYDWOy2rGfeWnOz07scoObiZbozlbZw15nWIAIzo4pELt5Ga0voBQ179KJdH88dso25mF9cAKhRezqTzJY1YS7GUKavdugfnL5Cpthyal4ajVrVw5J66cJZmyT2Qmj/uzfTrXxXfFfDALQOiFWea3EbV8qSnf0MkVV4pEixdlnD1jobFZNZLFg1VCNJionSbqZbUccSCLjjKkv05XTjUktJV37V5m41xBm7mRH9PvPgGHCOo= + skip_existing: true on: tags: true @@ -38,5 +39,6 @@ deploy: password: secure: 3WT5LhsCxkkJReN2Tg2wHwlzFIQ9cVQagIxekf7b/iPDy2M+CGhGC94sct5Rx5J6JSy2yiQfMRAjdvFQMFewM52s1H9iojsOx5uHxAzulEMdMkI7FehKD49d9k0wnBkkIu9cS9/0nvaFCQIiaV/J/5F7U7WXqC0JgZOoJCAIBWrUSjwnbeMlyRsJwfy4jQQY8AqzqewJFlcpfzW0tJKyNMsgRyi+pxT60ihuNrT3oCwzjV/g7CajmD1fq41FwRgSzmFzF3qyCSxEhQ0KOYtUNZ8FzkpxoN8s8CKOBT20B2tUJhMp2wv5f16r4zsFPemA7mpPuZMWlCghJId8ad61reWPs7sxjGgxHXOm0hvBGGrM17vOAM176pahjLlTSN9Bl0A2QyL7fKmQhxnBWT6ZnbVo3jW9cEx2qee1dyR/ybPbMZTatrx9eb9Jdl381/10YMeqkfCm0rrEfLluVVI3Oq0yGvzIRCOgCskzIKwj2bDbor5H2Tu45ht5OUB5inQpFQapRkZ3pc6W4o9c7ONcrhoQVoazEWUAm8hNn7oaR9rd+yY7F0+ojjLZxnOaIYsk11eSeTnVyIesexmHdL0iltuteWZ3wxEIsB8Revx3KxlhudwCvINlD8Jj8L1WdiyIPcEa4QeQF/bNTht6SWFPGC/EbM+jaOAGaagVkdBGQwk= skip_cleanup: true + skip_existing: true on: all_branches: true diff --git a/Dockerfile b/Dockerfile index f0f80b4..656939b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,5 @@ -FROM python:3-onbuild +FROM python:3.4 RUN mkdir /aws_ir - -COPY requirements.txt /aws_ir/requirements.txt - -RUN pip install --upgrade pip - ADD . /aws_ir/ - WORKDIR /aws_ir diff --git a/aws_ir/_version.py b/aws_ir/_version.py index e1424ed..80eb7f9 100644 --- a/aws_ir/_version.py +++ b/aws_ir/_version.py @@ -1 +1 @@ -__version__ = '0.3.1' +__version__ = '0.3.3' diff --git a/aws_ir/cli.py b/aws_ir/cli.py index a92b7f7..616592e 100755 --- a/aws_ir/cli.py +++ b/aws_ir/cli.py @@ -1,10 +1,9 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import argparse import logging import os import sys - import aws_ir from aws_ir import __version__ from aws_ir.libs import case diff --git a/bin/aws_ir b/bin/aws_ir index 7b93aae..27c95c6 100755 --- a/bin/aws_ir +++ b/bin/aws_ir @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys import os diff --git a/docker-compose.yml b/docker-compose.yml index 9c8a28c..7a41ec6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,3 @@ services: volumes: - ~/.aws:/root/.aws - .:/aws_ir/ - environment: - - EDDA_SERVER=192.168.1.83 - - EDDA_PORT=8080 - - EDDA_BASE_URL=/api/v2/ diff --git a/docs/development.rst b/docs/development.rst index 5f5304f..49d68e9 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -300,28 +300,58 @@ Step 1. Fork us on Github. # 1. git clone git@github.com:/aws_ir.git +Step 2. Setup + # 2. setup a virtualenv (must be python3) cd aws_ir - virtualenv env -p python3 + python3 -m virtualenv env # 3. activate the virtualenv source env/bin/activate - # 4. install the requirements - pip3 install -r requirements.txt - # 5. run the test suite (currently pyTest soon to be pyUnit) - pytest tests/ + # 4a. with setuptools + pip install -e . + python setup.py test + python setup.py pytest --addopts='tests/test_cli.py' + + -- or -- + + # 4b. with local plugins and pytest-watch + point requirements.txt to the local version of aws_ir_plugins `-e ../aws_ir_plugins` + .. code-block:: bash + pip3 install -r requirements.txt + ./bin/aws_ir -h + ptw --runner "python setup.py test" + + -- or -- + + #4c. Use the docker container + .. code-block:: bash + docker-compose build aws_ir + docker-compose run aws_ir bash + pip install -e . + - # 6. If all is well you can start developing code! +Step 3. Develop! -Step 2. Develop! -*Note:* aws_ir does not require an install to run out of a virtualenv. There -is a helper script in `bin/aws_ir` that can be called to execute your development -version of aws_ir. +*Note:* There is a helper script in `bin/aws_ir` that can be called to execute aws_ir. When your feature is finished simply open a PR back to us. -Happy developing! If you have any questions please do file a github issue +If you have any questions please do file a github issue or e-mail info@threatresponse.cloud . + +Using testpypi +******************************************* + +.. code-block:: bash + pip install --extra-index-url https://test.pypi.org/simple/ aws_ir==0.3.2b165 + +To use a test build of aws_ir_plugins: + in setup.py: + - point the required version at aws_ir_plugins==0.0.3b123 (substitute the build you want) + - add: dependency_links=['https://test.pypi.org/simple/aws-ir-plugins/'] + + diff --git a/docs/installing.rst b/docs/installing.rst index 5cf682c..1005a42 100644 --- a/docs/installing.rst +++ b/docs/installing.rst @@ -5,33 +5,17 @@ Installation System Requirements ******************* -ThreatResponse now requires python >= 3.4. It may still work(ish) with Python 2.7 but is not recommended due -to security problems with cryptography libraries in Python 2.7. +ThreatResponse requires python >= 3.4. -While aws_ir is written purely in python, some of the libraries used require additional system packages. - -Fedora / RHEL Distributions ---------------------------- - -* python-devel (Python 3.4+) -* python-pip -* libffi-devel -* libssl-devel - -Debian Distributions --------------------- - -* python-dev (Python 3.4+) -* python-pip -* libffi-dev -* libssl-dev Installing from PyPi ******************** .. code-block:: bash - + $ python3 -m virtualenv env + $ source/env/bin/activate $ pip install aws_ir + $ aws_ir -h Installing From Github @@ -39,8 +23,10 @@ Installing From Github .. code-block:: bash + $ python3 -m virtualenv env + $ source/env/bin/activate $ pip install git+ssh://git@github.com/ThreatResponse/aws_ir.git@master - $ margaritashotgun -h + $ aws_ir -h Local Build and Install *********************** @@ -49,9 +35,10 @@ Local Build and Install $ git clone https://github.com/ThreatResponse/aws_ir.git $ cd aws_ir - $ python setup.py - $ pip install dist/aws_ir-*.tar.gz - $ margaritashotgun -h + $ python3 -m virtualenv env + $ source/env/bin/activate + $ pip install . + $ aws_ir -h Local Execution *************** @@ -62,6 +49,62 @@ In the previous two example dependencies are automatically resolved, if you simp $ git clone https://github.com/ThreatResponse/aws_ir.git $ cd aws_ir + $ python3 -m virtualenv env + $ source/env/bin/activate $ pip install -r requirements.txt $ ./bin/aws_ir -h +Using Docker +************ + +.. code-block:: bash + + $ git clone https://github.com/ThreatResponse/aws_ir.git + $ cd aws_ir + $ docker-compose build aws_ir + $ docker-compose run aws_ir bash + $ pip install . + + +AWS Credentials Using MFA and AssumeRole +***************************************** + +Many users of aws_ir have requested the ability to use the tooling with mfa and +assumeRole functionality. While we don't natively support this yet v0.3.0 sets +the stage to do this natively by switching to boto-session instead of thick clients. + +For now if you need to use the tool with MFA we recommend: + +`https://pypi.python.org/pypi/awsmfa/0.2.4 `_. + +.. code-block:: bash + + aws-mfa \ + --device arn:aws:iam::12345678:mfa/bobert \ + -assume-role arn:aws:iam::12345678:role/ResponderRole \ + --role-session-name \"bobert-ir-session\" + +awsmfa takes a set of long lived access keys from a boto profile called [default-long-lived] +and uses those to generate temporary session tokens that are automatically put into +the default boto profile. This ensures that any native tooling that doesn't support +MFA + AssumeRole can still leverage MFA and short lived credentials for access. + + +Some Linux distributions require additional system packages +*********************************************************** + +Fedora / RHEL Distributions +--------------------------- + +* python-devel (Python 3.4+) +* python-pip +* libffi-devel +* libssl-devel + +Debian Distributions +-------------------- + +* python-dev (Python 3.4+) +* python-pip +* libffi-dev +* libssl-dev diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 7a0dd26..f4577b6 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -7,15 +7,13 @@ First, :doc:`Install aws_ir `. Installation ************ -Using a python3 virtualenv is highly recommended. - .. code-block:: bash - $ virtualenv aws_ir_env -p python3 - $ source/aws_ir_env/bin/activate - $ pip3 install aws_ir + $ python3 -m virtualenv env + $ source/env/bin/activate + $ pip install aws_ir -Or see `installing `__. +For other installation options see: `installing `__. AWS Credentials *************** @@ -26,8 +24,7 @@ Ensure aws credentials are configured under the user running aws_ir as documente Setup Roles with Cloudformation ************************************* -A cloudformation stack has been provided to setup a group and a responder role. *Note that this roles has a constraint -that all your responders use MFA.* +A cloudformation stack has been provided to setup a group and a responder role. Simply create the stack available at: @@ -35,28 +32,10 @@ Simply create the stack available at: Then add all your users to the IncidentResponders group. After that you're good to go! -AWS Credentials Using MFA and AssumeRole -***************************************** - -Many users of aws_ir have requested the ability to use the tooling with mfa and -assumeRole functionality. While we don't natively support this yet v0.3.0 sets -the stage to do this natively by switching to boto-session instead of thick clients. - -For now if you need to use the tool with MFA we recommend: - -`https://pypi.python.org/pypi/awsmfa/0.2.4 `_. - +*Note that this roles has a constraint that all your responders use MFA.* .. code-block:: bash + aws:MultiFactorAuthPresent: 'true' - aws-mfa \ - --device arn:aws:iam::12345678:mfa/bobert \ - -assume-role arn:aws:iam::12345678:role/ResponderRole \ - --role-session-name \"bobert-ir-session\" - -awsmfa takes a set of long lived access keys from a boto profile called [default-long-lived] -and uses those to generate temporary session tokens that are automatically put into -the default boto profile. This ensures that any native tooling that doesn't support -MFA + AssumeRole can still leverage MFA and short lived credentials for access. Key Compromise ************** diff --git a/requirements.txt b/requirements.txt index a319c08..5defa30 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,4 @@ jinja2 -pytest -pytest-cov boto3>=1.3.0 progressbar-latest gnupg @@ -8,10 +6,23 @@ requests structlog pytz logutils==0.3.3 +margaritashotgun>=0.4.1 +pluginbase + +mock moto +pytest +pytest-cov pytest-moto -mock -margaritashotgun -pluginbase -aws-ir-plugins +pytest-watch + +### Latest Stable +aws_ir_plugins==0.0.3 + +### Test build +# --extra-index-url https://test.pypi.org/simple +# aws-ir-plugins==0.0.3b52 + +### Local +# -e ../aws_ir_plugins diff --git a/setup.cfg b/setup.cfg index 2952d03..a78118a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,12 @@ +[aliases] +test=pytest + [metadata] description-file = README.rst [flake8] ignore=E402,H238 max-line-length=99 + +[tool:pytest] +[pytest-watch] diff --git a/setup.py b/setup.py index 974411d..8d790f8 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,6 @@ import re from distutils.command.build import build from setuptools import setup -from setuptools.command.install import install as _install VERSION = re.search( r"^__version__ = ['\"]([^'\"]*)['\"]", @@ -9,13 +8,7 @@ re.MULTILINE ).group(1) -class install(_install): - def run(self): - self.run_command('build') - _install.run(self) - setup(name="aws_ir", - version=VERSION, author="Andrew Krug, Alex McCormack, Joel Ferrier, Jeff Parr", author_email="andrewkrug@gmail.com,developer@amccormack.net,joel@ferrier.io", @@ -26,6 +19,7 @@ def run(self): url='https://github.com/ThreatResponse/aws_ir', download_url="https://github.com/ThreatResponse/aws_ir/archive/v0.3.0.tar.gz", use_2to3=True, + zip_safe=True, install_requires=['boto3>=1.3.0', 'progressbar_latest', 'logutils==0.3.3', @@ -35,11 +29,12 @@ def run(self): 'jinja2', 'pluginbase', 'margaritashotgun>=0.4.1', - 'aws-ir-plugins>=0.0.2' + 'aws-ir-plugins>=0.0.3' ], + setup_requires=['pytest-runner'], tests_require=['pytest', 'pytest-cov', + 'pytest-watch', 'moto', - 'mock', - 'magicmock'], + 'mock'], ) diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_case_lib.py b/tests/test_case_lib.py index 1f8ea4f..43e5a8f 100644 --- a/tests/test_case_lib.py +++ b/tests/test_case_lib.py @@ -1,234 +1,197 @@ -import boto3 import os +import shutil +import pytest +import boto3 import random import string -import sys -from moto import mock_ec2 from moto import mock_s3 -sys.path.append(os.getcwd()) from aws_ir.libs import case +log_base = "{}/mock_s3".format(os.path.dirname(os.path.abspath(__file__))) -class TestCaseLib(object): - def test_object_init(self): - # setup bucket to test providing an s3 bucket to Case class - self.m = mock_s3() - self.m.start() +def setup_module(): + if not os.path.exists(log_base): + os.mkdir(log_base) - self.e = mock_ec2() - self.e.start() - self.created_buckets = [] +def teardown_module(): + shutil.rmtree(log_base, ignore_errors=True) - self.s3_resource = boto3.resource( - service_name='s3', - region_name='us-west-2' - ) - self.existing_bucket_name = "case-lib-test-{0}".format( - ''.join( - random.choice( - string.ascii_lowercase + string.digits - ) - for _ in range(10) - ) - ) +@pytest.fixture +def s3(): + """ is a fixture the best place for this?""" + s3_mock = mock_s3() + s3_mock.start() + return s3_mock - with self.m: - self.s3_resource.Bucket(self.existing_bucket_name).create() - self.created_buckets.append(self.existing_bucket_name) +def test_object_init(s3): + created_buckets = [] - # create a Case object for testing - self.generic_case = case.Case() - self.created_buckets.append(self.generic_case.case_bucket) + with s3: - # setup default info for log collection - self.log_base = os.path.dirname(os.path.abspath(__file__)) + # test init with no args + case_without_args = case.Case() + created_buckets.append(case_without_args.case_bucket) - # create test files - self.test_log = "{0}/{1}-aws_ir.log".format( - self.log_base, - self.generic_case.case_number - ) - - self.renamed_test_log = "{0}/{1}-{2}-aws_ir.log".format( - self.log_base, - self.generic_case.case_number, - 'i-12345678' - ) + assert case_without_args is not None + assert case_without_args.case_number is not None + assert case_without_args.case_bucket is not None + assert case_without_args.examiner_cidr_range == '0.0.0.0/0' - with open(self.test_log, 'w') as f: - f.write('test log data') - f.close() + # test init with case number + case_with_number = case.Case( + case_number='cr-16-022605-3da6' + ) + created_buckets.append(case_with_number.case_bucket) - # create test screenshot - self.test_jpg = "{0}/{1}-console.jpg".format( - self.log_base, - self.generic_case.case_number - ) + assert case_with_number is not None + assert case_with_number.case_number == 'cr-16-022605-3da6' + assert case_with_number.case_bucket is not None + assert case_with_number.examiner_cidr_range == '0.0.0.0/0' - with open(self.test_jpg, 'w') as f: - f.write('test jpg data') - f.close() + # test init with cidr_range + case_with_cidr = case.Case( + examiner_cidr_range='8.8.8.8/32' + ) + created_buckets.append(case_with_cidr.case_bucket) - # test init with no args - case_without_args = case.Case() - self.created_buckets.append(case_without_args.case_bucket) + assert case_with_cidr is not None + assert case_with_cidr.case_number is not None + assert case_with_cidr.case_bucket is not None + assert case_with_cidr.examiner_cidr_range == '8.8.8.8/32' - assert case_without_args is not None - assert case_without_args.case_number is not None - assert case_without_args.case_bucket is not None - assert case_without_args.examiner_cidr_range == '0.0.0.0/0' - # test init with case number - case_with_number = case.Case( - case_number='cr-16-022605-3da6' - ) - self.created_buckets.append(case_with_number.case_bucket) +def test_init_with_existing_bucket(s3): + created_buckets = [] - assert case_with_number is not None - assert case_with_number.case_number == 'cr-16-022605-3da6' - assert case_with_number.case_bucket is not None - assert case_with_number.examiner_cidr_range == '0.0.0.0/0' + s3_resource = boto3.resource( + service_name='s3', + region_name='us-west-2' + ) - # est init with case_bucket - case_with_bucket = case.Case( - case_bucket=self.existing_bucket_name + existing_bucket_name = "case-lib-test-{0}".format( + ''.join( + random.choice( + string.ascii_lowercase + string.digits ) + for _ in range(10) + ) + ) - assert case_with_bucket is not None - assert case_with_bucket.case_number is not None - assert case_with_bucket.case_bucket == self.existing_bucket_name - assert case_with_bucket.examiner_cidr_range == '0.0.0.0/0' + with s3: - # test init with cidr_range - case_with_cidr = case.Case( - examiner_cidr_range='8.8.8.8/32' - ) - self.created_buckets.append(case_with_cidr.case_bucket) - - assert case_with_cidr is not None - assert case_with_cidr.case_number is not None - assert case_with_cidr.case_bucket is not None - assert case_with_cidr.examiner_cidr_range == '8.8.8.8/32' - - def test_rename_log_file(self): - # remove this test once we can test case.teardown - self.generic_case = case.Case() - self.log_base = os.path.dirname(os.path.abspath(__file__)) - - self.test_log = "{0}/{1}-aws_ir.log".format(self.log_base, - self.generic_case.case_number) - self.renamed_test_log = "{0}/{1}-{2}-aws_ir.log".format( - self.log_base, - self.generic_case.case_number, - 'i-12345678' + s3_resource.Bucket(existing_bucket_name).create() + created_buckets.append(existing_bucket_name) + + case_with_bucket = case.Case( + case_bucket=existing_bucket_name ) - with open(self.test_log, 'w') as f: - f.write('test log data') - f.close() + assert case_with_bucket is not None + assert case_with_bucket.case_number is not None + assert case_with_bucket.case_bucket == existing_bucket_name + assert case_with_bucket.examiner_cidr_range == '0.0.0.0/0' - # create test screenshot - self.test_jpg = "{0}/{1}-console.jpg".format( - self.log_base, - self.generic_case.case_number - ) - with open(self.test_jpg, 'w') as f: - f.write('test jpg data') - f.close() +def test_rename_log_file(): + # remove this test once we can test case.teardown + generic_case = case.Case() - result = self.generic_case._rename_log_file( - self.generic_case.case_number, - 'i-12345678', - base_dir=self.log_base - ) + test_log = "{0}/{1}-aws_ir.log".format(log_base, generic_case.case_number) - print(result) + with open(test_log, 'w') as f: + f.write('test log data') + f.close() - assert result is True + # create test screenshot + test_jpg = "{0}/{1}-console.jpg".format( + log_base, + generic_case.case_number + ) - def test_copy_logs_to_s3(self): - # setup bucket to test providing an s3 bucket to Case class - self.m = mock_s3() + with open(test_jpg, 'w') as f: + f.write('test jpg data') + f.close() - self.m.start() + result = generic_case._rename_log_file( + generic_case.case_number, + 'i-12345678', + base_dir=log_base + ) - self.e = mock_ec2() - self.e.start() + assert result is True - self.created_buckets = [] - with self.m: - self.s3_resource = boto3.resource( - service_name='s3', - region_name='us-west-2' - ) - self.existing_bucket_name = "case-lib-test-{0}".format( - ''.join( - random.choice( - string.ascii_lowercase + string.digits - ) - for _ in range(10) +def test_copy_logs_to_s3(s3): + created_buckets = [] + with s3: + s3_resource = boto3.resource( + service_name='s3', + region_name='us-west-2' + ) + + existing_bucket_name = "case-lib-test-{0}".format( + ''.join( + random.choice( + string.ascii_lowercase + string.digits ) + for _ in range(10) ) + ) - self.s3_resource.Bucket(self.existing_bucket_name).create() - self.created_buckets.append(self.existing_bucket_name) - - # create a Case object for testing - self.generic_case = case.Case() - self.created_buckets.append(self.generic_case.case_bucket) + s3_resource.Bucket(existing_bucket_name).create() + created_buckets.append(existing_bucket_name) - # setup default info for log collection - self.log_base = os.path.dirname(os.path.abspath(__file__)) + # create a Case object for testing + generic_case = case.Case() + created_buckets.append(generic_case.case_bucket) - # create test files - self.test_log = "{0}/{1}-aws_ir.log".format( - self.log_base, - self.generic_case.case_number - ) + # create test files + test_log = "{0}/{1}-aws_ir.log".format( + log_base, + generic_case.case_number + ) - self.renamed_test_log = "{0}/{1}-{2}-aws_ir.log".format( - self.log_base, - self.generic_case.case_number, - 'i-12345678' - ) + renamed_test_log = "{0}/{1}-{2}-aws_ir.log".format( + log_base, + generic_case.case_number, + 'i-12345678' + ) - with open(self.test_log, 'w') as f: - f.write('test log data') - f.close() + with open(test_log, 'w') as f: + f.write('test log data') + f.close() - # create test screenshot - self.test_jpg = "{0}/{1}-console.jpg".format( - self.log_base, - self.generic_case.case_number - ) + # create test screenshot + test_jpg = "{0}/{1}-console.jpg".format( + log_base, + generic_case.case_number + ) - with open(self.test_jpg, 'w') as f: - f.write('test jpg data') - f.close() + with open(test_jpg, 'w') as f: + f.write('test jpg data') + f.close() - self.generic_case._rename_log_file( - self.generic_case.case_number, - 'i-12345678', - base_dir=self.log_base - ) + generic_case._rename_log_file( + generic_case.case_number, + 'i-12345678', + base_dir=log_base + ) - self.generic_case.copy_logs_to_s3(base_dir=self.log_base) + generic_case.copy_logs_to_s3(base_dir=log_base) - case_bucket = self.s3_resource.Bucket(self.generic_case.case_bucket) - uploaded_files = [] - for obj in case_bucket.objects.all(): - print(obj.key) - uploaded_files.append(obj.key) + case_bucket = s3_resource.Bucket(generic_case.case_bucket) + uploaded_files = [] + for obj in case_bucket.objects.all(): + print(obj.key) + uploaded_files.append(obj.key) - test_log_key = self.renamed_test_log.split("/")[-1] - test_jpg_key = self.test_jpg.split("/")[-1] - assert test_log_key in uploaded_files - assert test_jpg_key in uploaded_files + test_log_key = renamed_test_log.split("/")[-1] + test_jpg_key = test_jpg.split("/")[-1] + assert test_log_key in uploaded_files + assert test_jpg_key in uploaded_files diff --git a/tests/test_cli.py b/tests/test_cli.py index 5d1bbfa..83098ea 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,9 +1,6 @@ import copy -import os import pytest -import sys -sys.path.append(os.getcwd()) from aws_ir.cli import cli diff --git a/tests/test_logging.py b/tests/test_logging.py index 75de3a7..8260ad9 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -1,6 +1,4 @@ import os -import sys -sys.path.append(os.getcwd()) import aws_ir from aws_ir import TimesketchLogger import logging