2019-02-12 22:57:09 +00:00
|
|
|
import Request from 'request-promise';
|
|
|
|
|
|
|
|
async function GetSecret(username: string, password: string) {
|
2019-03-03 22:51:52 +00:00
|
|
|
return await Request('https://singlefactor.example.com:8080/secret.html', {
|
2019-02-12 22:57:09 +00:00
|
|
|
auth: {
|
|
|
|
username,
|
|
|
|
password
|
|
|
|
},
|
|
|
|
rejectUnauthorized: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function() {
|
2019-03-26 20:00:47 +00:00
|
|
|
it("should retrieve secret when Proxy-Authorization header is provided", async function() {
|
2019-02-12 22:57:09 +00: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.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|