|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +const fs = require('fs'); |
| 19 | +const os = require('os'); |
| 20 | +const path = require('path'); |
| 21 | +const { getExportedFile } = require('../desktopPaths'); |
| 22 | + |
| 23 | +describe('desktop static export paths', () => { |
| 24 | + const exportRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'casbin-editor-paths-')); |
| 25 | + |
| 26 | + beforeAll(() => { |
| 27 | + fs.mkdirSync(path.join(exportRoot, '_next')); |
| 28 | + fs.writeFileSync(path.join(exportRoot, 'index.html'), 'editor'); |
| 29 | + fs.writeFileSync(path.join(exportRoot, 'gallery.html'), 'gallery'); |
| 30 | + fs.writeFileSync(path.join(exportRoot, 'github.svg'), '<svg/>'); |
| 31 | + fs.writeFileSync(path.join(exportRoot, '_next', 'chunk.js'), 'chunk'); |
| 32 | + }); |
| 33 | + |
| 34 | + afterAll(() => { |
| 35 | + fs.rmSync(exportRoot, { recursive: true }); |
| 36 | + }); |
| 37 | + |
| 38 | + test.each([ |
| 39 | + ['app://editor/', 'index.html'], |
| 40 | + ['app://editor/gallery', 'gallery.html'], |
| 41 | + ['app://editor/github.svg', 'github.svg'], |
| 42 | + ['app://editor/_next/chunk.js?v=1', '_next/chunk.js'], |
| 43 | + ])('serves %s from the exported bundle', (url, file) => { |
| 44 | + expect(getExportedFile(url, exportRoot)).toBe(path.join(exportRoot, file)); |
| 45 | + }); |
| 46 | + |
| 47 | + test.each([ |
| 48 | + 'https://editor/github.svg', |
| 49 | + 'app://other/github.svg', |
| 50 | + 'app://editor/%2e%2e%2foutside.txt', |
| 51 | + 'app://editor/%5coutside.txt', |
| 52 | + 'app://editor/%00outside.txt', |
| 53 | + 'app://editor/%E0%A4', |
| 54 | + 'invalid url', |
| 55 | + 'app://editor/missing.js', |
| 56 | + ])('does not serve %s', (url) => { |
| 57 | + expect(getExportedFile(url, exportRoot)).toBeNull(); |
| 58 | + }); |
| 59 | +}); |
0 commit comments