diff --git a/src/core/server/saved_objects/service/lib/repository.test.js b/src/core/server/saved_objects/service/lib/repository.test.js index 5a2e6a617fbb5..236677c221761 100644 --- a/src/core/server/saved_objects/service/lib/repository.test.js +++ b/src/core/server/saved_objects/service/lib/repository.test.js @@ -548,6 +548,19 @@ describe('SavedObjectsRepository', () => { ); expect(onBeforeWrite).toHaveBeenCalledTimes(1); }); + + it(`doesn't support Symbol namespaces`, async () => { + expect(savedObjectsRepository.create( + 'index-pattern', + { + title: 'Logstash', + }, + { + id: 'foo-id', + namespace: Symbol('foo-namespace'), + } + )).rejects.toThrowErrorMatchingSnapshot(); + }); }); describe('#bulkCreate', () => { @@ -993,6 +1006,15 @@ describe('SavedObjectsRepository', () => { expect(onBeforeWrite).toHaveBeenCalledTimes(1); }); + it(`doesn't support Symbol namespaces`, async () => { + expect(savedObjectsRepository.bulkCreate( + [{ type: 'globaltype', id: 'one', attributes: { title: 'Test One' } }], + { + namespace: Symbol('foo-namespace'), + } + )).rejects.toThrowErrorMatchingSnapshot(); + }); + it('should return objects in the same order regardless of type', () => {}); }); @@ -1071,6 +1093,12 @@ describe('SavedObjectsRepository', () => { expect(onBeforeWrite).toHaveBeenCalledTimes(1); }); + + it(`doesn't support Symbol namespaces`, async () => { + expect(savedObjectsRepository.delete('globaltype', 'logstash-*', { + namespace: Symbol('foo-namespace'), + })).rejects.toThrowErrorMatchingSnapshot(); + }); }); describe('#deleteByNamespace', () => { @@ -1090,6 +1118,15 @@ describe('SavedObjectsRepository', () => { expect(onBeforeWrite).not.toHaveBeenCalled(); }); + it(`doesn't support Symbol namespaces`, async () => { + callAdminCluster.mockReturnValue(deleteByQueryResults); + expect( + savedObjectsRepository.deleteByNamespace(Symbol('namespace-1')) + ).rejects.toThrowErrorMatchingSnapshot(); + expect(callAdminCluster).not.toHaveBeenCalled(); + expect(onBeforeWrite).not.toHaveBeenCalled(); + }); + it('constructs a deleteByQuery call using all types that are namespace aware', async () => { callAdminCluster.mockReturnValue(deleteByQueryResults); const result = await savedObjectsRepository.deleteByNamespace('my-namespace'); @@ -1283,6 +1320,11 @@ describe('SavedObjectsRepository', () => { expect(callAdminCluster).toHaveBeenCalledTimes(1); expect(callAdminCluster.mock.calls[0][1]).toHaveProperty('rest_total_hits_as_int', true); }); + + it(`doesn't support Symbol namespaces`, async () => { + expect(savedObjectsRepository.find({ type: 'foo', namespace: Symbol('foo') })) + .rejects.toThrowErrorMatchingSnapshot(); + }); }); describe('#get', () => { @@ -1404,6 +1446,12 @@ describe('SavedObjectsRepository', () => { }) ); }); + + it(`doesn't support Symbol namespaces`, async () => { + expect(savedObjectsRepository.get('globaltype', 'logstash-*', { + namespace: Symbol('foo-namespace'), + })).rejects.toThrowErrorMatchingSnapshot(); + }); }); describe('#bulkGet', () => { @@ -1645,6 +1693,17 @@ describe('SavedObjectsRepository', () => { }, ]); }); + + it(`doesn't support Symbol namespaces`, async () => { + expect(savedObjectsRepository.bulkGet([ + { id: 'one', type: 'config' }, + { id: 'two', type: 'invalidtype' }, + { id: 'three', type: 'config' }, + { id: 'four', type: 'invalidtype' }, + { id: 'five', type: 'config' }, + ], { namespace: Symbol('foo') })) + .rejects.toThrowErrorMatchingSnapshot(); + }); }); describe('#update', () => { @@ -1857,6 +1916,26 @@ describe('SavedObjectsRepository', () => { expect(onBeforeWrite).toHaveBeenCalledTimes(1); }); + + it(`doesn't support Symbol namespaces`, async () => { + expect(savedObjectsRepository.update( + 'index-pattern', + 'foo', + { + name: 'bar', + }, + { + namespace: Symbol('foo-namespace'), + references: [ + { + name: 'ref_0', + type: 'test', + id: '1', + }, + ], + } + )).rejects.toThrowErrorMatchingSnapshot(); + }); }); describe('#incrementCounter', () => { @@ -2053,6 +2132,14 @@ describe('SavedObjectsRepository', () => { ) ).rejects.toEqual(new Error('"counterFieldName" argument must be a string')); }); + + it(`doesn't support Symbol namespaces`, async () => { + expect( + savedObjectsRepository.incrementCounter('globaltype', 'foo', 'counter', { + namespace: Symbol('foo-namespace'), + }) + ).rejects.toThrowErrorMatchingSnapshot(); + }); }); describe('onBeforeWrite', () => { diff --git a/src/core/server/saved_objects/service/lib/repository.ts b/src/core/server/saved_objects/service/lib/repository.ts index eb41df3a19d2d..7af8e763a4da1 100644 --- a/src/core/server/saved_objects/service/lib/repository.ts +++ b/src/core/server/saved_objects/service/lib/repository.ts @@ -421,6 +421,10 @@ export class SavedObjectsRepository { throw new TypeError('options.fields must be an array'); } + if (typeof namespace === 'symbol') { + throw new TypeError('options.namespace must not be a Symbol'); + } + const esOptions = { index: this.getIndicesForTypes(allowedTypes), size: perPage,