mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Sanitize db name for dacpac/bacpac file names (#5479)
* Sanitize db name for filename * Add unit tests * lower timeout to 60 seconds * add extra coverageConfig.json and missing character check
This commit is contained in:
47
extensions/dacpac/src/test/dacpac.test.ts
Normal file
47
extensions/dacpac/src/test/dacpac.test.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import 'mocha';
|
||||
import * as should from 'should';
|
||||
import * as os from 'os';
|
||||
import { isValidFilenameCharacter, sanitizeStringForFilename } from '../wizard/api/utils';
|
||||
|
||||
|
||||
describe('Sanitize database name for filename tests', function (): void {
|
||||
it('Should only validate if one character is passed', async () => {
|
||||
should(isValidFilenameCharacter(null)).equal(false);
|
||||
should(isValidFilenameCharacter('')).equal(false);
|
||||
should(isValidFilenameCharacter('abc')).equal(false);
|
||||
should(isValidFilenameCharacter('c')).equal(true);
|
||||
});
|
||||
|
||||
it('Should determine invalid file name characters', async () => {
|
||||
// invalid for both Windows and non-Windows
|
||||
should(isValidFilenameCharacter('\\')).equal(false);
|
||||
should(isValidFilenameCharacter('/')).equal(false);
|
||||
});
|
||||
|
||||
it('Should determine invalid Windows file name characters', async () => {
|
||||
let isWindows = os.platform() === 'win32';
|
||||
|
||||
// invalid only for Windows
|
||||
should(isValidFilenameCharacter('?')).equal(isWindows ? false : true);
|
||||
should(isValidFilenameCharacter(':')).equal(isWindows ? false : true);
|
||||
should(isValidFilenameCharacter('*')).equal(isWindows ? false : true);
|
||||
should(isValidFilenameCharacter('<')).equal(isWindows ? false : true);
|
||||
should(isValidFilenameCharacter('>')).equal(isWindows ? false : true);
|
||||
should(isValidFilenameCharacter('|')).equal(isWindows ? false : true);
|
||||
should(isValidFilenameCharacter('"')).equal(isWindows ? false : true);
|
||||
});
|
||||
|
||||
it('Should sanitize database name for filename', async () => {
|
||||
let invalidDbName = '"in|valid*<>db/?name';
|
||||
let expectedWindows = '_in_valid___db__name';
|
||||
let expectedNonWindows = '"in|valid*<>db_?name';
|
||||
let isWindows = os.platform() === 'win32';
|
||||
should(sanitizeStringForFilename(invalidDbName)).equal(isWindows ? expectedWindows : expectedNonWindows);
|
||||
});
|
||||
});
|
||||
34
extensions/dacpac/src/test/index.ts
Normal file
34
extensions/dacpac/src/test/index.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
const path = require('path');
|
||||
import * as testRunner from 'vscodetestcover';
|
||||
|
||||
const suite = 'DacFx Tests';
|
||||
|
||||
const testOptions: any = {
|
||||
ui: 'bdd',
|
||||
useColors: true,
|
||||
timeout: 60000
|
||||
};
|
||||
|
||||
const coverageConfig: any = {
|
||||
coverConfig: '../../coverageConfig.json'
|
||||
};
|
||||
|
||||
if (process.env.BUILD_ARTIFACTSTAGINGDIRECTORY) {
|
||||
testOptions.reporter = 'mocha-multi-reporters';
|
||||
testOptions.reporterOptions = {
|
||||
reporterEnabled: 'spec, mocha-junit-reporter',
|
||||
mochaJunitReporterReporterOptions: {
|
||||
testsuitesTitle: `${suite} ${process.platform}`,
|
||||
mochaFile: path.join(process.env.BUILD_ARTIFACTSTAGINGDIRECTORY, `test-results/${process.platform}-${suite.toLowerCase().replace(/[^\w]/g, '-')}-results.xml`)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
testRunner.configure(testOptions, coverageConfig);
|
||||
|
||||
export = testRunner;
|
||||
Reference in New Issue
Block a user