-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ajout test d'intégration SLO classique
- Loading branch information
1 parent
7ea0949
commit debd73d
Showing
5 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
})(); |