Implement the check as part of the integration
This commit is contained in:
parent
e8fa690566
commit
2f9b076381
|
@ -358,6 +358,15 @@ class MongoIntegration implements IntegrationBase {
|
|||
this.client = new MongoClient(config.connectionString, options)
|
||||
}
|
||||
|
||||
async testConnection() {
|
||||
try {
|
||||
await this.connect()
|
||||
return true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
}
|
||||
}
|
||||
|
||||
async connect() {
|
||||
return this.client.connect()
|
||||
}
|
||||
|
@ -631,18 +640,8 @@ class MongoIntegration implements IntegrationBase {
|
|||
}
|
||||
}
|
||||
}
|
||||
async function validateConnection(config: MongoDBConfig) {
|
||||
const integration = new MongoIntegration(config)
|
||||
try {
|
||||
await integration.connect()
|
||||
return true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
schema: SCHEMA,
|
||||
integration: MongoIntegration,
|
||||
validateConnection,
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import { GenericContainer } from "testcontainers"
|
||||
import mongodb from "../../../../packages/server/src/integrations/mongodb"
|
||||
import mongo from "../../../../packages/server/src/integrations/mongodb"
|
||||
import { generator } from "../../shared"
|
||||
|
||||
jest.unmock("mongodb")
|
||||
|
||||
describe("datasource validators", () => {
|
||||
describe("mongo", () => {
|
||||
const validator = integrations.getValidator[SourceName.MONGODB]
|
||||
|
||||
let connectionSettings: {
|
||||
user: string
|
||||
password: string
|
||||
|
@ -42,46 +41,50 @@ describe("datasource validators", () => {
|
|||
})
|
||||
|
||||
it("test valid connection string", async () => {
|
||||
const result = await validator({
|
||||
const integration = new mongo.integration({
|
||||
connectionString: getConnectionString(),
|
||||
db: "",
|
||||
tlsCertificateFile: "",
|
||||
tlsCertificateKeyFile: "",
|
||||
tlsCAFile: "",
|
||||
})
|
||||
const result = await integration.testConnection()
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
|
||||
it("test invalid password", async () => {
|
||||
const result = await validator({
|
||||
const integration = new mongo.integration({
|
||||
connectionString: getConnectionString({ password: "wrong" }),
|
||||
db: "",
|
||||
tlsCertificateFile: "",
|
||||
tlsCertificateKeyFile: "",
|
||||
tlsCAFile: "",
|
||||
})
|
||||
const result = await integration.testConnection()
|
||||
expect(result).toEqual({ error: "Authentication failed." })
|
||||
})
|
||||
|
||||
it("test invalid username", async () => {
|
||||
const result = await validator({
|
||||
const integration = new mongo.integration({
|
||||
connectionString: getConnectionString({ user: "wrong" }),
|
||||
db: "",
|
||||
tlsCertificateFile: "",
|
||||
tlsCertificateKeyFile: "",
|
||||
tlsCAFile: "",
|
||||
})
|
||||
const result = await integration.testConnection()
|
||||
expect(result).toEqual({ error: "Authentication failed." })
|
||||
})
|
||||
|
||||
it("test invalid connection", async () => {
|
||||
const result = await validator({
|
||||
const integration = new mongo.integration({
|
||||
connectionString: getConnectionString({ host: "http://nothinghere" }),
|
||||
db: "",
|
||||
tlsCertificateFile: "",
|
||||
tlsCertificateKeyFile: "",
|
||||
tlsCAFile: "",
|
||||
})
|
||||
const result = await integration.testConnection()
|
||||
expect(result).toEqual({ error: "Error: getaddrinfo ENOTFOUND http" })
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue