Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const logger = RequestLogger(/localhost/);
//[
// 'http://localhost:3000/idp/idx/introspect',
// 'https://localhost:3000/probe2000',
// 'https://localhost:3000/probe6511',
// 'https://localhost:3000/probe6512',
// 'https://localhost:3000/probe6513',
// 'https://localhost:3000/challenge2000',
// 'https://localhost:3000/challenge6511',
// 'https://localhost:3000/challenge6512',
// 'https://localhost:3000/challenge6513',
// ]);
let failureCount = 0;
const mock = RequestMock()
.onRequestTo('http://localhost:3000/idp/idx/introspect')
.respond(identifyWithDeviceProbingLoopback)
.onRequestTo('http://localhost:3000/idp/idx/authenticators/poll')
.respond((req, res) => {
res.statusCode = '200';
if (failureCount === 2) {
res.setBody(loopbackChallengeNotReceived);
} else {
res.setBody(identifyWithDeviceProbingLoopback);
}
})
.onRequestTo('http://localhost:2000/probe')
.respond(null, 500, { 'access-control-allow-origin': '*' })
.onRequestTo('http://localhost:6511/probe')
.respond(null, 500, { 'access-control-allow-origin': '*' })
.onRequestTo('http://localhost:6512/probe')
import IdentityPageObject from '../framework/page-objects/IdentityPageObject';
import SelectFactorPageObject from '../framework/page-objects/SelectFactorPageObject';
import { RequestMock } from 'testcafe';
import selectFactorAuthenticate from '../../../playground/mocks/idp/idx/data/select-factor-authenticate';
const mock = RequestMock()
.onRequestTo('http://localhost:3000/idp/idx')
.respond(selectFactorAuthenticate);
fixture(`Select Factor Form`)
.requestHooks(mock);
async function setup(t) {
const identityPage = new IdentityPageObject(t);
await identityPage.navigateToPage();
await identityPage.fillIdentifierField('Test Identifier');
await identityPage.clickNextButton();
return new SelectFactorPageObject(t);
}
test(`should load select factor list`, async t => {
const selectFactorPage = await setup(t);
import IdentityPageObject from '../framework/page-objects/IdentityPageObject';
import unknownUser from '../../../playground/mocks/idp/idx/data/unknown-user'
import { RequestMock } from 'testcafe';
const mock = RequestMock()
.onRequestTo('http://localhost:3000/idp/idx')
.respond(unknownUser)
fixture(`Unknown user form`)
.requestHooks(mock);
async function setup(t) {
const identityPage = new IdentityPageObject(t);
await identityPage.navigateToPage();
return identityPage;
}
test(`should show messages callout for unknown user`, async t => {
const identityPage = await setup(t);
await identityPage.fillIdentifierField('unknown');
await identityPage.clickNextButton();
import IdentityPageObject from '../framework/page-objects/IdentityPageObject';
import { ClientFunction, RequestMock } from 'testcafe';
import success from '../../../playground/mocks/idp/idx/data/success';
const mock = RequestMock()
.onRequestTo('http://localhost:3000/idp/idx')
.respond(success);
fixture(`Success Form`)
.requestHooks(mock);
async function setup(t) {
const identityPage = new IdentityPageObject(t);
await identityPage.navigateToPage();
return identityPage;
}
const getPageUrl = ClientFunction(() => window.location.href);
test(`should navigate to redirect link google.com after success`, async t => {
const identityPage = await setup(t);
await identityPage.fillIdentifierField('Test Identifier');
import IdentityPageObject from '../framework/page-objects/IdentityPageObject';
import ChallengeFactorPageObject from '../framework/page-objects/ChallengeFactorPageObject';
import { ClientFunction, RequestMock } from 'testcafe';
import factorRequiredPassword from '../../../playground/mocks/idp/idx/data/factor-verification-password';
import success from '../../../playground/mocks/idp/idx/data/success';
const mock = RequestMock()
.onRequestTo('http://localhost:3000/idp/idx')
.respond(factorRequiredPassword)
.onRequestTo('http://localhost:3000/idp/idx/challenge/answer')
.respond(success)
fixture(`Challenge Password Form`)
.requestHooks(mock)
async function setup(t) {
const identityPage = new IdentityPageObject(t);
await identityPage.navigateToPage();
await identityPage.fillIdentifierField('Challenge Password');
await identityPage.clickNextButton();
return new ChallengeFactorPageObject(t);
}
const getPageUrl = ClientFunction(() => window.location.href);
import TerminalPageObject from '../framework/page-objects/TerminalPageObject';
import { RequestMock } from 'testcafe';
import terminalReturnEmail from '../../../playground/mocks/idp/idx/data/terminal-return-email';
const mock = RequestMock()
.onRequestTo('http://localhost:3000/idp/idx/introspect')
.respond(terminalReturnEmail)
fixture(`Return Email Terminal`)
.requestHooks(mock)
async function setup(t) {
const terminalPage = new TerminalPageObject(t);
await terminalPage.navigateToPage();
return terminalPage;
}
test
(`show the correct content`, async t => {
const terminalPageObject = await setup(t);
await t.expect(terminalPageObject.getHeader()).eql('Email link (o*****m@abbott.dev)');
import IdentityPageObject from '../framework/page-objects/IdentityPageObject';
import ChallengeFactorPageObject from '../framework/page-objects/ChallengeFactorPageObject';
import { RequestMock, RequestLogger } from 'testcafe';
import magicLinkReturnTab from '../../../playground/mocks/idp/idx/data/terminal-return-email';
import magicLinkExpired from '../../../playground/mocks/idp/idx/data/terminal-return-expired-email';
import magicLinkEmailSent from '../../../playground/mocks/idp/idx/data/factor-verification-email';
const magicLinkReturnTabMock = RequestMock()
.onRequestTo('http://localhost:3000/idp/idx')
.respond(magicLinkReturnTab)
const magicLinkExpiredMock = RequestMock()
.onRequestTo('http://localhost:3000/idp/idx')
.respond(magicLinkExpired)
const magicLinkEmailSentMock = RequestMock()
.onRequestTo('http://localhost:3000/idp/idx')
.respond(magicLinkEmailSent)
const resendEmailMock = RequestMock()
.onRequestTo('http://localhost:3000/idp/idx/challenge/resend')
.respond(magicLinkEmailSent)
const logger = RequestLogger(/poll|resend/);
fixture(`Challenge Email Magic Link Form Content`)
async function setup(t) {
const identityPage = new IdentityPageObject(t);
await identityPage.navigateToPage();
await identityPage.fillIdentifierField('Challenge Email');
await identityPage.clickNextButton();
await waitForReact(180000);
};
export const fixtureAfterHook = async (ctx) => {
for (const request of logger.requests) {
if (fs.existsSync(`./testcafe/cachedAjax/${path2file(request.request.url)}.json`)) {
continue;
}
await fetchFromAPI(request.request.url);
await new Promise(res => setTimeout(res, 3000));
}
};
const mock = RequestMock()
.onRequestTo(/api.opendota.com\/api/).respond((req, res) => {
const data = fs.readFileSync(`./testcafe/cachedAjax/${path2file(req.url)}.json`, 'utf8');
res.headers['Access-Control-Allow-Origin'] = '*';
res.statusCode = 200;
res.setBody(data);
});
export const fixtureRequestHooks = [logger, mock];
`;
const requestMock = RequestMock()
.onRequestTo('http://dummy-url.com')
.respond(testPageMarkup)
.onRequestTo('http://dummy-url.com/get')
.respond('Data from mocked fetch request')
.onRequestTo('https://another-dummy-url.com')
.respond();
fixture `Basic`;
test
.requestHooks(requestMock)
('Basic', async t => {
await t
.navigateTo('http://dummy-url.com')
.expect(Selector('h1').textContent).eql('Mocked page')
.click('button')
}
async onResponse (event: object) {
}
}
const customHook = new CustomRequestHook();
const logger1 = RequestLogger('example.com', {logRequestBody: true});
const logger2 = RequestLogger(req => {
return req.url === 'example.com';
});
const mock = RequestMock()
.onRequestTo(/example.com/)
.respond()
.onRequestTo({url: 'https://example.com'})
.respond(null, 204)
.onRequestTo('https://example.com')
.respond(null, 200, {'x-frame-options': 'deny'})
.onRequestTo(req => {
return req.url === 'https://example.com';
}).respond((req, res) => {
if (req.url === 'https://example.com')
res.statusCode = '200';
});
fixture `Request Hooks`
.requestHooks(mock, logger1, logger2, customHook);