Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,21 @@ export default class Client extends API {
this.diagnostic = opts[kChild].diagnostic
} else {
this.diagnostic = new Diagnostic()
this.serializer = new options.Serializer()

let serializerOptions
if (opts.disablePrototypePoisoningProtection != null) {
if (typeof opts.disablePrototypePoisoningProtection === 'boolean') {
serializerOptions = {
enablePrototypePoisoningProtection: !opts.disablePrototypePoisoningProtection
}
} else {
serializerOptions = {
enablePrototypePoisoningProtection: opts.disablePrototypePoisoningProtection
}
}
}
this.serializer = new options.Serializer(serializerOptions)

this.connectionPool = new options.ConnectionPool({
pingTimeout: options.pingTimeout,
resurrectStrategy: options.resurrectStrategy,
Expand Down
46 changes: 46 additions & 0 deletions test/unit/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,3 +504,49 @@ test('Ensure new client does not time out at default (30s) when client sets requ
t.end()
}
})

test('Pass disablePrototypePoisoningProtection option to serializer', async t => {
let client = new Client({
node: 'http://localhost:9200',
disablePrototypePoisoningProtection: false
})
t.same(client.serializer[symbols.kJsonOptions], {
protoAction: 'error',
constructorAction: 'error'
})

client = new Client({
node: 'http://localhost:9200',
disablePrototypePoisoningProtection: true
})
t.same(client.serializer[symbols.kJsonOptions], {
protoAction: 'ignore',
constructorAction: 'ignore'
})

client = new Client({
node: 'http://localhost:9200',
disablePrototypePoisoningProtection: 'proto'
})
t.same(client.serializer[symbols.kJsonOptions], {
protoAction: 'error',
constructorAction: 'ignore'
})

client = new Client({
node: 'http://localhost:9200',
disablePrototypePoisoningProtection: 'constructor'
})
t.same(client.serializer[symbols.kJsonOptions], {
protoAction: 'ignore',
constructorAction: 'error'
})
})

test('disablePrototypePoisoningProtection is true by default', async t => {
const client = new Client({ node: 'http://localhost:9200' })
t.same(client.serializer[symbols.kJsonOptions], {
protoAction: 'ignore',
constructorAction: 'ignore'
})
})