Merge pull request #10555 from Budibase/budi-6932/verify_arango

Implement arango connection verification
This commit is contained in:
Michael Drury 2023-05-15 17:11:12 +01:00 committed by GitHub
commit 001e8757e8
2 changed files with 86 additions and 2 deletions

View File

@ -6,7 +6,7 @@ import {
DatasourceFeature, DatasourceFeature,
} from "@budibase/types" } from "@budibase/types"
const { Database, aql } = require("arangojs") import { Database, aql } from "arangojs"
interface ArangodbConfig { interface ArangodbConfig {
url: string url: string
@ -60,7 +60,7 @@ const SCHEMA: Integration = {
class ArangoDBIntegration implements IntegrationBase { class ArangoDBIntegration implements IntegrationBase {
private config: ArangodbConfig private config: ArangodbConfig
private client: any private client
constructor(config: ArangodbConfig) { constructor(config: ArangodbConfig) {
const newConfig = { const newConfig = {
@ -76,6 +76,15 @@ class ArangoDBIntegration implements IntegrationBase {
this.client = new Database(newConfig) this.client = new Database(newConfig)
} }
async testConnection() {
try {
await this.client.get()
return true
} catch (e: any) {
return { error: e.message as string }
}
}
async read(query: { sql: any }) { async read(query: { sql: any }) {
try { try {
const result = await this.client.query(query.sql) const result = await this.client.query(query.sql)

View File

@ -0,0 +1,75 @@
import { GenericContainer, Wait } from "testcontainers"
import arangodb from "../../../../packages/server/src/integrations/arangodb"
import { generator } from "../../shared"
jest.unmock("arangojs")
describe("datasource validators", () => {
describe("arangodb", () => {
let connectionSettings: {
user: string
password: string
url: string
}
beforeAll(async () => {
const user = "root"
const password = generator.hash()
const container = await new GenericContainer("arangodb")
.withExposedPorts(8529)
.withEnv("ARANGO_ROOT_PASSWORD", password)
.withWaitStrategy(
Wait.forLogMessage("is ready for business. Have fun!")
)
.start()
connectionSettings = {
user,
password,
url: `http://${container.getContainerIpAddress()}:${container.getMappedPort(
8529
)}`,
}
})
it("test valid connection string", async () => {
const integration = new arangodb.integration({
url: connectionSettings.url,
username: connectionSettings.user,
password: connectionSettings.password,
databaseName: "",
collection: "",
})
const result = await integration.testConnection()
expect(result).toBe(true)
})
it("test wrong password", async () => {
const integration = new arangodb.integration({
url: connectionSettings.url,
username: connectionSettings.user,
password: "wrong",
databaseName: "",
collection: "",
})
const result = await integration.testConnection()
expect(result).toEqual({
error: "not authorized to execute this request",
})
})
it("test wrong url", async () => {
const integration = new arangodb.integration({
url: "http://not.here",
username: connectionSettings.user,
password: connectionSettings.password,
databaseName: "",
collection: "",
})
const result = await integration.testConnection()
expect(result).toEqual({
error: "getaddrinfo ENOTFOUND not.here",
})
})
})
})