-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2 - Use tedious mssql module instead of sqlcmd (#96)
* Use tedious mssql library instead of sqlcmd * Fix mssql connection * Fix SqlUtils tests * Use config instead of connection string * Replace conn string builder with mssql config * Connect to master db * Restore connection string validation regex * PR comments, fix error handling * Update main.js * Use try catch for error handling * Fix typo
- Loading branch information
Showing
15 changed files
with
2,813 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,33 @@ | ||
import * as exec from '@actions/exec'; | ||
import mssql from 'mssql'; | ||
import SqlUtils from "../src/SqlUtils"; | ||
import AzureSqlActionHelper from "../src/AzureSqlActionHelper"; | ||
import SqlConnectionStringBuilder from '../src/SqlConnectionStringBuilder'; | ||
import SqlConnectionConfig from '../src/SqlConnectionConfig'; | ||
|
||
describe('SqlUtils tests', () => { | ||
it('detectIPAddress should return ipaddress', async () => { | ||
let getSqlCmdPathSpy = jest.spyOn(AzureSqlActionHelper, 'getSqlCmdPath').mockResolvedValue('SqlCmd.exe'); | ||
let execSpy = jest.spyOn(exec, 'exec').mockImplementation((_commandLine, _args, options) => { | ||
let sqlClientError = `Client with IP address '1.2.3.4' is not allowed to access the server.`; | ||
options!.listeners!.stderr!(Buffer.from(sqlClientError)); | ||
return Promise.reject(1); | ||
}); | ||
let ipAddress = await SqlUtils.detectIPAddress('serverName', new SqlConnectionStringBuilder('Server=testServer.database.windows.net;Initial Catalog=testDB;User Id=testUser;Password=placeholder')); | ||
const mssqlSpy = jest.spyOn(mssql.ConnectionPool.prototype, 'connect').mockImplementation((callback) => { | ||
callback(new mssql.ConnectionError(new Error(`Client with IP address '1.2.3.4' is not allowed to access the server.`))); | ||
}); | ||
const ipAddress = await SqlUtils.detectIPAddress(new SqlConnectionConfig('Server=testServer.database.windows.net;Initial Catalog=testDB;User Id=testUser;Password=placeholder')); | ||
|
||
expect(getSqlCmdPathSpy).toHaveBeenCalledTimes(1); | ||
expect(execSpy).toHaveBeenCalledTimes(1); | ||
expect(mssqlSpy).toHaveBeenCalledTimes(1); | ||
expect(ipAddress).toBe('1.2.3.4'); | ||
}); | ||
|
||
it('detectIPAddress should return empty', async () => { | ||
let getSqlCmdSpy = jest.spyOn(AzureSqlActionHelper, 'getSqlCmdPath').mockResolvedValue('SqlCmd.exe'); | ||
let execSpy = jest.spyOn(exec, 'exec').mockResolvedValue(0); | ||
let ipAddress = await SqlUtils.detectIPAddress('serverName', new SqlConnectionStringBuilder('Server=testServer.database.windows.net;Initial Catalog=testDB;User Id=testUser;Password=placeholder')); | ||
const mssqlSpy = jest.spyOn(mssql.ConnectionPool.prototype, 'connect').mockImplementation((callback) => { | ||
// Successful connections calls back with null error | ||
callback(null); | ||
}); | ||
const ipAddress = await SqlUtils.detectIPAddress(new SqlConnectionConfig('Server=testServer.database.windows.net;Initial Catalog=testDB;User Id=testUser;Password=placeholder')); | ||
|
||
expect(getSqlCmdSpy).toHaveBeenCalledTimes(1); | ||
expect(execSpy).toHaveBeenCalledTimes(1); | ||
expect(mssqlSpy).toHaveBeenCalledTimes(1); | ||
expect(ipAddress).toBe(''); | ||
}); | ||
|
||
it('detectIPAddress should throw error', () => { | ||
let getSqlCmdSpy = jest.spyOn(AzureSqlActionHelper, 'getSqlCmdPath').mockResolvedValue('SqlCmd.exe') | ||
|
||
expect(SqlUtils.detectIPAddress('serverName', new SqlConnectionStringBuilder('Server=testServer.database.windows.net;Initial Catalog=testDB;User Id=testUser;Password=placeholder'))).rejects; | ||
expect(getSqlCmdSpy).toHaveBeenCalledTimes(1); | ||
const mssqlSpy = jest.spyOn(mssql.ConnectionPool.prototype, 'connect'); | ||
expect(SqlUtils.detectIPAddress(new SqlConnectionConfig('Server=testServer.database.windows.net;Initial Catalog=testDB;User Id=testUser;Password=placeholder'))).rejects; | ||
expect(mssqlSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/*! | ||
* mime-db | ||
* Copyright(c) 2014 Jonathan Ong | ||
* MIT Licensed | ||
*/ | ||
|
||
/*! | ||
* mime-types | ||
* Copyright(c) 2014 Jonathan Ong | ||
* Copyright(c) 2015 Douglas Christopher Wilson | ||
* MIT Licensed | ||
*/ | ||
|
||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
|
||
/*! @azure/msal-common v4.5.1 2021-08-02 */ | ||
|
||
/*! @azure/msal-common v6.3.0 2022-05-02 */ | ||
|
||
/** | ||
* @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper | ||
* @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos | ||
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree) | ||
*/ | ||
|
||
/** | ||
* @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper | ||
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree) | ||
*/ | ||
|
||
//! @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos | ||
|
||
//! @copyright (c) 2015-present, Philipp Thürwächter, Pattrick Hüper & js-joda contributors | ||
|
||
//! @license BSD-3-Clause (see LICENSE in the root directory of this source tree) | ||
|
||
//! @version @js-joda/core - 4.3.1 |
Oops, something went wrong.