Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(uve): Fixed API button on toolbar #31136

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,75 @@ describe('DotEmaShellComponent', () => {
expect(spyStoreLoadPage).toHaveBeenCalledWith(INITIAL_PAGE_PARAMS);
});

describe('Sanitize url when called loadPageAsset', () => {
it('should sanitize when url is index', () => {
const spyloadPageAsset = jest.spyOn(store, 'loadPageAsset');
KevinDavilaDotCMS marked this conversation as resolved.
Show resolved Hide resolved
const spyLocation = jest.spyOn(location, 'go');

const params = {
...INITIAL_PAGE_PARAMS,
url: '/index'
};

overrideRouteSnashot(
activatedRoute,
SNAPSHOT_MOCK({ queryParams: params, data: UVE_CONFIG_MOCK(BASIC_OPTIONS) })
);

spectator.detectChanges();
expect(spyloadPageAsset).toHaveBeenCalledWith({ ...params, url: 'index' });
expect(spyLocation).toHaveBeenCalledWith(
'/?language_id=1&url=index&variantName=DEFAULT&com.dotmarketing.persona.id=modes.persona.no.persona&editorMode=edit'
);
});

it('should sanitize when url is nested', () => {
const spyloadPageAsset = jest.spyOn(store, 'loadPageAsset');

const spyLocation = jest.spyOn(location, 'go');

const params = {
...INITIAL_PAGE_PARAMS,
url: '/some-url/some-nested-url/'
};

overrideRouteSnashot(
activatedRoute,
SNAPSHOT_MOCK({ queryParams: params, data: UVE_CONFIG_MOCK(BASIC_OPTIONS) })
);

spectator.detectChanges();
expect(spyloadPageAsset).toHaveBeenCalledWith({
...params,
url: 'some-url/some-nested-url'
});
expect(spyLocation).toHaveBeenCalledWith(
'/?language_id=1&url=some-url%2Fsome-nested-url&variantName=DEFAULT&com.dotmarketing.persona.id=modes.persona.no.persona&editorMode=edit'
);
});

it('should sanitize when url is nested and ends in index', () => {
const spyloadPageAsset = jest.spyOn(store, 'loadPageAsset');
const spyLocation = jest.spyOn(location, 'go');

const params = {
...INITIAL_PAGE_PARAMS,
url: '/some-url/index'
};

overrideRouteSnashot(
activatedRoute,
SNAPSHOT_MOCK({ queryParams: params, data: UVE_CONFIG_MOCK(BASIC_OPTIONS) })
);

spectator.detectChanges();
expect(spyloadPageAsset).toHaveBeenCalledWith({ ...params, url: 'some-url/' });
expect(spyLocation).toHaveBeenCalledWith(
'/?language_id=1&url=some-url%2F&variantName=DEFAULT&com.dotmarketing.persona.id=modes.persona.no.persona&editorMode=edit'
);
});
});

it('should patch viewParams with empty object when the editorMode is edit', () => {
const patchViewParamsSpy = jest.spyOn(store, 'patchViewParams');
const params = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
checkClientHostAccess,
getAllowedPageParams,
getTargetUrl,
sanitizeURL,
shouldNavigate
} from '../utils';

Expand Down Expand Up @@ -209,6 +210,9 @@ export class DotEmaShellComponent implements OnInit {
const params = getAllowedPageParams(queryParams);
const validHost = checkClientHostAccess(params.clientHost, allowedDevURLs);

//Sanitize the url
params.url = sanitizeURL(params.url);

if (!validHost) {
delete params.clientHost;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,7 @@ describe('EditEmaGuard', () => {
expect(didEnteredPortlet).toBe(true);
});

it('should navigate to "edit-page" and sanitize url', () => {
const route: ActivatedRouteSnapshot = {
firstChild: {
url: [{ path: 'content' }]
},
queryParams: { url: '/some-url/with-index/index' }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;

TestBed.runInInjectionContext(() => editEmaGuard(route, state) as Observable<boolean>);

expect(router.navigate).toHaveBeenCalledWith(['/edit-page/content'], {
queryParams: {
'com.dotmarketing.persona.id': 'modes.persona.no.persona',
language_id: 1,
url: 'some-url/with-index/'
},
replaceUrl: true
});
});

it('should navigate to "edit-page" and sanitize url when the url is "/"', () => {
it('should navigate to "edit-page" with url as "index" when the initial url queryParam is "/"', () => {
const route: ActivatedRouteSnapshot = {
firstChild: {
url: [{ path: 'content' }]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { inject } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivateFn, Params, Router } from '@angular/router';

import { DEFAULT_PERSONA } from '../../shared/consts';
import { sanitizeURL } from '../../utils';

type EmaQueryParams = {
url: string;
Expand Down Expand Up @@ -44,19 +43,11 @@ function confirmQueryParams(queryParams: Params): {
return acc;
}

// Handle URL parameter special cases
if (key === 'url') {
if (queryParams[key] !== 'index' && queryParams[key].endsWith('/index')) {
acc[key] = sanitizeURL(queryParams[key]);
acc.missing = true;
}

if (queryParams[key] === '/') {
acc[key] = 'index';
acc.missing = true;
if (key === 'url' && queryParams[key] === '/') {
acc[key] = 'index';
acc.missing = true;

return acc;
}
return acc;
}

return acc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function withLoad() {
return of(pageAsset);
}

// Maybe we can use retryWhen() instead of this navigate.
const url = vanityUrl.forwardTo.replace('/', '');
router.navigate([], {
queryParamsHandling: 'merge',
Expand Down