Skip to content

TIDO-505 Update base image #3

merged 9 commits into from Aug 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Replace testing image and add selenium standalone image
dmartinez committed Aug 21, 2024
commit bef25c238f43db5cbee2991f57733ed4c697f6d7
54 changes: 47 additions & 7 deletions docker-compose.yml
@@ -2,6 +2,11 @@ version: "3"

networks:
proxy-net:
driver: bridge
ipam:
config:
- subnet: 172.19.0.0/16
gateway: 172.19.0.1

services:

@@ -34,7 +39,7 @@ services:
- "443:443"
networks:
proxy-net:
# ipv4_address: 172.19.0.10
ipv4_address: 172.19.0.10
depends_on:
- app
- idp
@@ -111,10 +116,10 @@ services:
/oz8xKl5PKwOrvk2DH+FwaAg
-----END PRIVATE KEY-----
SAML_ENTITYID: https://sptest.example.edu/shibboleth
SAML_IDP_ENTITYID: http://localhost:8080/simplesaml/saml2/idp/metadata.php
SAML_IDP_METADATA_URL: http://localhost:8080/simplesaml/saml2/idp/metadata.php
SAML_IDP_ENTITYID: http://idp:8080/simplesaml/saml2/idp/metadata.php
SAML_IDP_METADATA_URL: http://idp:8080/simplesaml/saml2/idp/metadata.php
SAML_IDP_METADATA: |
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" entityID="http://localhost:8080/simplesaml/saml2/idp/metadata.php">
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" entityID="http://idp:8080/simplesaml/saml2/idp/metadata.php">
<md:IDPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:KeyDescriptor use="signing">
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
@@ -130,9 +135,9 @@ services:
</ds:X509Data>
</ds:KeyInfo>
</md:KeyDescriptor>
<md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="http://localhost:8080/simplesaml/saml2/idp/SingleLogoutService.php"/>
<md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="http://idp:8080/simplesaml/saml2/idp/SingleLogoutService.php"/>
<md:NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</md:NameIDFormat>
<md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="http://localhost:8080/simplesaml/saml2/idp/SSOService.php"/>
<md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="http://idp:8080/simplesaml/saml2/idp/SSOService.php"/>
</md:IDPSSODescriptor>
</md:EntityDescriptor>
SAML_SIGNING_CERT: |
@@ -252,9 +257,44 @@ services:
ZMmUvRJr8jzCCPD8DrHf85GAACRPoVsBDLD3oXTLcY8Frum1npH57H6Eaa/Jmuk5
UdDJprIEgUhY47jK1O+IKtxnTQPnqotqWC5Lk4Rhnr62APxhkl9jraI=
-----END RSA PRIVATE KEY-----
healthcheck:
test: ["CMD", "curl", "-f", "--insecure", "https://localhost:443"]

selenium-firefox:
image: selenium/standalone-firefox:120.0-20231122
networks:
- proxy-net
ports:
- "4444:4444"
- "7900:7900"
extra_hosts:
- "sptest.example.edu:172.19.0.10"
shm_size: "2g"
environment:
SE_OPTS: "--log-level SEVERE"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:4444/wd/hub/status"]

test:
test-auth-firefox:
build:
context: "./tests/containers/test"
networks:
- proxy-net
command: [ "python", "/selenium/test_script.py" ]
depends_on:
selenium-firefox:
condition: service_healthy
proxy:
condition: service_healthy
# app:
# condition: service_healthy
idp:
condition: service_healthy
volumes:
- "./tests/containers/test:/selenium"

# test:
# build:
# context: "./tests/containers/test"
# networks:
# - proxy-net
3 changes: 0 additions & 3 deletions tests/containers/app/container_files/app.conf

This file was deleted.

353 changes: 0 additions & 353 deletions tests/containers/app/container_files/httpd.conf

This file was deleted.

42 changes: 7 additions & 35 deletions tests/containers/test/Dockerfile
@@ -1,38 +1,10 @@
FROM centos:centos7

# Update repo files since change from CentOS Base to CentOS Vault on 7/1/24
RUN sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo && \
sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo && \
sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo

# Install Python 3 and Firefox
RUN yum -y update \
&& yum -y --setopt=skip_missing_names_on_install=False install \
firefox \
python3 \
&& rm -fr /var/cache/yum/* && yum clean all

# Install Selenium
RUN pip3 install -U selenium

# Install Mozilla Gecko driver for Firefox
ENV GECKO_VERSION="v0.26.0"
ENV GECKO_TARBALL="geckodriver-${GECKO_VERSION}-linux64.tar.gz"
ENV GECKO_URL="https://github.com/mozilla/geckodriver/releases/download/${GECKO_VERSION}/${GECKO_TARBALL}"
WORKDIR /tmp/geckodriver
RUN curl --location --remote-name --show-error --silent $GECKO_URL && \
gunzip -c $GECKO_TARBALL | tar -xvf - && \
chown root:root geckodriver && \
chmod u=rwx,g=rx,o=rx geckodriver && \
mv geckodriver /usr/local/bin/ && \
rm $GECKO_TARBALL && \
cd / && \
rmdir /tmp/geckodriver

COPY container_files/test.py /tests/test.py

CMD [ "python3", "/tests/test.py" ]

FROM python:3.9

ARG DEBIAN_FRONTEND=noninteractive

RUN apt update \
&& apt upgrade -y

RUN pip install \
requests \
selenium
44 changes: 0 additions & 44 deletions tests/containers/test/container_files/test.py

This file was deleted.

54 changes: 54 additions & 0 deletions tests/containers/test/test_script.py
@@ -0,0 +1,54 @@
"""
A simple selenium test written by python
"""

import unittest
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options

class TestTemplate(unittest.TestCase):
"""Include test cases on a given url"""

def setUp(self):
"""Start web driver"""

options = Options()
# options.add_argument("--headless")

self.driver = webdriver.Remote(command_executor="http://selenium-firefox:4444",options=options)
self.driver.implicitly_wait(10)

def tearDown(self):
"""Stop web driver"""
self.driver.quit()

def test_case_1(self):
"""Test redirect to IDP"""
try:
self.driver.get('https://sptest.example.edu')

wait = WebDriverWait(self.driver, timeout=10)
wait.until(EC.presence_of_element_located((By.ID, 'username')))

username_textfield = self.driver.find_element(By.ID, 'username')
username_textfield.send_keys("user1")

password_textfield = self.driver.find_element(By.ID, 'password')
password_textfield.send_keys("user1pass")

login_button = self.driver.find_element(By.XPATH, "/html/body/div/div[3]/form/table/tbody/tr[3]/td[3]/button")
login_button.click()

x_forwarded_server = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#\/headers\/X-Forwarded-Server > td:nth-child(2) > span:nth-child(1) > span:nth-child(1)")))
self.assertEqual(x_forwarded_server.text.replace('"',''), 'sptest.example.edu')

except NoSuchElementException as ex:
self.fail(ex.msg)

if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestTemplate)
unittest.TextTestRunner(verbosity=2).run(suite)