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:
kisantia
2019-05-14 15:00:28 -07:00
committed by GitHub
parent be60ad6766
commit 48ba9ce175
12 changed files with 1496 additions and 6 deletions

View 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);
});
});

View 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;