mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-22 07:01:09 +02:00
* update test helpers, export DELAY_IN_MS, make window event a helper * simplify auth method map helpers, move page tests into separate files * use new buttons * finish separating page tests * move test helpers back to relevant files * remove redundant oidc test * move misplaced linked block AUTH_FORM selector * i definitely already addressed these.. * comment meant remove "trailing" forward slash...lol * cleanup stubs
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
import sinon from 'sinon';
|
|
|
|
export const DELAY_IN_MS = 500;
|
|
|
|
// suggestions for a custom popup
|
|
// passing { close: true } automatically closes popups opened from window.open()
|
|
// passing { closed: true } sets value on popup window
|
|
export const windowStub = ({ stub, popup } = {}) => {
|
|
// if already stubbed, don't re-stub
|
|
const openStub = stub ? stub : sinon.stub(window, 'open');
|
|
|
|
const defaultPopup = { close: () => true };
|
|
openStub.returns(popup || defaultPopup);
|
|
return openStub;
|
|
};
|
|
|
|
export const buildMessage = (opts) => ({
|
|
isTrusted: true,
|
|
origin: 'https://my-vault.com',
|
|
data: callbackData(),
|
|
...opts,
|
|
});
|
|
|
|
export const callbackData = (data = {}) => ({
|
|
source: 'oidc-callback',
|
|
path: 'foo',
|
|
state: 'state',
|
|
code: 'code',
|
|
...data,
|
|
});
|
|
|
|
// Simulates the OIDC popup message event the OIDC auth method waits for
|
|
// mountPath is necessary because it builds the callback URL
|
|
export const triggerMessageEvent = (mountPath, delay = DELAY_IN_MS) => {
|
|
setTimeout(() => {
|
|
window.postMessage(callbackData({ path: mountPath }), window.origin);
|
|
}, delay);
|
|
};
|