Skip to content

Commit

Permalink
[Multiple Datasource] Test connection schema validation for registere…
Browse files Browse the repository at this point in the history
…d auth types (#6109) (#6116)

* [Token Exchange Unification] Test connextion router schema validation support for registered auth type

Signed-off-by: Xinrui Bai <[email protected]>

* Update changefile

Signed-off-by: Xinrui Bai <[email protected]>

* [UT] Add test cases for registered auth type, test connection failure case

Signed-off-by: Xinrui Bai <[email protected]>

* [UT] Update testing URL value to avoid linkchecker failure

Signed-off-by: Xinrui Bai <[email protected]>

* [UT] Update testing URL value to avoid linkchecker failure round2

Signed-off-by: Xinrui Bai <[email protected]>

* [UT] Update testing URL value to avoid linkchecker failure round 3

Signed-off-by: Xinrui Bai <[email protected]>

---------

Signed-off-by: Xinrui Bai <[email protected]>
(cherry picked from commit 362ab1e)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 5203830 commit ddb9cf7
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
127 changes: 127 additions & 0 deletions src/plugins/data_source/server/routes/test_connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,58 @@ describe(`Test connection ${URL}`, () => {
},
};

const dataSourceAttrForRegisteredAuthWithCredentials = {
endpoint: 'https://test.com',
auth: {
type: 'Some Registered Type',
credentials: {
firstField: 'some value',
secondField: 'some value',
},
},
};

const dataSourceAttrForRegisteredAuthWithEmptyCredentials = {
endpoint: 'https://test.com',
auth: {
type: 'Some Registered Type',
credentials: {},
},
};

const dataSourceAttrForRegisteredAuthWithoutCredentials = {
endpoint: 'https://test.com',
auth: {
type: 'Some Registered Type',
},
};

const dataSourceAttrForRegisteredAuthWithNoAuthType = {
endpoint: 'https://test.com',
auth: {
type: AuthType.NoAuth,
credentials: {
field: 'some value',
},
},
};

const dataSourceAttrForRegisteredAuthWithBasicAuthType = {
endpoint: 'https://test.com',
auth: {
type: AuthType.UsernamePasswordType,
credentials: {},
},
};

const dataSourceAttrForRegisteredAuthWithSigV4AuthType = {
endpoint: 'https://test.com',
auth: {
type: AuthType.SigV4,
credentials: {},
},
};

beforeEach(async () => {
({ server, httpSetup, handlerContext } = await setupServer());
customApiSchemaRegistryPromise = Promise.resolve(customApiSchemaRegistry);
Expand Down Expand Up @@ -205,6 +257,48 @@ describe(`Test connection ${URL}`, () => {
expect(result.body.error).toEqual('Bad Request');
});

it('registered Auth with NoAuthType should fail', async () => {
const result = await supertest(httpSetup.server.listener)
.post(URL)
.send({
id: 'testId',
dataSourceAttr: dataSourceAttrForRegisteredAuthWithNoAuthType,
})
.expect(400);
expect(result.body.error).toEqual('Bad Request');
expect(result.body.message).toContain(
`Must not be no_auth or username_password or sigv4 for registered auth types`
);
});

it('registered Auth with Basic AuthType should fail', async () => {
const result = await supertest(httpSetup.server.listener)
.post(URL)
.send({
id: 'testId',
dataSourceAttr: dataSourceAttrForRegisteredAuthWithBasicAuthType,
})
.expect(400);
expect(result.body.error).toEqual('Bad Request');
expect(result.body.message).toContain(
`Must not be no_auth or username_password or sigv4 for registered auth types`
);
});

it('registered Auth with sigV4 AuthType should fail', async () => {
const result = await supertest(httpSetup.server.listener)
.post(URL)
.send({
id: 'testId',
dataSourceAttr: dataSourceAttrForRegisteredAuthWithSigV4AuthType,
})
.expect(400);
expect(result.body.error).toEqual('Bad Request');
expect(result.body.message).toContain(
`Must not be no_auth or username_password or sigv4 for registered auth types`
);
});

it('full credential with sigV4 auth should success', async () => {
const result = await supertest(httpSetup.server.listener)
.post(URL)
Expand All @@ -215,4 +309,37 @@ describe(`Test connection ${URL}`, () => {
.expect(200);
expect(result.body).toEqual({ success: true });
});

it('credential with registered auth type should success', async () => {
const result = await supertest(httpSetup.server.listener)
.post(URL)
.send({
id: 'testId',
dataSourceAttr: dataSourceAttrForRegisteredAuthWithCredentials,
})
.expect(200);
expect(result.body).toEqual({ success: true });
});

it('empty credential with registered auth type should success', async () => {
const result = await supertest(httpSetup.server.listener)
.post(URL)
.send({
id: 'testId',
dataSourceAttr: dataSourceAttrForRegisteredAuthWithEmptyCredentials,
})
.expect(200);
expect(result.body).toEqual({ success: true });
});

it('no credential with registered auth type should success', async () => {
const result = await supertest(httpSetup.server.listener)
.post(URL)
.send({
id: 'testId',
dataSourceAttr: dataSourceAttrForRegisteredAuthWithoutCredentials,
})
.expect(200);
expect(result.body).toEqual({ success: true });
});
});
14 changes: 14 additions & 0 deletions src/plugins/data_source/server/routes/test_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ export const registerTestConnectionRoute = async (
]),
}),
}),
schema.object({
type: schema.string({
validate: (value) => {
if (
value === AuthType.NoAuth ||
value === AuthType.UsernamePasswordType ||
value === AuthType.SigV4
) {
return `Must not be no_auth or username_password or sigv4 for registered auth types`;
}
},
}),
credentials: schema.nullable(schema.any()),
}),
])
),
}),
Expand Down

0 comments on commit ddb9cf7

Please sign in to comment.