Skip to content

Commit

Permalink
[ BB2-537 ] Create Middleware-Logging Integration Tests (#946)
Browse files Browse the repository at this point in the history
* create middleware logging tests (integration tests)

* adjust command line option name from --loggingit to --logit, meaning log integration tests.

* no echo for sensitive info.

* code refactor.

* pick up changes from BB2-545

* pick bb2 545 changes and rebase.

* merge

* refactor test_logging settings, temp pull in cbc job selenium pipeline to facilitate reviewing and verifying.

* refactor, hookup with selenium tests job.

* fix linting.

* simplify audit logging redirect.

* cleanup.

* add logging integration tests to cbc job pipeline.

* fix log file path.

* remove print.

* create audit logger file handler path.

* trace logging.

* trace

* trace

* fix file handler.

* fix logger file handler.

* temp comment out logging integration tests from pipeline.

* trace

* trace

* trace

* trace

* trace

* trace

* trace

* turn off pretty json in logging.

* sync up with Pillow ver bump.

* print schema to facilitate debugging.

* print schema to facilitate debugging.

* relax attr check for crosswalk type, for runing under local(mslsx) vs remote(slsx) .

* cleanup and fix schema checking.

* cleanup and fix path validation.

* changes per review, remove django mslsx.

* catch up fix of docker-compose.selenium.yaml revert back to go lang mslsx.

* Fix local dev docker-compose issues

- Add healthcheck to postgres startup and bb2slsx to
  depend on service_healthy to fix timing issue
  in docker-compose.selenium.yml

- Move DJANGO_SETTINGS_MODULE location in
  launcher script docker-compose/run_selenium_tests_local_keybase.sh
  to enable other types of tests (non logit) to run.

BB2-537

Co-authored-by: Nick Bragdon <[email protected]>
Co-authored-by: Dave Tisza <[email protected]>
  • Loading branch information
3 people committed Oct 13, 2021
1 parent b2c2ab8 commit 79b3441
Show file tree
Hide file tree
Showing 10 changed files with 868 additions and 90 deletions.
20 changes: 20 additions & 0 deletions Dockerfiles/Dockerfile.jenkins
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.7.10
# For build CBC Jenkins job ECR image
ENV PYTHONUNBUFFERED 1
# ENV PYTHONDEVMODE 1

RUN mkdir /code
ADD . /code/
WORKDIR /code

RUN apt-get update && apt-get install -yq git unzip curl

# Install Chrome for Selenium
RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb \
&& dpkg -i /chrome.deb || apt-get install -yf \
&& rm /chrome.deb

# Install chromedriver for Selenium
RUN wget -O /tmp/chromedriver.zip http:https://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip \
&& unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/ \
&& chmod +x /usr/local/bin/chromedriver
23 changes: 18 additions & 5 deletions Jenkinsfiles/Jenkinsfile.cbc-run-multi-pr-checks-w-selenium
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,19 @@ pipeline {
steps{
sh """
. venv/bin/activate
export DJANGO_SETTINGS_MODULE=hhs_oauth_server.settings.dev && python manage.py migrate && python manage.py create_admin_groups && python manage.py loaddata scopes.json && python manage.py create_blue_button_scopes && python manage.py create_test_user_and_application && python manage.py create_user_identification_label_selection && python manage.py create_test_feature_switches && (if [ ! -d 'bluebutton-css' ] ; then git clone https://github.com/CMSgov/bluebutton-css.git ; else echo 'CSS already installed.' ; fi) && echo 'starting bb2...' && (python manage.py runserver 0.0.0.0:8000 > /tmp/bb2_server.log 2>&1 &)
python manage.py migrate && python manage.py create_admin_groups && python manage.py loaddata scopes.json && python manage.py create_blue_button_scopes && python manage.py create_test_user_and_application && python manage.py create_user_identification_label_selection && python manage.py create_test_feature_switches && (if [ ! -d 'bluebutton-css' ] ; then git clone https://github.com/CMSgov/bluebutton-css.git ; else echo 'CSS already installed.' ; fi) && echo 'starting bb2...' && (export DJANGO_SETTINGS_MODULE=hhs_oauth_server.settings.logging_it && python manage.py runserver 0.0.0.0:8000 &)
"""
}
}

stage("RUN logging integration tests") {
when {
expression { params.RUN_SELENIUM_TESTS == true }
}
steps{
sh """
. venv/bin/activate
python runtests.py --selenium apps.integration_tests.logging_tests.LoggingTests.test_auth_fhir_flows_logging
"""
}
}
Expand All @@ -105,11 +117,12 @@ pipeline {
expression { params.RUN_SELENIUM_TESTS == true }
}
steps{
sh """
. venv/bin/activate
python runtests.py --selenium apps.integration_tests.selenium_tests.SeleniumTests
"""
sh """
. venv/bin/activate
python runtests.py --selenium apps.integration_tests.selenium_tests.SeleniumTests
"""
}
}

}
}
51 changes: 29 additions & 22 deletions apps/integration_tests/integration_test_fhir_resources.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os

from django.conf import settings
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
Expand Down Expand Up @@ -186,17 +187,20 @@ def test_health_external_endpoint_v2(self):
self._call_health_external_endpoint(True)

def _call_health_external_endpoint(self, v2=False):
client = APIClient()
# no authenticate needed
response = client.get(self.live_server_url + "/health/external_v2" if v2 else "/health/external")
self.assertEqual(response.status_code, 200)
content = json.loads(response.content)
msg = None
try:
msg = content['message']
except KeyError:
pass
self.assertEqual(msg, "all's well")
use_mslsx = os.environ.get('USE_MSLSX', None)
if use_mslsx is not None and not use_mslsx == 'true':
# do not ping health end point if using MSLSX
client = APIClient()
# no authenticate needed
response = client.get(self.live_server_url + "/health/external_v2" if v2 else "/health/external")
self.assertEqual(response.status_code, 200)
content = json.loads(response.content)
msg = None
try:
msg = content['message']
except KeyError:
pass
self.assertEqual(msg, "all's well")

@override_switch('require-scopes', active=True)
def test_health_bfd_endpoint(self):
Expand Down Expand Up @@ -236,17 +240,20 @@ def test_health_db_endpoint(self):

@override_switch('require-scopes', active=True)
def test_health_sls_endpoint(self):
client = APIClient()
# no authenticate needed
response = client.get(self.live_server_url + "/health/sls")
self.assertEqual(response.status_code, 200)
content = json.loads(response.content)
msg = None
try:
msg = content['message']
except KeyError:
pass
self.assertEqual(msg, "all's well")
use_mslsx = os.environ.get('USE_MSLSX', None)
if use_mslsx is not None and not use_mslsx == 'true':
# do not ping health end point if using MSLSX
client = APIClient()
# no authenticate needed
response = client.get(self.live_server_url + "/health/sls")
self.assertEqual(response.status_code, 200)
content = json.loads(response.content)
msg = None
try:
msg = content['message']
except KeyError:
pass
self.assertEqual(msg, "all's well")

@override_switch('require-scopes', active=True)
def test_userinfo_endpoint(self):
Expand Down
Loading

0 comments on commit 79b3441

Please sign in to comment.