Skip to content

Commit

Permalink
[UT] Add test cases for registered auth type, test connection failure…
Browse files Browse the repository at this point in the history
… case

Signed-off-by: Xinrui Bai <xinruiba@amazon.com>
  • Loading branch information
xinruiba committed Mar 11, 2024
1 parent 2e53366 commit 75a1344
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 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 @@ -126,6 +126,32 @@ describe(`Test connection ${URL}`, () => {
},
};

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 @@ -231,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 Down

0 comments on commit 75a1344

Please sign in to comment.