Skip to content

Commit

Permalink
test: ajout test d'intégration SLO classique
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancailbourdin committed Oct 14, 2024
1 parent 7ea0949 commit debd73d
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ci/python/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
SERVICE_ATTRIBUTE_RELEASE_URL = "http://localhost:8010/test"

# Url du service avec lequel on doit pouvoir se connecter quand on teste la redirection token portail après connexion
SERVICE_TOKEN_NOREDIRECT_URL = "http://localhost:8016/test"
SERVICE_TOKEN_NOREDIRECT_URL = "http://localhost:8016/test"

# Url du service pour tester la déconnexion globale
SERVICE_SLO_URL = "http://localhost:8019/test"
35 changes: 35 additions & 0 deletions ci/python/service_test19.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Serveur python simulant un service web.
Il n'est pas là pour faire les requêtes (ce sont les scripts de test qui les font) mais pour pour faire valider des ST et le SLO.
Utilisé comme service pour tester si le CAS envoie bien une requête de SLO lors de la déconnexion.
"""

import urllib3
from http.server import BaseHTTPRequestHandler, HTTPServer
from constants import CAS_BASE_URL, SERVICE_SLO_URL
from utils import validate_ticket_to_cas, handle_logout_request, send_logout_status

urllib3.disable_warnings()

data={}

class RequestHandler(BaseHTTPRequestHandler):

def do_GET(self):
if "checkLogout" in self.path:
send_logout_status(self, data["logged_in"])
else:
validate_ticket_to_cas(self, SERVICE_SLO_URL, CAS_BASE_URL)
data["logged_in"] = True

def do_POST(self):
data["logged_in"] = handle_logout_request(self)

def run(server_class=HTTPServer, handler_class=RequestHandler, port=8019):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print(f'Starting server on port {port}...')
httpd.serve_forever()

if __name__ == '__main__':
run()
24 changes: 24 additions & 0 deletions ci/python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,27 @@ def validate_ticket_to_cas_and_return_attributes(request_handler, service_url, c
request_handler.send_response(404)
request_handler.end_headers()
request_handler.wfile.write(b'404 Not Found')

def handle_logout_request(request_handler):
"""
Méthode pour traiter une requête de logout envoyée par le serveur CAS.
Retourne un booléen à False si la déconnexion a été réalisée.
"""
# Récupérer le contenu de la requête
content_length = int(request_handler.headers['Content-Length'])
post_data = request_handler.rfile.read(content_length)
post_data = post_data.decode('utf-8')
# Si logoutRequest est dans le contenu alors c'est OK
if "logoutRequest" in post_data:
return False
return True

def send_logout_status(request_handler, is_logged_in):
"""
Méthode pour envoyer au client de test le statut actuel de la session (connecté ou non).
Se base sur le paramètre is_logged_in qui tracke la connexion.
"""
request_handler.send_response(200)
request_handler.send_header('Content-type', 'text/html')
request_handler.end_headers()
request_handler.wfile.write(f"LOGGED IN={is_logged_in}".encode('utf-8'))
3 changes: 3 additions & 0 deletions puppeteer/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ python3 service_test10.py &
pid_python_service_test10=$!
python3 service_test16.py &
pid_python_service_test16=$!
python3 service_test19.py &
pid_python_service_test19=$!
python3 structs_info_api.py &
pid_python_structs_info_api=$!
python3 externalid_api.py &
Expand Down Expand Up @@ -159,6 +161,7 @@ kill -9 "$pid_python_service_test1"
kill -9 "$pid_python_service_test2"
kill -9 "$pid_python_service_test10"
kill -9 "$pid_python_service_test16"
kill -9 "$pid_python_service_test19"
kill -9 "$pid_python_structs_info_api"
kill -9 "$pid_python_externalid_api"
kill -9 "$pid_python_saml_client"
Expand Down
38 changes: 38 additions & 0 deletions puppeteer/scenarios/slo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const cas = require("../cas.js");
const puppeteer = require('puppeteer');
const assert = require("assert");

(async () => {
const browser = await puppeteer.launch(cas.browserOptions());

try {
const page = await browser.newPage();
const client = await page.createCDPSession();
const casHost = "https://localhost:8443";
const service = "http://localhost:8019"

// Login to cas
await cas.loginWith(page, casHost, service+"/test", "test1", "test")

// Assert that user is connected
await cas.verifyTGC(client)

// Logout from CAS
await page.goto(`${casHost}/cas/logout`);

// Get logout status from app
await page.goto(service+"/checkLogout");

// Assert that the user is logged out of the app
const pageContent = await page.content();
assert(pageContent.includes("LOGGED IN=False"))

process.exit(0)

} catch (e) {
cas.loge(e);
process.exit(1)
} finally {
await browser.close();
}
})();

0 comments on commit debd73d

Please sign in to comment.