Skip to content

Commit bc1bbb6

Browse files
committed
Fix config test
1 parent 3b9d61e commit bc1bbb6

File tree

8 files changed

+200
-215
lines changed

8 files changed

+200
-215
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ jobs:
196196

197197
- name: Run Playwright tests
198198
id: run-tests
199-
run: npm run e2e
199+
run: bash scripts/cert-gen.sh mongo-tls-auth && npm run e2e
200200

201201
- name: Docker logs
202202
if: ${{ always() && steps.run-tests.outcome == 'failure' }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
secureJsonData:

provisioning/datasources/test/mongo-no-auth.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

provisioning/datasources/test/mongo-tls-auth.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

provisioning/datasources/test/mongo-username-password-auth.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/components/ConfigEditor.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
ConnectionStringScheme,
1818
} from '../types';
1919

20-
interface Props extends DataSourcePluginOptionsEditorProps<MongoDataSourceOptions, MongoDataSourceSecureJsonData> {}
20+
interface Props extends DataSourcePluginOptionsEditorProps<MongoDataSourceOptions, MongoDataSourceSecureJsonData> { }
2121

2222
const mongoDBAuthMethods: SelectableValue[] = [
2323
{ label: 'None', value: MongoDBAuthMethod.NONE },
@@ -219,6 +219,7 @@ export function ConfigEditor(props: Props) {
219219
<Input
220220
required
221221
id="config-editor-tls-ca"
222+
placeholder='/path/to/ca.pem'
222223
value={jsonData.caCertPath}
223224
onChange={(event: ChangeEvent<HTMLInputElement>) =>
224225
onOptionsChange({
@@ -235,6 +236,7 @@ export function ConfigEditor(props: Props) {
235236
<Input
236237
required
237238
id="config-editor-tls-cc"
239+
placeholder='/path/to/mongodb.crt'
238240
value={jsonData.clientCertPath}
239241
onChange={(event: ChangeEvent<HTMLInputElement>) =>
240242
onOptionsChange({
@@ -249,8 +251,8 @@ export function ConfigEditor(props: Props) {
249251
</Field>
250252
<Field label="Client Key" description="Path to private client key (.pem)">
251253
<Input
252-
required
253254
id="config-editor-tls-ck"
255+
placeholder='/path/to/mongodb.pem'
254256
value={jsonData.clientKeyPath}
255257
onChange={(event: ChangeEvent<HTMLInputElement>) =>
256258
onOptionsChange({

tests/configEditor.spec.js

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,43 @@ import { test, expect } from '@grafana/plugin-e2e';
22

33
test('"Save & test" should be successful when mongo without auth config is valid', async ({
44
createDataSourceConfigPage,
5-
readProvisionedDataSource,
65
page,
76
}) => {
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 ?? '');
7+
const configPage = await createDataSourceConfigPage({ type: 'haohanyang-mongodb-datasource' });
8+
await page.getByLabel('Host').fill('mongo-no-auth');
9+
await page.getByLabel('Port').fill('27017');
10+
await page.getByLabel('Database').fill('test');
1311
await page.getByRole('radio', { name: 'None' }).check();
1412
await expect(configPage.saveAndTest()).toBeOK();
1513
});
1614

1715
test('"Save & test" should be successful when mongo username-password auth config is valid', async ({
1816
createDataSourceConfigPage,
19-
readProvisionedDataSource,
2017
page,
2118
}) => {
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 ?? '');
19+
const configPage = await createDataSourceConfigPage({ type: 'haohanyang-mongodb-datasource' });
20+
await page.getByLabel('Host').fill('mongo-username-password-auth');
21+
await page.getByLabel('Port').fill('27017');
22+
await page.getByLabel('Database').fill('test');
2723
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 ?? '');
24+
await page.getByLabel('Username', { exact: true }).fill('username');
25+
await page.getByLabel('Password', { exact: true }).fill('password');
3026
await expect(configPage.saveAndTest()).toBeOK();
3127
});
3228

3329
test('"Save & test" should be successful when mongo tls auth config is valid', async ({
3430
createDataSourceConfigPage,
35-
readProvisionedDataSource,
3631
page,
3732
}) => {
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 ?? '');
33+
const configPage = await createDataSourceConfigPage({ type: 'haohanyang-mongodb-datasource' });
34+
await page.getByLabel('Host').fill('mongo-tls-auth');
35+
await page.getByLabel('Port').fill('27017');
36+
await page.getByLabel('Database').fill('test');
4337
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 ?? '');
38+
await page.screenshot({ path: 'mongo-tls-auth1.png' });
39+
40+
await page.getByLabel('Certificate Authority').fill('/certs/ca.pem');
41+
await page.getByLabel('Client Certificate').fill('/certs/mongodb.crt');
42+
await page.getByPlaceholder('/path/to/mongodb.pem').fill('/certs/mongodb.pem');
4743
await expect(configPage.saveAndTest()).toBeOK();
4844
});

0 commit comments

Comments
 (0)