Skip to content

Commit

Permalink
Merge pull request #205 from johngian/circleci
Browse files Browse the repository at this point in the history
E2E automation
  • Loading branch information
johngian committed Jan 31, 2018
2 parents 4edc5a7 + 5af0318 commit 5980f2b
Show file tree
Hide file tree
Showing 4 changed files with 334 additions and 2 deletions.
169 changes: 169 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
version: 2

common_steps: &common_steps
steps:
- checkout
- attach_workspace:
at: /tmp/workspace
- run:
name: Setup testrp /etc/hosts
command: echo 127.0.0.1 testrp | tee -a /etc/hosts
- run:
name: Setup testprovider /etc/hosts
command: echo 127.0.0.1 testprovider | tee -a /etc/hosts
- run:
name: Install latest lib build
command: pip install /tmp/workspace/mozilla-django-oidc-dev.tar.gz
- run:
name: Override django version
command: pip install $DJANGO_VERSION
- run:
name: Run testprovider service
command: ./bin/run.sh
background: True
working_directory: /testprovider
- run:
name: Run testrp service
command: ./bin/run.sh
background: True
working_directory: /testrp
- run:
name: Wait for testprovider
command: wait-for-it -p 8080 -h localhost -t 60
- run:
name: Wait for testrp
command: wait-for-it -p 8081 -h localhost -t 60
- run:
name: Run integration tests
command: python integration_tests.py
working_directory: ~/project/integration_tests

jobs:
build_lib:
docker:
- image: circleci/python:3
steps:
- checkout
- run: mkdir workspace
- run: make sdist
- run: mv dist/mozilla-django-oidc-* workspace/mozilla-django-oidc-dev.tar.gz
- persist_to_workspace:
root: workspace
paths:
- mozilla-django-oidc-dev.tar.gz
e2e_test_py2_rs_django18:
docker:
- image: mozillaparsys/oidc_e2e_setup:py2
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=1.8,<1.9
<<: *common_steps
e2e_test_py2_rs_django111:
docker:
- image: mozillaparsys/oidc_e2e_setup:py2
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=1.11,<2.0.0
<<: *common_steps
e2e_test_py3_rs_django18:
docker:
- image: mozillaparsys/oidc_e2e_setup:py3
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=1.8,<1.9
<<: *common_steps
e2e_test_py3_rs_django111:
docker:
- image: mozillaparsys/oidc_e2e_setup:py3
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=1.11,<2.0.0
<<: *common_steps
e2e_test_py3_rs_django200:
docker:
- image: mozillaparsys/oidc_e2e_setup:py3
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=rs
- DJANGO_VERSION=Django>=2.0.0
<<: *common_steps
e2e_test_py2_hs_django18:
docker:
- image: mozillaparsys/oidc_e2e_setup:py2
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=1.8,<1.9
<<: *common_steps
e2e_test_py2_hs_django111:
docker:
- image: mozillaparsys/oidc_e2e_setup:py2
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=1.11,<2.0.0
<<: *common_steps
e2e_test_py3_hs_django18:
docker:
- image: mozillaparsys/oidc_e2e_setup:py3
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=1.8,<1.9
<<: *common_steps
e2e_test_py3_hs_django111:
docker:
- image: mozillaparsys/oidc_e2e_setup:py3
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=1.11,<2.0.0
<<: *common_steps
e2e_test_py3_hs_django200:
docker:
- image: mozillaparsys/oidc_e2e_setup:py3
name: testoidcsetup
environment:
- TEST_OIDC_ALGO=hs
- DJANGO_VERSION=Django>=2.0.0
<<: *common_steps

workflows:
version: 2
build_and_test:
jobs:
- build_lib
- e2e_test_py2_rs_django18:
requires:
- build_lib
- e2e_test_py2_rs_django111:
requires:
- build_lib
- e2e_test_py2_hs_django18:
requires:
- build_lib
- e2e_test_py2_hs_django111:
requires:
- build_lib
- e2e_test_py3_rs_django18:
requires:
- build_lib
- e2e_test_py3_rs_django111:
requires:
- build_lib
- e2e_test_py3_rs_django200:
requires:
- build_lib
- e2e_test_py3_hs_django18:
requires:
- build_lib
- e2e_test_py3_hs_django111:
requires:
- build_lib
- e2e_test_py3_hs_django200:
requires:
- build_lib
42 changes: 40 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Documentation
The full documentation is at `<https://mozilla-django-oidc.readthedocs.io>`_.


Running Tests
-------------
Running Unit Tests
-------------------

Use ``tox`` to run as many different versions of Python you have. If you
don't have ``tox`` installed (and executable) already you can either
Expand Down Expand Up @@ -59,6 +59,44 @@ Measuring code coverage, continuing the steps above:
(venv) $ coverage html
(venv) $ open htmlcov/index.html
Local development
-----------------

