Validate and test microsoft sql
This commit is contained in:
parent
cb398dad02
commit
32695018bf
|
@ -22,7 +22,7 @@ import { MSSQLTablesResponse, MSSQLColumn } from "./base/types"
|
||||||
const sqlServer = require("mssql")
|
const sqlServer = require("mssql")
|
||||||
const DEFAULT_SCHEMA = "dbo"
|
const DEFAULT_SCHEMA = "dbo"
|
||||||
|
|
||||||
interface MSSQLConfig {
|
export interface MSSQLConfig {
|
||||||
user: string
|
user: string
|
||||||
password: string
|
password: string
|
||||||
server: string
|
server: string
|
||||||
|
@ -138,6 +138,10 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// async end(){
|
||||||
|
// this.client!.
|
||||||
|
// }
|
||||||
|
|
||||||
async internalQuery(
|
async internalQuery(
|
||||||
query: SqlQuery,
|
query: SqlQuery,
|
||||||
operation: string | undefined = undefined
|
operation: string | undefined = undefined
|
||||||
|
@ -306,7 +310,18 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function validateConnection(config: MSSQLConfig) {
|
||||||
|
const integration = new SqlServerIntegration(config)
|
||||||
|
try {
|
||||||
|
await integration.connect()
|
||||||
|
return true
|
||||||
|
} catch (e: any) {
|
||||||
|
return { error: e.message as string }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
schema: SCHEMA,
|
schema: SCHEMA,
|
||||||
integration: SqlServerIntegration,
|
integration: SqlServerIntegration,
|
||||||
|
validateConnection,
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { GenericContainer } from "testcontainers"
|
||||||
import postgres from "../../../../packages/server/src/integrations/postgres"
|
import postgres from "../../../../packages/server/src/integrations/postgres"
|
||||||
|
|
||||||
jest.unmock("pg")
|
jest.unmock("pg")
|
||||||
|
jest.unmock("mssql")
|
||||||
|
|
||||||
describe("datasource validators", () => {
|
describe("datasource validators", () => {
|
||||||
describe("postgres", () => {
|
describe("postgres", () => {
|
||||||
|
@ -50,4 +51,50 @@ describe("datasource validators", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("mssql", () => {
|
||||||
|
const validator = integrations.getValidator[SourceName.SQL_SERVER]!
|
||||||
|
|
||||||
|
let host: string, port: number
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
const container = await new GenericContainer(
|
||||||
|
"mcr.microsoft.com/mssql/server"
|
||||||
|
)
|
||||||
|
.withExposedPorts(1433)
|
||||||
|
.withEnv("ACCEPT_EULA", "Y")
|
||||||
|
.withEnv("MSSQL_SA_PASSWORD", "Str0Ng_p@ssW0rd!")
|
||||||
|
.withEnv("MSSQL_PID", "Developer")
|
||||||
|
.start()
|
||||||
|
|
||||||
|
host = container.getContainerIpAddress()
|
||||||
|
port = container.getMappedPort(1433)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("test valid connection string", async () => {
|
||||||
|
const result = await validator({
|
||||||
|
user: "sa",
|
||||||
|
password: "Str0Ng_p@ssW0rd!",
|
||||||
|
server: host,
|
||||||
|
port: port,
|
||||||
|
database: "master",
|
||||||
|
schema: "dbo",
|
||||||
|
})
|
||||||
|
expect(result).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("test invalid password", async () => {
|
||||||
|
const result = await validator({
|
||||||
|
user: "sa",
|
||||||
|
password: "wrong_pwd",
|
||||||
|
server: host,
|
||||||
|
port: port,
|
||||||
|
database: "master",
|
||||||
|
schema: "dbo",
|
||||||
|
})
|
||||||
|
expect(result).toEqual({
|
||||||
|
error: "ConnectionError: Login failed for user 'sa'.",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue