mirror of
https://github.com/logto-io/logto.git
synced 2025-01-20 21:32:31 -05:00
fix: connector metadata update should be optional (#2666)
This commit is contained in:
parent
bed00c4918
commit
f3baaf919f
3 changed files with 53 additions and 6 deletions
|
@ -208,12 +208,14 @@ export default function connectorRoutes<T extends AuthedRouter>(router: T) {
|
||||||
const { type, validateConfig, metadata: originalMetadata } = await getLogtoConnectorById(id);
|
const { type, validateConfig, metadata: originalMetadata } = await getLogtoConnectorById(id);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
originalMetadata.isStandard !== true || metadata?.target === originalMetadata.target,
|
originalMetadata.isStandard !== true ||
|
||||||
|
!metadata ||
|
||||||
|
metadata.target === originalMetadata.target,
|
||||||
'connector.can_not_modify_target'
|
'connector.can_not_modify_target'
|
||||||
);
|
);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
originalMetadata.isStandard === true || metadata === undefined,
|
originalMetadata.isStandard === true || !metadata,
|
||||||
'connector.cannot_overwrite_metadata_for_non_standard_connector'
|
'connector.cannot_overwrite_metadata_for_non_standard_connector'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,54 @@ describe('connector PATCH routes', () => {
|
||||||
expect(response).toHaveProperty('statusCode', 400);
|
expect(response).toHaveProperty('statusCode', 400);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('successfully updates connector configs', async () => {
|
it('throws when updates non-standard connector metadata', async () => {
|
||||||
|
getLogtoConnectors.mockResolvedValue([
|
||||||
|
{
|
||||||
|
dbEntry: mockConnector,
|
||||||
|
metadata: { ...mockMetadata },
|
||||||
|
type: ConnectorType.Social,
|
||||||
|
...mockLogtoConnector,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
const response = await connectorRequest.patch('/connectors/id').send({
|
||||||
|
metadata: {
|
||||||
|
target: 'connector',
|
||||||
|
name: { en: 'connector_name', fr: 'connector_name' },
|
||||||
|
logo: 'new_logo.png',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(response).toHaveProperty('statusCode', 400);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('successfully updates connector config', async () => {
|
||||||
|
getLogtoConnectors.mockResolvedValue([
|
||||||
|
{
|
||||||
|
dbEntry: mockConnector,
|
||||||
|
metadata: { ...mockMetadata, isStandard: true },
|
||||||
|
type: ConnectorType.Social,
|
||||||
|
...mockLogtoConnector,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
updateConnector.mockResolvedValueOnce({
|
||||||
|
...mockConnector,
|
||||||
|
config: { cliend_id: 'client_id', client_secret: 'client_secret' },
|
||||||
|
});
|
||||||
|
const response = await connectorRequest.patch('/connectors/id').send({
|
||||||
|
config: { cliend_id: 'client_id', client_secret: 'client_secret' },
|
||||||
|
});
|
||||||
|
expect(response).toHaveProperty('statusCode', 200);
|
||||||
|
expect(updateConnector).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
where: { id: 'id' },
|
||||||
|
set: {
|
||||||
|
config: { cliend_id: 'client_id', client_secret: 'client_secret' },
|
||||||
|
},
|
||||||
|
jsonbMode: 'replace',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('successfully updates connector config and metadata', async () => {
|
||||||
getLogtoConnectors.mockResolvedValue([
|
getLogtoConnectors.mockResolvedValue([
|
||||||
{
|
{
|
||||||
dbEntry: mockConnector,
|
dbEntry: mockConnector,
|
||||||
|
|
|
@ -77,9 +77,7 @@ test('connector set-up flow', async () => {
|
||||||
connectorId: mockStandardEmailConnectorId,
|
connectorId: mockStandardEmailConnectorId,
|
||||||
metadata: { target: 'mock-standard-mail' },
|
metadata: { target: 'mock-standard-mail' },
|
||||||
});
|
});
|
||||||
await updateConnectorConfig(id, mockStandardEmailConnectorConfig, {
|
await updateConnectorConfig(id, mockStandardEmailConnectorConfig);
|
||||||
target: 'mock-standard-mail',
|
|
||||||
});
|
|
||||||
connectorIdMap.set(mockStandardEmailConnectorId, id);
|
connectorIdMap.set(mockStandardEmailConnectorId, id);
|
||||||
const currentConnectors = await listConnectors();
|
const currentConnectors = await listConnectors();
|
||||||
expect(
|
expect(
|
||||||
|
|
Loading…
Add table
Reference in a new issue