authelia/test/features/step_definitions/authelia.ts
Clement Michaud 6586402114 Support 'redirect' in /api/verify endpoint to support Traefik
Traefik handles auth forwarding but does not manage redirections like Nginx.
Therefore, Authelia must redirect the user and Traefik will forward this
request.

To support both Nginx and Traefik, /api/verify is now configurable with the
'redirect' get parameter. If the verification fails and 'redirect' is not
provided the response will be a 401 error as before.
If the parameter is provided and set to any URL, the response will be a
redirection (302) to this URL.
2017-12-04 22:52:33 +01:00

51 lines
1.4 KiB
TypeScript

import Cucumber = require("cucumber");
import seleniumWebdriver = require("selenium-webdriver");
import Assert = require("assert");
import Request = require("request-promise");
import Bluebird = require("bluebird");
Cucumber.defineSupportCode(function ({ Given, When, Then, Before, After }) {
Before(function () {
this.jar = Request.jar();
})
When("I query {stringInDoubleQuotes}", function (url: string) {
const that = this;
return Request(url, { followRedirect: false })
.then(function(response) {
console.log(response);
that.response = response;
})
.catch(function(err: Error) {
that.error = err;
})
});
Then("I get error code 401", function() {
const that = this;
return new Bluebird(function(resolve, reject) {
if(that.error && that.error.statusCode == 401) {
resolve();
}
else {
if(that.response)
reject(new Error("No error thrown"));
else if(that.error.statusCode != 401)
reject(new Error("Error code != 401"));
}
});
});
Then("I get redirected to {stringInDoubleQuotes}", function(url: string) {
const that = this;
return new Bluebird(function(resolve, reject) {
if(that.error && that.error.statusCode == 302
&& that.error.message.indexOf(url) > -1) {
resolve();
}
else {
reject(new Error("Not redirected"));
}
});
})
});