diff --git a/test/suites/README.md b/test/suites/README.md new file mode 100644 index 00000000..6629a206 --- /dev/null +++ b/test/suites/README.md @@ -0,0 +1,55 @@ +# Authelia Suites + +Authelia is a single component in interaction with many others. Consequently, testing the features +is not as easy as we might think. Consequently, a suite is kind of a virtual environment for Authelia, +it allows to create an environment made of components such as nginx, redis or mongo in which Authelia can +run and be tested. + +This abstraction allows to prepare an environment for manual testing during development and also to +craft and run integration tests. + +## Start a suite. + +Starting a suite called *simple* is done with the following command: + + npm run scripts suites start simple + +It will start the suite and block until you hit ctrl-c to stop the suite. + +## Run tests of a suite + +### Run tests of running suite + +If you are already running a suite with the previous command, you can simply type: + + npm run scripts test + +and this will run the tests related to the running suite. + +### Run tests of non-running suite + +However, if no suite is running and you still want to test a particular suite like *complete*. +You can do so with the next command: + + npm run scripts test complete + +This command will run the tests for the *complete* suite using the built version of Authelia that +should be located in *dist*. + +WARNING: Authelia must be built before running this command. + +### Run all tests of all suites + +Running all tests is as easy as making sure that there is no running suite and typing: + + npm run scripts test + + +## Create a suite + +Creating a suite is as easy as creating a new directory with at least two files: + +* **environment.ts** - It defines the setup and teardown phases when creating the environment. The *setup* +phase is the phase when the required components will be spawned and Authelia will start while the *teardown* +is executed when the suite is destroyed (ctrl-c hit by the user). +* **test.ts** - It defines a set of tests to run in the virtual environment of the suite. \ No newline at end of file diff --git a/test/suites/basic/README.md b/test/suites/basic/README.md new file mode 100644 index 00000000..751dfbc5 --- /dev/null +++ b/test/suites/basic/README.md @@ -0,0 +1,13 @@ +# Basic suite + +This suite has been created to test Authelia with basic feature in a non highly-available setup. +Authelia basically use an in-memory cache to store user sessions and persist data on disk instead +of using a remote database. Also, the user accounts are stored in file-based database. + +## Components + +Authelia, nginx, fake webmail for registering devices. + +## Tests + +Broad range of tests. \ No newline at end of file diff --git a/test/suites/simple/config.yml b/test/suites/basic/config.yml similarity index 100% rename from test/suites/simple/config.yml rename to test/suites/basic/config.yml diff --git a/test/suites/simple/environment.ts b/test/suites/basic/environment.ts similarity index 100% rename from test/suites/simple/environment.ts rename to test/suites/basic/environment.ts diff --git a/test/suites/simple/scenarii/BackendProtection.ts b/test/suites/basic/scenarii/BackendProtection.ts similarity index 100% rename from test/suites/simple/scenarii/BackendProtection.ts rename to test/suites/basic/scenarii/BackendProtection.ts diff --git a/test/suites/simple/scenarii/BadPassword.ts b/test/suites/basic/scenarii/BadPassword.ts similarity index 100% rename from test/suites/simple/scenarii/BadPassword.ts rename to test/suites/basic/scenarii/BadPassword.ts diff --git a/test/suites/simple/scenarii/LogoutRedirectToAlreadyLoggedIn.ts b/test/suites/basic/scenarii/LogoutRedirectToAlreadyLoggedIn.ts similarity index 100% rename from test/suites/simple/scenarii/LogoutRedirectToAlreadyLoggedIn.ts rename to test/suites/basic/scenarii/LogoutRedirectToAlreadyLoggedIn.ts diff --git a/test/suites/simple/scenarii/RegisterTotp.ts b/test/suites/basic/scenarii/RegisterTotp.ts similarity index 100% rename from test/suites/simple/scenarii/RegisterTotp.ts rename to test/suites/basic/scenarii/RegisterTotp.ts diff --git a/test/suites/simple/scenarii/RequiredTwoFactor.ts b/test/suites/basic/scenarii/RequiredTwoFactor.ts similarity index 100% rename from test/suites/simple/scenarii/RequiredTwoFactor.ts rename to test/suites/basic/scenarii/RequiredTwoFactor.ts diff --git a/test/suites/simple/scenarii/ResetPassword.ts b/test/suites/basic/scenarii/ResetPassword.ts similarity index 100% rename from test/suites/simple/scenarii/ResetPassword.ts rename to test/suites/basic/scenarii/ResetPassword.ts diff --git a/test/suites/simple/scenarii/SimpleAuthentication.ts b/test/suites/basic/scenarii/SimpleAuthentication.ts similarity index 100% rename from test/suites/simple/scenarii/SimpleAuthentication.ts rename to test/suites/basic/scenarii/SimpleAuthentication.ts diff --git a/test/suites/simple/scenarii/TOTPValidation.ts b/test/suites/basic/scenarii/TOTPValidation.ts similarity index 100% rename from test/suites/simple/scenarii/TOTPValidation.ts rename to test/suites/basic/scenarii/TOTPValidation.ts diff --git a/test/suites/simple/scenarii/VerifyEndpoint.ts b/test/suites/basic/scenarii/VerifyEndpoint.ts similarity index 100% rename from test/suites/simple/scenarii/VerifyEndpoint.ts rename to test/suites/basic/scenarii/VerifyEndpoint.ts diff --git a/test/suites/simple/test.ts b/test/suites/basic/test.ts similarity index 100% rename from test/suites/simple/test.ts rename to test/suites/basic/test.ts diff --git a/test/suites/docker/config.yml b/test/suites/docker/config.yml deleted file mode 100644 index 7920a409..00000000 --- a/test/suites/docker/config.yml +++ /dev/null @@ -1,110 +0,0 @@ -############################################################### -# Authelia minimal configuration # -############################################################### - -port: 9091 - -logs_level: debug - -default_redirection_url: https://home.example.com:8080/ - -authentication_backend: - file: - path: ./users_database.yml - -session: - secret: unsecure_session_secret - domain: example.com - inactivity: 5000 - expiration: 8000 - -# Configuration of the storage backend used to store data and secrets. i.e. totp data -storage: - local: - path: /tmp/authelia/db - -# TOTP Issuer Name -# -# This will be the issuer name displayed in Google Authenticator -# See: https://github.com/google/google-authenticator/wiki/Key-Uri-Format for more info on issuer names -totp: - issuer: example.com - -# Access Control -# -# Access control is a set of rules you can use to restrict user access to certain -# resources. -access_control: - # Default policy can either be `bypass`, `one_factor`, `two_factor` or `deny`. - default_policy: deny - - rules: - - domain: single_factor.example.com - policy: one_factor - - - domain: '*.example.com' - subject: "group:admins" - policy: two_factor - - - domain: dev.example.com - resources: - - '^/users/john/.*$' - subject: "user:john" - policy: two_factor - - - domain: dev.example.com - resources: - - '^/users/harry/.*$' - subject: "user:harry" - policy: two_factor - - - domain: '*.mail.example.com' - subject: "user:bob" - policy: two_factor - - - domain: dev.example.com - resources: - - '^/users/bob/.*$' - subject: "user:bob" - policy: two_factor - - -# Configuration of the authentication regulation mechanism. -regulation: - # Set it to 0 to disable max_retries. - max_retries: 3 - - # The user is banned if the authenticaction failed `max_retries` times in a `find_time` seconds window. - find_time: 10 - - # The length of time before a banned user can login again. - ban_time: 5 - -# Default redirection URL -# -# Note: this parameter is optional. If not provided, user won't -# be redirected upon successful authentication. -#default_redirection_url: https://authelia.example.domain - -notifier: - # For testing purpose, notifications can be sent in a file - # filesystem: - # filename: /tmp/authelia/notification.txt - - # Use your email account to send the notifications. You can use an app password. - # List of valid services can be found here: https://nodemailer.com/smtp/well-known/ - ## email: - ## username: user@example.com - ## password: yourpassword - ## sender: admin@example.com - ## service: gmail - - # Use a SMTP server for sending notifications - smtp: - username: test - password: password - secure: false - host: 127.0.0.1 - port: 1025 - sender: admin@example.com - diff --git a/test/suites/docker/environment.ts b/test/suites/docker/environment.ts deleted file mode 100644 index e9aa70e6..00000000 --- a/test/suites/docker/environment.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { exec } from '../../helpers/utils/exec'; -import ChildProcess from 'child_process'; - -async function setup() { - await exec('docker run -d -v $(pwd)/config.yml:/etc/authelia/config.yml --name authelia-test clems4ever/authelia > /dev/null'); - console.log('Container has been spawned.'); -} - -async function teardown() { - try { - ChildProcess.execSync('docker ps | grep "authelia-test"'); - await exec('docker rm -f authelia-test > /dev/null'); - } catch (e) { - // If grep does not find anything, execSync throws an exception since the command returns 1. - } -} - -export { setup, teardown }; \ No newline at end of file diff --git a/test/suites/docker/test.ts b/test/suites/docker/test.ts deleted file mode 100644 index 3004fccb..00000000 --- a/test/suites/docker/test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import ChildProcess from 'child_process'; -import Bluebird from 'bluebird'; -import Assert from 'assert'; -import sleep from '../../helpers/utils/sleep'; -import AutheliaSuite from '../../helpers/context/AutheliaSuite'; - -const execAsync = Bluebird.promisify(ChildProcess.exec); - -AutheliaSuite('Test docker container runs as expected', __dirname, function() { - this.timeout(15000); - - it('should be running', async function() { - await sleep(5000); - const output: string = await execAsync('docker ps -a | grep "authelia-test"'); - Assert(output.match(new RegExp('Up [0-9]+ seconds'))); - }); -}); \ No newline at end of file diff --git a/test/suites/dockerhub/README.md b/test/suites/dockerhub/README.md new file mode 100644 index 00000000..15326855 --- /dev/null +++ b/test/suites/dockerhub/README.md @@ -0,0 +1,13 @@ +# Dockerhub suite + +This suite is made to quickly test that the Docker image of Authelia runs properly when spawned. +It can also be used for you to test Authelia without building it since the latest image will be +pulled from Dockerhub. + +## Components + +This suite will spawn an highly-available setup with nginx, mongo, redis, OpenLDAP, etc... + +## Tests + +Check if the image runs and does not crash unexpectedly and do a simple authentication with 2FA. \ No newline at end of file diff --git a/test/suites/high-availability/README.md b/test/suites/high-availability/README.md new file mode 100644 index 00000000..e2c34e02 --- /dev/null +++ b/test/suites/high-availability/README.md @@ -0,0 +1,15 @@ +# High-availability suite + +This suite is made to test Authelia in a *complete* environment, that is, with +all components making Authelia highly available. + +## Components + +This suite will spawn nginx as the edge reverse proxy, redis and mongo for storing +user sessions and configurations, LDAP for storing user accounts and authenticating, +as well as a few helpers such as a fake webmail to receive e-mails sent by Authelia +and httpbin to check headers forwarded by Authelia. + +## Tests + +There is broad range of tests in this suite. Check out in the *scenarii* directory. \ No newline at end of file diff --git a/test/suites/complete/config.yml b/test/suites/high-availability/config.yml similarity index 100% rename from test/suites/complete/config.yml rename to test/suites/high-availability/config.yml diff --git a/test/suites/complete/environment.ts b/test/suites/high-availability/environment.ts similarity index 100% rename from test/suites/complete/environment.ts rename to test/suites/high-availability/environment.ts diff --git a/test/suites/complete/scenarii/AccessControl.ts b/test/suites/high-availability/scenarii/AccessControl.ts similarity index 100% rename from test/suites/complete/scenarii/AccessControl.ts rename to test/suites/high-availability/scenarii/AccessControl.ts diff --git a/test/suites/complete/scenarii/AutheliaRestart.ts b/test/suites/high-availability/scenarii/AutheliaRestart.ts similarity index 100% rename from test/suites/complete/scenarii/AutheliaRestart.ts rename to test/suites/high-availability/scenarii/AutheliaRestart.ts diff --git a/test/suites/complete/scenarii/AuthenticationRegulation.ts b/test/suites/high-availability/scenarii/AuthenticationRegulation.ts similarity index 100% rename from test/suites/complete/scenarii/AuthenticationRegulation.ts rename to test/suites/high-availability/scenarii/AuthenticationRegulation.ts diff --git a/test/suites/complete/scenarii/BasicAuthentication.ts b/test/suites/high-availability/scenarii/BasicAuthentication.ts similarity index 100% rename from test/suites/complete/scenarii/BasicAuthentication.ts rename to test/suites/high-availability/scenarii/BasicAuthentication.ts diff --git a/test/suites/complete/scenarii/CustomHeadersForwarded.ts b/test/suites/high-availability/scenarii/CustomHeadersForwarded.ts similarity index 100% rename from test/suites/complete/scenarii/CustomHeadersForwarded.ts rename to test/suites/high-availability/scenarii/CustomHeadersForwarded.ts diff --git a/test/suites/complete/scenarii/EnforceInternalRedirectionsOnly.ts b/test/suites/high-availability/scenarii/EnforceInternalRedirectionsOnly.ts similarity index 100% rename from test/suites/complete/scenarii/EnforceInternalRedirectionsOnly.ts rename to test/suites/high-availability/scenarii/EnforceInternalRedirectionsOnly.ts diff --git a/test/suites/complete/scenarii/MongoConnectionRecovery.ts b/test/suites/high-availability/scenarii/MongoConnectionRecovery.ts similarity index 100% rename from test/suites/complete/scenarii/MongoConnectionRecovery.ts rename to test/suites/high-availability/scenarii/MongoConnectionRecovery.ts diff --git a/test/suites/complete/scenarii/SingleFactorAuthentication.ts b/test/suites/high-availability/scenarii/SingleFactorAuthentication.ts similarity index 100% rename from test/suites/complete/scenarii/SingleFactorAuthentication.ts rename to test/suites/high-availability/scenarii/SingleFactorAuthentication.ts diff --git a/test/suites/complete/test.ts b/test/suites/high-availability/test.ts similarity index 100% rename from test/suites/complete/test.ts rename to test/suites/high-availability/test.ts diff --git a/test/suites/short-timeouts/README.md b/test/suites/short-timeouts/README.md new file mode 100644 index 00000000..049cd574 --- /dev/null +++ b/test/suites/short-timeouts/README.md @@ -0,0 +1,12 @@ +# Short timeouts suite + +This suite has been created to configure Authelia with short timeouts for sessions expiration +in order to test the inactivity feature and the remember me feature. + +## Components + +Authelia, nginx and a fake webmail for registering a device. + +## Tests + +Related to user inactivity. \ No newline at end of file