Skip to content

Commit

Permalink
fix:proxy call for CORS disabled domain for Model layer (#10745)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowheat02 authored Jan 15, 2025
1 parent 779416d commit 78b7da3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
35 changes: 35 additions & 0 deletions web/client/components/map/cesium/__tests__/Layer-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ import '../plugins/WFSLayer';
import '../plugins/TerrainLayer';
import '../plugins/ElevationLayer';
import '../plugins/ArcGISLayer';
import '../plugins/ModelLayer';

import {setStore} from '../../../../utils/SecurityUtils';
import ConfigUtils from '../../../../utils/ConfigUtils';
import MockAdapter from 'axios-mock-adapter';
import axios from '../../../../libs/ajax';


describe('Cesium layer', () => {
let map;
Expand Down Expand Up @@ -1741,4 +1745,35 @@ describe('Cesium layer', () => {
done();
}).catch(done);
});

it('ensure proxy usage in Model layer', (done) => {
const options = {
type: "model",
// url that fails
url: "https://test-CORS/FontaneMarosegeoreferenziato.ifc",
visibility: true,
format: 'ifc'
};

// Create a mock adapter for axios
const mockAxios = new MockAdapter(axios);

ReactDOM.render(
<CesiumLayer
type={options.type}
options={options}
map={map}
/>, document.getElementById('container'));


setTimeout(() => {
// Check if the API call was made
expect(mockAxios.history.get.length).toBe(1);
// ensure calling from proxy URL (CORS test is performed on fetch before this call)
expect(mockAxios.history.get[0].url.includes('/proxy')).toBe(true); // Check the URL
expect(mockAxios.history.get[0].url.includes('?url=https%3A%2F%2Ftest-cors%2FFontaneMarosegeoreferenziato.ifc')).toBe(true);
mockAxios.restore(); // Restore the original axios instance
done();
}, 1000);
});
});
5 changes: 4 additions & 1 deletion web/client/components/map/cesium/plugins/ModelLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,13 @@ const createLayer = (options, map) => {

Layers.registerType('model', {
create: createLayer,
update: (layer, newOptions, oldOptions) => {
update: (layer, newOptions, oldOptions, map) => {
if (layer?.primitives && !isEqual(newOptions?.features?.[0], oldOptions?.features?.[0])) {
updatePrimitivesMatrix(layer?.primitives, newOptions?.features?.[0]);
}
if (newOptions?.forceProxy !== oldOptions?.forceProxy) {
return createLayer(newOptions, map);
}
return null;
}
});

0 comments on commit 78b7da3

Please sign in to comment.