The local development setup is based on Docker so you need the following installed in your system:

* `docker`
* `docker-compose`

You will also need to edit your ``hosts`` file to resolve ``testrp`` and ``testprovider`` hostnames to ``127.0.0.1``.

Running test services
=====================

To run the `testrp` and `testprovider` instances run the following:

.. code-block:: shell
(venv) $ docker-compose up -d testprovider testrp
Then visit the testing django app on: ``http://testrp:8081``.

The library source code is mounted as a docker volume and source code changes are reflected directly in.
In order to test a change you need to restart the ``testrp`` service.

.. code-block:: shell
(venv) $ docker-compose stop testrp
(venv) $ docker-compose up -d testrp
Running integration tests
=========================

Integration tests are mounted as a volume to the docker containers. Tests can be run using the following command:

.. code-block:: shell
(venv) $ docker-compose run --service-ports testrunner
Linting
-------

Expand Down
37 changes: 37 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Based in the `docker-test-mozilla-django-oidc` images
# https://github.com/mozilla-parsys/docker-test-mozilla-django-oidc

version: '3'
services:
testprovider:
image: mozillaparsys/oidc_testprovider
ports:
- "8080:8080"
testrp:
image: mozillaparsys/oidc_testrp:py${PYTHON_VERSION:-3}
ports:
- "8081:8081"
volumes:
- ./:/mozilla-django-oidc
environment:
- TEST_OIDC_ALGO=${TEST_OIDC_ALGO:-hs}
- DJANGO_VERSION=${DJANGO_VERSION:-Django>=2.0}
command: >-
bash -c "cd /mozilla-django-oidc/ &&
python setup.py build &&
python setup.py install &&
cd /code &&
pip install $$DJANGO_VERSION &&
./bin/run.sh"
testrunner:
image: mozillaparsys/oidc_testrunner
volumes:
- ./integration_tests:/integration_tests
links:
- testrp
- testprovider
command: >-
bash -c "cd /integration_tests &&
wait-for-it -t 60 -p 8080 -h testprovider &&
wait-for-it -t 60 -p 8081 -h testrp &&
python integration_tests.py"
88 changes: 88 additions & 0 deletions integration_tests/integration_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import unittest

from splinter import Browser


class IntegrationTest(unittest.TestCase):

def __init__(self, *args, **kwargs):
super(IntegrationTest, self).__init__(*args, **kwargs)

self.webdriver = 'phantomjs'
self.account = {
'username': 'example_username',
'password': 'example_p@ssw0rd',
'email': 'example@example.com'
}

def setUp(self):
"""Create test account in `testprovider` instance"""
with Browser(self.webdriver) as browser:
browser.visit('http://testprovider:8080/account/signup')
browser.find_by_css('#id_username').fill(self.account['username'])
browser.find_by_css('#id_password').fill(self.account['password'])
browser.find_by_css('#id_password_confirm').fill(self.account['password'])
browser.find_by_css('#id_email').fill(self.account['email'])
browser.find_by_css('.btn-primary').click()

def tearDown(self):
"""Remove test account from `testprovider` instance"""
with Browser(self.webdriver) as browser:
self.perform_login(browser)
browser.visit('http://testprovider:8080/account/delete')
browser.find_by_css('.btn-danger').click()

def perform_login(self, browser):
"""Perform login using webdriver"""
browser.visit('http://testrp:8081')
browser.find_by_css('div > a').click()
browser.find_by_css('#id_username').fill(self.account['username'])
browser.find_by_css('#id_password').fill(self.account['password'])
browser.find_by_css('.btn-primary').click()

def perform_logout(self, browser):
"""Perform logout using webdriver"""
browser.visit('http://testrp:8081')
browser.find_by_css('input[value="Logout"]').click()

def test_login(self):
"""Test logging in `testrp` using OIDC"""
browser = Browser(self.webdriver)

# Check that user is not logged in
browser.visit('http://testrp:8081')
self.assertTrue(browser.is_text_not_present('Current user:'))

# Perform login
self.perform_login(browser)

# Accept scope
browser.find_by_css('input[name="allow"]').click()

# Check that user is now logged in
self.assertTrue(browser.is_text_present('Current user:'))

def test_logout(self):
"""Test logout functionality of OIDC lib"""
browser = Browser(self.webdriver)

# Check that user is not logged in
browser.visit('http://testrp:8081')
self.assertTrue(browser.is_text_not_present('Current user:'))

self.perform_login(browser)

# Accept scope
browser.find_by_css('input[name="allow"]').click()

# Check that user is now logged in
self.assertTrue(browser.is_text_present('Current user:'))

self.perform_logout(browser)

# Check that user is now logged out
self.assertTrue(browser.is_text_not_present('Current user:'))


if __name__ == '__main__':
unittest.main()

0 comments on commit 5980f2b

Please sign in to comment.