2019-02-13 05:57:09 +07:00
|
|
|
import Request from 'request-promise';
|
|
|
|
|
|
|
|
async function GetSecret(username: string, password: string) {
|
2019-03-04 05:51:52 +07:00
|
|
|
return await Request('https://singlefactor.example.com:8080/secret.html', {
|
2019-02-13 05:57:09 +07:00
|
|
|
auth: {
|
|
|
|
username,
|
|
|
|
password
|
|
|
|
},
|
|
|
|
rejectUnauthorized: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function() {
|
2019-03-27 03:00:47 +07:00
|
|
|
it("should retrieve secret when Proxy-Authorization header is provided", async function() {
|
2019-02-13 05:57:09 +07:00
|
|
|
const res = await GetSecret('john', 'password');
|
|
|
|
if (res.indexOf('This is a very important secret!') < 0) {
|
|
|
|
throw new Error('Cannot access secret.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not retrieve secret when providing bad password", async function() {
|
|
|
|
const res = await GetSecret('john', 'bad-password');
|
|
|
|
if (res.indexOf('This is a very important secret!') >= 0) {
|
|
|
|
throw new Error('Cannot access secret.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not retrieve secret when authenticating with unexisting user", async function() {
|
|
|
|
const res = await GetSecret('dontexist', 'password');
|
|
|
|
if (res.indexOf('This is a very important secret!') >= 0) {
|
|
|
|
throw new Error('Cannot access secret.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|