Skip to content

Commit c603a46

Browse files
authored
COMPASS-9674: add to special collections
1 parent 85cb2e1 commit c603a46

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

index.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ class NS {
44
database: string;
55
collection: string;
66
system: boolean;
7-
isSystem: boolean;
7+
isSystem(): boolean;
88
oplog: boolean;
9-
isOplog: boolean;
9+
isOplog(): boolean;
1010
command: boolean;
11-
isCommand: boolean;
11+
isCommand(): boolean;
1212
special: boolean;
13-
isSpecial: boolean;
13+
isSpecial(): boolean;
1414
specialish: boolean;
1515
normal: boolean;
16-
isNormal: boolean;
16+
isNormal(): boolean;
1717
validDatabaseName: boolean;
1818
validCollectionName: boolean;
1919
databaseHash: number;

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ function NS(ns) {
1616
this.collection = ns.slice(this.dotIndex + 1);
1717
}
1818

19-
this.system = /^(?:system|enxcol_)\./.test(this.collection);
19+
this.system = /^(?:system(?!\.profile$).*|enxcol_)\./.test(this.collection);
20+
2021
this.oplog = /local\.oplog\.(\$main|rs)/.test(ns);
2122

2223
this.command =
2324
this.collection === '$cmd' || this.collection.indexOf('$cmd.sys') === 0;
2425
this.special =
25-
this.oplog || this.command || this.system || this.database === 'config';
26+
this.oplog || this.command || this.system || this.database === 'config' || /^__mdb_internal_\w/.test(this.database);
2627

2728
this.specialish =
2829
this.special || ['local', 'admin'].indexOf(this.database) > -1;

test.js

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ describe('ns', function() {
3535
assert.equal(ns('local.oplog.$foo').oplog, false);
3636
});
3737

38-
it('should identify special namespaces', function() {
39-
it('should acccept `a.$.b`', function() {
40-
assert(ns('a.$.b').special);
38+
describe('should identify special namespaces', function() {
39+
it('should NOT accept `a.$.b as special`', function() {
40+
assert.equal(ns('a.$.b').special, false);
4141
});
4242
it('should acccept `a.system.foo`', function() {
4343
assert(ns('a.system.foo').special);
@@ -54,6 +54,43 @@ describe('ns', function() {
5454
it('should not accept `a.foo.system.bar`', function() {
5555
assert.equal(ns('a.foo.system.bar').special, false);
5656
});
57+
it('should not accept `prefix__mdb_internal_suffix`', function() {
58+
assert.equal(ns('prefix__mdb_internal_suffix').special, false);
59+
});
60+
it('should not accept `anyDB.prefix__mdb_internal_suffix`', function() {
61+
assert.equal(ns('anyDB.prefix__mdb_internal_itsACollectionNow').special, false);
62+
});
63+
it('should not accept `prefix__mdb_internal_suffix`', function() {
64+
assert.equal(ns('prefix__mdb_internal_').special, false);
65+
});
66+
it('should acccept `__mdb_internal_suffix`', function() {
67+
assert(ns('__mdb_internal_suffix').special);
68+
});
69+
});
70+
71+
describe('should identify system namespaces', function() {
72+
it('should acccept `anyDB.enxcol_.` as system`', function() {
73+
assert(ns('anyDB.enxcol_.').system);
74+
});
75+
it('should acccept `anyDB.system.` as system`', function() {
76+
assert(ns('anyDB.system.').system);
77+
});
78+
it('should acccept `anyDB.system.anyCollSuffix` as system`', function() {
79+
assert(ns('anyDB.system.anyCollSuffix').system);
80+
});
81+
it('should NOT acccept `anyDB.anyCollPrefix.system` as system`', function() {
82+
assert.equal((ns('anyDB.anyCollPrefix.system').system), false);
83+
});
84+
it('should NOT acccept `anyDB.system` as system`', function() {
85+
assert.equal((ns('anyDB.system').system), false);
86+
});
87+
// exception for system.profile COMPASS-9377
88+
it('should NOT acccept `anyDB.system.profile as system`', function() {
89+
assert.equal((ns('anyDB.system.profile').system), false);
90+
});
91+
it('should acccept `anyDB.system.profile_anything as system`', function() {
92+
assert(ns('anyDB.system.profile_anything').system);
93+
});
5794
});
5895

5996
describe('database name validation', function() {

0 commit comments

Comments
 (0)