This script aims at triggering a valid Roundcube login request, needed to trigger some Roundcube plugin functions (via Roundcube hooks like ready
).
It uses puppeteer
to start a headless chrome instance and watch/wait for conditionsn, and meow
to handle arguments.
Usage
$ npx --yes ts-node index.ts <options>
Options
--authType , -a 'Authentication type (Basic auth, Auth provider, etc)'
--host , -h 'Roundcube instance URL'
--username , -u 'Username of the (Roundcube or OAuth provider) account'
--password , -p 'Password of the (Roundcube or OAuth provider) account'
Examples
$ index.ts -a basic -h http://host.docker.internal:9000 -u [email protected] -p letmein
$ index.ts -a basic -h http://host.docker.internal:9000 -u [email protected] -p wrongpassword
Return code | Description |
---|---|
0 |
Roundcube connection done (valid credentials) |
1 |
An error occured (unknown error, not catched) |
2 |
Roundcube connection failed (invalid credentials, invalid host, config, etc) |
- Go to the Roundcube login page
- Wait/search for the login form/button
- Fill the
user
andpwd
fields - Submit the form
- Wait for 401 response (auth failed) OR 200 response on mails AND GET request on refresh (auth success)
- Go to the Roundcube login page (will redirect to Keycloak login page)
- Wait/search for the login form/button
- Fill the
username
andpassword
fields - Click the login button
- Wait for error on login form (auth failed) OR 200 response on mails AND GET request on refresh (auth success)
# Run an interactive Docker container with Chrome and Puppeteer
docker run -it --rm zenika/alpine-chrome:with-puppeteer /bin/sh
# Run the same Docker container, with the Typescript code/project as a volume
docker run -it --rm -v "$PWD/src/helpers/RoundcubeHelper":/usr/src/app zenika/alpine-chrome:with-puppeteer /bin/sh
# Call the project script, with `ts-node` to call Typescript code directly (TS to JS conversion)
npx --yes ts-node index.ts --auth-type basic --host http://host.docker.internal:9000 --username [email protected] --password letmein
# Run the same Docker container and call the script directly
docker run -it --rm -v "$PWD/src/helpers/RoundcubeHelper":/usr/src/app zenika/alpine-chrome:with-puppeteer npx --yes ts-node index.ts --auth-type basic --host http://host.docker.internal:9000 --username [email protected] --password letmein
# Get the result value (exit code)
echo $?
# Build the image
docker build -t apitech/roundcube-login-ts:1.0 .
# Use the image
docker run -it --rm apitech/roundcube-login-ts:1.0 --auth-type basic --host http://host.docker.internal:9000 --username [email protected] --password letmein
# Get the result value (exit code)
echo $?