Skip to content

Commit

Permalink
assert that the repository cannot accept Symbol namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego committed Jun 20, 2019
1 parent 348ef98 commit 8353f0f
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
87 changes: 87 additions & 0 deletions src/core/server/saved_objects/service/lib/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {});
});

Expand Down Expand Up @@ -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', () => {
Expand All @@ -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');
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8353f0f

Please sign in to comment.