Skip to content

Commit

Permalink
feat: possibilité de lancer les tests de bout en bout avec puppeteer
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancailbourdin committed Jun 20, 2024
1 parent 3d5f61c commit 9281c46
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ design your own test scenarios that verify functionality specific to your CAS de
To execute Puppeteer scenarios, run:

```bash
./puppeteer/run.sh
CAS_ARGS="-Dcom.sun.net.ssl.checkRevocation=false --spring.profiles.active=test" ./puppeteer/run.sh
```

This will first attempt to build your CAS deployment, will install Puppeteer and all other needed libraries. It will then launch the CAS server,
Expand Down
28 changes: 27 additions & 1 deletion puppeteer/run.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,39 @@ function printred() {
printf "${RED}$1${ENDCOLOR}\n"
}

# Faire un clean avant tout pour s'assurer qu'on rebuild bien le CAS s'il y a eu des modifs
echo "Cleaning last deployment..."
./gradlew clean

# Remplacer appServer= par appServer=-tomcat
casGradlePropertiesFile="${PWD}/gradle.properties"
if grep -q 'appServer=' "$casGradlePropertiesFile"; then
echo "Replacing 'appServer=' with 'appServer=-tomcat' in $casGradlePropertiesFile"
sed -i 's/appServer=/appServer=-tomcat/' "$casGradlePropertiesFile"
else
echo "'appServer=' not found or already replaced in $casGradlePropertiesFile"
fi

# Build le war du CAS
casWebApplicationFile="${PWD}/build/libs/cas.war"
if [[ ! -f "$casWebApplicationFile" ]]; then
echo "Building CAS"
./gradlew clean build -x test -x javadoc --no-configuration-cache --offline
./gradlew clean build -x test -x javadoc --no-configuration-cache
if [ $? -ne 0 ]; then
printred "Failed to build CAS"
exit 1
fi
fi

# Une fois le build fini on peut remettre le gradle.properties dans son état d'origine
if grep -q 'appServer=-tomcat' "$casGradlePropertiesFile"; then
echo "Replacing 'appServer=-tomcat' with 'appServer=' in $casGradlePropertiesFile"
sed -i 's/appServer=-tomcat/appServer=/' "$casGradlePropertiesFile"
else
echo "'appServer=-tomcat' not found or already replaced in $casGradlePropertiesFile"
fi

# Installation de puppeteer s'il n'est pas enore installé
if [[ ! -d "${PWD}/puppeteer/node_modules/puppeteer" ]]; then
echo "Installing Puppeteer"
(cd "${PWD}/puppeteer" && npm install puppeteer)
Expand All @@ -37,6 +60,7 @@ fi
echo -n "NPM version: " && npm --version
echo -n "Node version: " && node --version

# Lancement du serveur CAS grâce au war qu'on a construit plus haut
echo "Launching CAS at $casWebApplicationFile with options $CAS_ARGS"
java -jar "$casWebApplicationFile" $CAS_ARGS &
pid=$!
Expand All @@ -52,6 +76,7 @@ if [[ $? -ne 0 ]]; then
exit 1
fi

# Si on est sûr que le serveur CAS est lancé, alors on éxécute les scénarios puppeteer un par un
export NODE_TLS_REJECT_UNAUTHORIZED=0
echo "Executing puppeteer scenarios..."
for scenario in "${PWD}"/puppeteer/scenarios/*; do
Expand All @@ -71,5 +96,6 @@ for scenario in "${PWD}"/puppeteer/scenarios/*; do
sleep 1
done;

# On kill le serveur CAS avant de terminer le script
kill -9 "$pid"
exit 0
28 changes: 28 additions & 0 deletions src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Ce fichier contient les properties utilisées pour les tests avec puppeteer
cas.server.name: https://localhost:8443
cas.server.prefix: https://localhost:8443/cas
server.port: 8443
spring.main.lazy-initialization: false
management.endpoints.web.discovery.enabled: true
cas.audit.engine.enabled: true
cas.audit.slf4j.use-single-line: true
cas.monitor.endpoints.endpoint.defaults.access: ANONYMOUS
management.health.redis.enabled: true
management.health.redisHealthIndicator.enabled: true
management.endpoints.web.exposure.include: health,ssoSessions,ticketRegistry
management.endpoint.health.show-details: always
management.endpoints.enabled-by-default: true
cas.service-registry.redis.host: localhost
cas.service-registry.redis.port: 6379
cas.ticket.registry.redis.host: cas2
cas.ticket.registry.redis.port: 6379
cas.audit.redis.host: cas2
cas.audit.redis.port: 6379
cas.service-registry.core.init-from-json: false
cas.service-registry.git.repository-url: https://github.com/nathancailbourdin/cas-git-service-registry-test.git
cas.service-registry.git.active-branch: main
cas.service-registry.git.branches-to-clone: main
cas.service-registry.git.clone-directory.location: file:/tmp/cas-service-registry-test
cas.service-registry.schedule.start-delay: 10000
cas.service-registry.schedule.repeat-interval: 120000
cas.service-registry.cache.duration: 900000
3 changes: 1 addition & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Application properties that need to be
# embedded within the web application can be included here
# Application properties that need to be embedded within the web application can be included here
cas.standalone.configuration-directory: /home/esco/cas-properties

0 comments on commit 9281c46

Please sign in to comment.