|
|
@@ -1,4 +1,4 @@
|
|
|
-const { isTopPage, convertToNewAffiliationPath } = require('../../lib/util/path-utils');
|
|
|
+const { isTopPage, convertToNewAffiliationPath, isCreatablePage } = require('../../lib/util/path-utils');
|
|
|
|
|
|
|
|
|
describe('TopPage Path test', () => {
|
|
|
@@ -55,3 +55,53 @@ describe('convertToNewAffiliationPath test', () => {
|
|
|
}).toThrow();
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+describe('isCreatablePage test', () => {
|
|
|
+ test('should decide creatable or not', () => {
|
|
|
+ expect(isCreatablePage('/hoge')).toBeTruthy();
|
|
|
+
|
|
|
+ // edge cases
|
|
|
+ expect(isCreatablePage('/me')).toBeFalsy();
|
|
|
+ expect(isCreatablePage('/me/')).toBeFalsy();
|
|
|
+ expect(isCreatablePage('/me/x')).toBeFalsy();
|
|
|
+ expect(isCreatablePage('/meeting')).toBeTruthy();
|
|
|
+ expect(isCreatablePage('/meeting/x')).toBeTruthy();
|
|
|
+
|
|
|
+ // end with "edit"
|
|
|
+ expect(isCreatablePage('/meeting/edit')).toBeFalsy();
|
|
|
+
|
|
|
+ // under score
|
|
|
+ expect(isCreatablePage('/_')).toBeTruthy();
|
|
|
+ expect(isCreatablePage('/_template')).toBeTruthy();
|
|
|
+ expect(isCreatablePage('/__template')).toBeTruthy();
|
|
|
+ expect(isCreatablePage('/_r/x')).toBeFalsy();
|
|
|
+ expect(isCreatablePage('/_api')).toBeFalsy();
|
|
|
+ expect(isCreatablePage('/_apix')).toBeFalsy();
|
|
|
+ expect(isCreatablePage('/_api/x')).toBeFalsy();
|
|
|
+
|
|
|
+ expect(isCreatablePage('/hoge/xx.md')).toBeFalsy();
|
|
|
+
|
|
|
+ // relative path
|
|
|
+ expect(isCreatablePage('/..')).toBeFalsy();
|
|
|
+ expect(isCreatablePage('/../page')).toBeFalsy();
|
|
|
+ expect(isCreatablePage('/page/..')).toBeFalsy();
|
|
|
+ expect(isCreatablePage('/page/../page')).toBeFalsy();
|
|
|
+
|
|
|
+ // start with https?
|
|
|
+ expect(isCreatablePage('/http://demo.growi.org/hoge')).toBeFalsy();
|
|
|
+ expect(isCreatablePage('/https://demo.growi.org/hoge')).toBeFalsy();
|
|
|
+ expect(isCreatablePage('http://demo.growi.org/hoge')).toBeFalsy();
|
|
|
+ expect(isCreatablePage('https://demo.growi.org/hoge')).toBeFalsy();
|
|
|
+
|
|
|
+ expect(isCreatablePage('/ the / path / with / space')).toBeFalsy();
|
|
|
+
|
|
|
+ const forbidden = ['installer', 'register', 'login', 'logout',
|
|
|
+ 'admin', 'files', 'trash', 'paste', 'comments'];
|
|
|
+ for (let i = 0; i < forbidden.length; i++) {
|
|
|
+ const pn = forbidden[i];
|
|
|
+ expect(isCreatablePage(`/${pn}`)).toBeFalsy();
|
|
|
+ expect(isCreatablePage(`/${pn}/`)).toBeFalsy();
|
|
|
+ expect(isCreatablePage(`/${pn}/abc`)).toBeFalsy();
|
|
|
+ }
|
|
|
+ });
|
|
|
+});
|