-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into user-allowlist-artifacts-pt3
- Loading branch information
Showing
18 changed files
with
506 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
IMPORT_BUFFER_SIZE, | ||
LIST_INDEX, | ||
LIST_ITEM_INDEX, | ||
MAX_IMPORT_PAYLOAD_BYTES, | ||
} from '../common/constants.mock'; | ||
|
||
import { ConfigType } from './config'; | ||
|
||
export const getConfigMock = (): Partial<ConfigType> => ({ | ||
listIndex: LIST_INDEX, | ||
listItemIndex: LIST_ITEM_INDEX, | ||
}); | ||
|
||
export const getConfigMockDecoded = (): ConfigType => ({ | ||
enabled: true, | ||
importBufferSize: IMPORT_BUFFER_SIZE, | ||
listIndex: LIST_INDEX, | ||
listItemIndex: LIST_ITEM_INDEX, | ||
maxImportPayloadBytes: MAX_IMPORT_PAYLOAD_BYTES, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { ConfigSchema, ConfigType } from './config'; | ||
import { getConfigMock, getConfigMockDecoded } from './config.mock'; | ||
|
||
describe('config_schema', () => { | ||
test('it works with expected basic mock data set and defaults', () => { | ||
expect(ConfigSchema.validate(getConfigMock())).toEqual(getConfigMockDecoded()); | ||
}); | ||
|
||
test('it throws if given an invalid value', () => { | ||
const mock: Partial<ConfigType> & { madeUpValue: string } = { | ||
madeUpValue: 'something', | ||
...getConfigMock(), | ||
}; | ||
expect(() => ConfigSchema.validate(mock)).toThrow( | ||
'[madeUpValue]: definition for this key is missing' | ||
); | ||
}); | ||
|
||
test('it throws if the "maxImportPayloadBytes" value is 0', () => { | ||
const mock: ConfigType = { | ||
...getConfigMockDecoded(), | ||
maxImportPayloadBytes: 0, | ||
}; | ||
expect(() => ConfigSchema.validate(mock)).toThrow( | ||
'[maxImportPayloadBytes]: Value must be equal to or greater than [1].' | ||
); | ||
}); | ||
|
||
test('it throws if the "maxImportPayloadBytes" value is less than 0', () => { | ||
const mock: ConfigType = { | ||
...getConfigMockDecoded(), | ||
maxImportPayloadBytes: -1, | ||
}; | ||
expect(() => ConfigSchema.validate(mock)).toThrow( | ||
'[maxImportPayloadBytes]: Value must be equal to or greater than [1].' | ||
); | ||
}); | ||
|
||
test('it throws if the "importBufferSize" value is 0', () => { | ||
const mock: ConfigType = { | ||
...getConfigMockDecoded(), | ||
importBufferSize: 0, | ||
}; | ||
expect(() => ConfigSchema.validate(mock)).toThrow( | ||
'[importBufferSize]: Value must be equal to or greater than [1].' | ||
); | ||
}); | ||
|
||
test('it throws if the "importBufferSize" value is less than 0', () => { | ||
const mock: ConfigType = { | ||
...getConfigMockDecoded(), | ||
importBufferSize: -1, | ||
}; | ||
expect(() => ConfigSchema.validate(mock)).toThrow( | ||
'[importBufferSize]: Value must be equal to or greater than [1].' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
x-pack/plugins/lists/server/routes/utils/create_stream_from_buffer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { Readable } from 'stream'; | ||
|
||
export const createStreamFromBuffer = (buffer: Buffer): Readable => { | ||
const stream = new Readable(); | ||
stream.push(buffer); | ||
stream.push(null); | ||
return stream; | ||
}; |
Oops, something went wrong.