Skip to content

Commit 3b9d61e

Browse files
committed
Add tls auth config test
1 parent c1eda49 commit 3b9d61e

File tree

3 files changed

+75
-25
lines changed

3 files changed

+75
-25
lines changed

docker-compose.test.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ services:
2020
- ./dist:/var/lib/grafana/plugins/haohanyang-mongodb-datasource
2121
- ./provisioning:/etc/grafana/provisioning
2222
- .:/root/haohanyang-mongodb-datasource
23+
- ./certs:/certs
2324

2425
environment:
2526
NODE_ENV: development
@@ -49,6 +50,18 @@ services:
4950
networks:
5051
- mongodb-datasource
5152

53+
mongo-tls-auth:
54+
image: mongo
55+
container_name: mongodb-datasource-mongo-tls-auth
56+
command: [--config, /etc/mongo/mongod.conf]
57+
ports:
58+
- 27020:27017
59+
volumes:
60+
- ./certs:/certs
61+
- ./mongod.conf:/etc/mongo/mongod.conf
62+
networks:
63+
- mongodb-datasource
64+
5265
networks:
5366
mongodb-datasource:
5467
driver: bridge
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: 1
2+
3+
datasources:
4+
- name: 'MongoDB Datasource test'
5+
type: 'haohanyang-mongodb-datasource'
6+
access: proxy
7+
isDefault: false
8+
orgId: 1
9+
version: 1
10+
editable: true
11+
jsonData:
12+
host: mongo-tls-auth
13+
port: 27017
14+
database: test
15+
authType: auth-tls
16+
caCertPath: /certs/ca.crt
17+
clientCertPath: /certs/mongodb.crt
18+
clientKeyPath: /certs/mongodb.pem
19+
secureJsonData:
20+
password: password

tests/configEditor.spec.js

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
1-
import { test, expect } from "@grafana/plugin-e2e";
1+
import { test, expect } from '@grafana/plugin-e2e';
22

3-
test("\"Save & test\" should be successful when mongo without auth config is valid", async ({
4-
createDataSourceConfigPage,
5-
readProvisionedDataSource,
6-
page,
3+
test('"Save & test" should be successful when mongo without auth config is valid', async ({
4+
createDataSourceConfigPage,
5+
readProvisionedDataSource,
6+
page,
77
}) => {
8-
const ds = await readProvisionedDataSource({ fileName: "test/mongo-no-auth.yml" });
9-
const configPage = await createDataSourceConfigPage({ type: ds.type });
10-
await page.getByLabel("Host").fill(ds.jsonData.host || "");
11-
await page.getByLabel("Port").fill(ds.jsonData.port?.toString() || "");
12-
await page.getByLabel("Database").fill(ds.jsonData.database || "");
13-
await page.getByRole("radio", { name: "None" }).check();
14-
await expect(configPage.saveAndTest()).toBeOK();
8+
const ds = await readProvisionedDataSource({ fileName: 'test/mongo-no-auth.yml' });
9+
const configPage = await createDataSourceConfigPage({ type: ds.type });
10+
await page.getByLabel('Host').fill(ds.jsonData.host ?? '');
11+
await page.getByLabel('Port').fill(ds.jsonData.port?.toString() ?? '');
12+
await page.getByLabel('Database').fill(ds.jsonData.database ?? '');
13+
await page.getByRole('radio', { name: 'None' }).check();
14+
await expect(configPage.saveAndTest()).toBeOK();
1515
});
1616

17-
test("\"Save & test\" should be successful when mongo username-password auth config is valid", async ({
18-
createDataSourceConfigPage,
19-
readProvisionedDataSource,
20-
page,
17+
test('"Save & test" should be successful when mongo username-password auth config is valid', async ({
18+
createDataSourceConfigPage,
19+
readProvisionedDataSource,
20+
page,
2121
}) => {
22-
const ds = await readProvisionedDataSource({ fileName: "test/mongo-username-password-auth.yml" });
23-
const configPage = await createDataSourceConfigPage({ type: ds.type });
24-
await page.getByLabel("Host").fill(ds.jsonData.host || "");
25-
await page.getByLabel("Port").fill(ds.jsonData.port?.toString() || "");
26-
await page.getByLabel("Database").fill(ds.jsonData.database || "");
27-
await page.getByRole("radio", { name: "Username/Password", exact: true }).check();
28-
await page.getByLabel("Username", { exact: true }).fill(ds.jsonData.username || "");
29-
await page.getByLabel("Password", { exact: true }).fill(ds.secureJsonData?.password || "");
30-
await expect(configPage.saveAndTest()).toBeOK();
22+
const ds = await readProvisionedDataSource({ fileName: 'test/mongo-username-password-auth.yml' });
23+
const configPage = await createDataSourceConfigPage({ type: ds.type });
24+
await page.getByLabel('Host').fill(ds.jsonData.host ?? '');
25+
await page.getByLabel('Port').fill(ds.jsonData.port?.toString() ?? '');
26+
await page.getByLabel('Database').fill(ds.jsonData.database ?? '');
27+
await page.getByRole('radio', { name: 'Username/Password', exact: true }).check();
28+
await page.getByLabel('Username', { exact: true }).fill(ds.jsonData.username ?? '');
29+
await page.getByLabel('Password', { exact: true }).fill(ds.secureJsonData?.password ?? '');
30+
await expect(configPage.saveAndTest()).toBeOK();
31+
});
32+
33+
test('"Save & test" should be successful when mongo tls auth config is valid', async ({
34+
createDataSourceConfigPage,
35+
readProvisionedDataSource,
36+
page,
37+
}) => {
38+
const ds = await readProvisionedDataSource({ fileName: 'test/mongo-tls-auth.yml' });
39+
const configPage = await createDataSourceConfigPage({ type: ds.type });
40+
await page.getByLabel('Host').fill(ds.jsonData.host ?? '');
41+
await page.getByLabel('Port').fill(ds.jsonData.port?.toString() ?? '');
42+
await page.getByLabel('Database').fill(ds.jsonData.database ?? '');
43+
await page.getByRole('radio', { name: 'TLS/SSL', exact: true }).check();
44+
await page.getByLabel('Certificate Authority', { exact: true }).fill(ds.jsonData.caCertPath ?? '');
45+
await page.getByLabel('Client Certificate', { exact: true }).fill(ds.jsonData.clientCertPath ?? '');
46+
await page.getByLabel('Client Key', { exact: true }).fill(ds.jsonData.clientKeyPath ?? '');
47+
await expect(configPage.saveAndTest()).toBeOK();
3148
});

0 commit comments

Comments
 (0)