mirror of
https://github.com/apache/superset.git
synced 2026-04-24 18:44:53 +00:00
fix(superset-ui-core): Include appRoot in endpoint of SupersetClientClass.postForm action (#34395)
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
import { LOGIN } from 'cypress/utils/urls';
|
||||
|
||||
function interceptLogin() {
|
||||
cy.intercept('POST', '/login/').as('login');
|
||||
cy.intercept('POST', '**/login/').as('login');
|
||||
}
|
||||
|
||||
describe('Login view', () => {
|
||||
|
||||
@@ -115,11 +115,15 @@ export default class SupersetClientClass {
|
||||
return this.getCSRFToken();
|
||||
}
|
||||
|
||||
async postForm(url: string, payload: Record<string, any>, target = '_blank') {
|
||||
if (url) {
|
||||
async postForm(
|
||||
endpoint: string,
|
||||
payload: Record<string, any>,
|
||||
target = '_blank',
|
||||
) {
|
||||
if (endpoint) {
|
||||
await this.ensureAuth();
|
||||
const hiddenForm = document.createElement('form');
|
||||
hiddenForm.action = url;
|
||||
hiddenForm.action = this.getUrl({ endpoint });
|
||||
hiddenForm.method = 'POST';
|
||||
hiddenForm.target = target;
|
||||
const payloadWithToken: Record<string, any> = {
|
||||
|
||||
@@ -658,26 +658,36 @@ describe('SupersetClientClass', () => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('makes postForm request', async () => {
|
||||
await client.postForm(mockPostFormUrl, {});
|
||||
it.each(['', '/prefix'])(
|
||||
"makes postForm request when appRoot is '%s'",
|
||||
async appRoot => {
|
||||
if (appRoot !== '') {
|
||||
client = new SupersetClientClass({ protocol, host, appRoot });
|
||||
authSpy = jest.spyOn(SupersetClientClass.prototype, 'ensureAuth');
|
||||
await client.init();
|
||||
}
|
||||
await client.postForm(mockPostFormEndpoint, {});
|
||||
|
||||
const hiddenForm = createElement.mock.results[0].value;
|
||||
const csrfTokenInput = createElement.mock.results[1].value;
|
||||
const hiddenForm = createElement.mock.results[0].value;
|
||||
const csrfTokenInput = createElement.mock.results[1].value;
|
||||
|
||||
expect(createElement.mock.calls).toHaveLength(2);
|
||||
expect(createElement.mock.calls).toHaveLength(2);
|
||||
|
||||
expect(hiddenForm.action).toBe(mockPostFormUrl);
|
||||
expect(hiddenForm.method).toBe('POST');
|
||||
expect(hiddenForm.target).toBe('_blank');
|
||||
expect(hiddenForm.action).toBe(
|
||||
`${protocol}//${host}${appRoot}${mockPostFormEndpoint}`,
|
||||
);
|
||||
expect(hiddenForm.method).toBe('POST');
|
||||
expect(hiddenForm.target).toBe('_blank');
|
||||
|
||||
expect(csrfTokenInput.type).toBe('hidden');
|
||||
expect(csrfTokenInput.name).toBe('csrf_token');
|
||||
expect(csrfTokenInput.value).toBe(1234);
|
||||
expect(csrfTokenInput.type).toBe('hidden');
|
||||
expect(csrfTokenInput.name).toBe('csrf_token');
|
||||
expect(csrfTokenInput.value).toBe(1234);
|
||||
|
||||
expect(appendChild.mock.calls).toHaveLength(1);
|
||||
expect(removeChild.mock.calls).toHaveLength(1);
|
||||
expect(authSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
expect(appendChild.mock.calls).toHaveLength(1);
|
||||
expect(removeChild.mock.calls).toHaveLength(1);
|
||||
expect(authSpy).toHaveBeenCalledTimes(1);
|
||||
},
|
||||
);
|
||||
|
||||
it('makes postForm request with guest token', async () => {
|
||||
client = new SupersetClientClass({ protocol, host, guestToken });
|
||||
|
||||
Reference in New Issue
Block a user