scaffolder-backend: fix file protocol check

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-04-08 11:05:45 +02:00
parent b109375902
commit 7abec4dbcf
3 changed files with 32 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': patch
---
Fix for the `file://` protocol check in the `FilePreparer` being too strict, breaking Windows.
@@ -31,7 +31,7 @@ describe('File preparer', () => {
const targetPath = path.resolve(workspacePath, 'template');
await preparer.prepare({
url: `file:///${root}path/to/template`,
url: `file://${root}path/to/template`,
logger,
workspacePath,
});
@@ -46,12 +46,34 @@ describe('File preparer', () => {
await expect(
preparer.prepare({
url: 'file://not/full/path',
url: 'http://not/file/path',
logger,
workspacePath,
}),
).rejects.toThrow(
"Wrong location protocol, should be 'file', file://not/full/path",
"Wrong location protocol, should be 'file', http://not/file/path",
);
if (os.platform() === 'win32') {
// eslint-disable-next-line jest/no-conditional-expect
await expect(
preparer.prepare({
url: 'file:///unix/file/path',
logger,
workspacePath,
}),
).rejects.toThrow('File URL path must be absolute');
} else {
// eslint-disable-next-line jest/no-conditional-expect
await expect(
preparer.prepare({
url: 'file://not/full/path',
logger,
workspacePath,
}),
).rejects.toThrow(
`File URL host must be "localhost" or empty on ${os.platform()}`,
);
}
});
});
@@ -25,11 +25,11 @@ export class FilePreparer implements PreparerBase {
throw new InputError(`Wrong location protocol, should be 'file', ${url}`);
}
const templatePath = fileURLToPath(url);
const targetDir = path.join(workspacePath, 'template');
await fs.ensureDir(targetDir);
const templatePath = fileURLToPath(url);
await fs.copy(templatePath, targetDir, {
recursive: true,
});