|
@@ -1,8 +1,6 @@
|
|
|
import type { IncomingMessage } from 'http';
|
|
import type { IncomingMessage } from 'http';
|
|
|
|
|
|
|
|
-import {
|
|
|
|
|
- describe, it, expect, beforeEach,
|
|
|
|
|
-} from 'vitest';
|
|
|
|
|
|
|
+import { beforeEach, describe, expect, it } from 'vitest';
|
|
|
|
|
|
|
|
import { pageApiModule } from './page-api-handler';
|
|
import { pageApiModule } from './page-api-handler';
|
|
|
|
|
|
|
@@ -15,22 +13,22 @@ describe('pageApiModule', () => {
|
|
|
|
|
|
|
|
describe('canHandle', () => {
|
|
describe('canHandle', () => {
|
|
|
it.each`
|
|
it.each`
|
|
|
- description | url | expected
|
|
|
|
|
- ${'pages list endpoint'} | ${'/_api/v3/pages/list?path=/home'} | ${true}
|
|
|
|
|
- ${'subordinated list endpoint'} | ${'/_api/v3/pages/subordinated-list?path=/docs'} | ${true}
|
|
|
|
|
- ${'check page existence endpoint'} | ${'/_api/v3/page/check-page-existence?path=/wiki'} | ${true}
|
|
|
|
|
- ${'get page paths with descendant count endpoint'} | ${'/_api/v3/page/get-page-paths-with-descendant-count?paths=[]'} | ${true}
|
|
|
|
|
- ${'pages list without query'} | ${'/_api/v3/pages/list'} | ${true}
|
|
|
|
|
- ${'subordinated list without query'} | ${'/_api/v3/pages/subordinated-list'} | ${true}
|
|
|
|
|
- ${'check page existence without query'} | ${'/_api/v3/page/check-page-existence'} | ${true}
|
|
|
|
|
- ${'get page paths without query'} | ${'/_api/v3/page/get-page-paths-with-descendant-count'} | ${true}
|
|
|
|
|
- ${'other pages endpoint'} | ${'/_api/v3/pages/create'} | ${false}
|
|
|
|
|
- ${'different API version'} | ${'/_api/v2/pages/list'} | ${false}
|
|
|
|
|
- ${'non-page API'} | ${'/_api/v3/search'} | ${false}
|
|
|
|
|
- ${'regular page path'} | ${'/page/path'} | ${false}
|
|
|
|
|
- ${'root path'} | ${'/'} | ${false}
|
|
|
|
|
- ${'empty URL'} | ${''} | ${false}
|
|
|
|
|
- ${'partial match but different endpoint'} | ${'/_api/v3/pages-other/list'} | ${false}
|
|
|
|
|
|
|
+ description | url | expected
|
|
|
|
|
+ ${'pages list endpoint'} | ${'/_api/v3/pages/list?path=/home'} | ${true}
|
|
|
|
|
+ ${'subordinated list endpoint'} | ${'/_api/v3/pages/subordinated-list?path=/docs'} | ${true}
|
|
|
|
|
+ ${'check page existence endpoint'} | ${'/_api/v3/page/check-page-existence?path=/wiki'} | ${true}
|
|
|
|
|
+ ${'get page paths with descendant count endpoint'} | ${'/_api/v3/page/get-page-paths-with-descendant-count?paths=[]'} | ${true}
|
|
|
|
|
+ ${'pages list without query'} | ${'/_api/v3/pages/list'} | ${true}
|
|
|
|
|
+ ${'subordinated list without query'} | ${'/_api/v3/pages/subordinated-list'} | ${true}
|
|
|
|
|
+ ${'check page existence without query'} | ${'/_api/v3/page/check-page-existence'} | ${true}
|
|
|
|
|
+ ${'get page paths without query'} | ${'/_api/v3/page/get-page-paths-with-descendant-count'} | ${true}
|
|
|
|
|
+ ${'other pages endpoint'} | ${'/_api/v3/pages/create'} | ${false}
|
|
|
|
|
+ ${'different API version'} | ${'/_api/v2/pages/list'} | ${false}
|
|
|
|
|
+ ${'non-page API'} | ${'/_api/v3/search'} | ${false}
|
|
|
|
|
+ ${'regular page path'} | ${'/page/path'} | ${false}
|
|
|
|
|
+ ${'root path'} | ${'/'} | ${false}
|
|
|
|
|
+ ${'empty URL'} | ${''} | ${false}
|
|
|
|
|
+ ${'partial match but different endpoint'} | ${'/_api/v3/pages-other/list'} | ${false}
|
|
|
`('should return $expected for $description: $url', ({ url, expected }) => {
|
|
`('should return $expected for $description: $url', ({ url, expected }) => {
|
|
|
const result = pageApiModule.canHandle(url);
|
|
const result = pageApiModule.canHandle(url);
|
|
|
expect(result).toBe(expected);
|
|
expect(result).toBe(expected);
|
|
@@ -66,7 +64,8 @@ describe('pageApiModule', () => {
|
|
|
|
|
|
|
|
describe('pages/subordinated-list endpoint', () => {
|
|
describe('pages/subordinated-list endpoint', () => {
|
|
|
it('should anonymize path parameter', () => {
|
|
it('should anonymize path parameter', () => {
|
|
|
- const originalUrl = '/_api/v3/pages/subordinated-list?path=/user/documents&offset=0';
|
|
|
|
|
|
|
+ const originalUrl =
|
|
|
|
|
+ '/_api/v3/pages/subordinated-list?path=/user/documents&offset=0';
|
|
|
|
|
|
|
|
// Verify canHandle returns true for this URL
|
|
// Verify canHandle returns true for this URL
|
|
|
expect(pageApiModule.canHandle(originalUrl)).toBe(true);
|
|
expect(pageApiModule.canHandle(originalUrl)).toBe(true);
|
|
@@ -74,12 +73,14 @@ describe('pageApiModule', () => {
|
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
expect(result).toEqual({
|
|
|
- 'http.target': '/_api/v3/pages/subordinated-list?path=%5BANONYMIZED%5D&offset=0',
|
|
|
|
|
|
|
+ 'http.target':
|
|
|
|
|
+ '/_api/v3/pages/subordinated-list?path=%5BANONYMIZED%5D&offset=0',
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should handle encoded path parameters', () => {
|
|
it('should handle encoded path parameters', () => {
|
|
|
- const originalUrl = '/_api/v3/pages/subordinated-list?path=%2Fuser%2Fdocs&includeEmpty=true';
|
|
|
|
|
|
|
+ const originalUrl =
|
|
|
|
|
+ '/_api/v3/pages/subordinated-list?path=%2Fuser%2Fdocs&includeEmpty=true';
|
|
|
|
|
|
|
|
// Verify canHandle returns true for this URL
|
|
// Verify canHandle returns true for this URL
|
|
|
expect(pageApiModule.canHandle(originalUrl)).toBe(true);
|
|
expect(pageApiModule.canHandle(originalUrl)).toBe(true);
|
|
@@ -87,14 +88,16 @@ describe('pageApiModule', () => {
|
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
expect(result).toEqual({
|
|
|
- 'http.target': '/_api/v3/pages/subordinated-list?path=%5BANONYMIZED%5D&includeEmpty=true',
|
|
|
|
|
|
|
+ 'http.target':
|
|
|
|
|
+ '/_api/v3/pages/subordinated-list?path=%5BANONYMIZED%5D&includeEmpty=true',
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
describe('page/check-page-existence endpoint', () => {
|
|
describe('page/check-page-existence endpoint', () => {
|
|
|
it('should anonymize path parameter', () => {
|
|
it('should anonymize path parameter', () => {
|
|
|
- const originalUrl = '/_api/v3/page/check-page-existence?path=/project/wiki';
|
|
|
|
|
|
|
+ const originalUrl =
|
|
|
|
|
+ '/_api/v3/page/check-page-existence?path=/project/wiki';
|
|
|
|
|
|
|
|
// Verify canHandle returns true for this URL
|
|
// Verify canHandle returns true for this URL
|
|
|
expect(pageApiModule.canHandle(originalUrl)).toBe(true);
|
|
expect(pageApiModule.canHandle(originalUrl)).toBe(true);
|
|
@@ -102,12 +105,14 @@ describe('pageApiModule', () => {
|
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
expect(result).toEqual({
|
|
|
- 'http.target': '/_api/v3/page/check-page-existence?path=%5BANONYMIZED%5D',
|
|
|
|
|
|
|
+ 'http.target':
|
|
|
|
|
+ '/_api/v3/page/check-page-existence?path=%5BANONYMIZED%5D',
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should handle multiple parameters including path', () => {
|
|
it('should handle multiple parameters including path', () => {
|
|
|
- const originalUrl = '/_api/v3/page/check-page-existence?path=/docs/api&includePrivate=false';
|
|
|
|
|
|
|
+ const originalUrl =
|
|
|
|
|
+ '/_api/v3/page/check-page-existence?path=/docs/api&includePrivate=false';
|
|
|
|
|
|
|
|
// Verify canHandle returns true for this URL
|
|
// Verify canHandle returns true for this URL
|
|
|
expect(pageApiModule.canHandle(originalUrl)).toBe(true);
|
|
expect(pageApiModule.canHandle(originalUrl)).toBe(true);
|
|
@@ -115,14 +120,16 @@ describe('pageApiModule', () => {
|
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
expect(result).toEqual({
|
|
|
- 'http.target': '/_api/v3/page/check-page-existence?path=%5BANONYMIZED%5D&includePrivate=false',
|
|
|
|
|
|
|
+ 'http.target':
|
|
|
|
|
+ '/_api/v3/page/check-page-existence?path=%5BANONYMIZED%5D&includePrivate=false',
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
describe('page/get-page-paths-with-descendant-count endpoint', () => {
|
|
describe('page/get-page-paths-with-descendant-count endpoint', () => {
|
|
|
it('should anonymize paths parameter when present', () => {
|
|
it('should anonymize paths parameter when present', () => {
|
|
|
- const originalUrl = '/_api/v3/page/get-page-paths-with-descendant-count?paths=["/docs","/wiki"]';
|
|
|
|
|
|
|
+ const originalUrl =
|
|
|
|
|
+ '/_api/v3/page/get-page-paths-with-descendant-count?paths=["/docs","/wiki"]';
|
|
|
|
|
|
|
|
// Verify canHandle returns true for this URL
|
|
// Verify canHandle returns true for this URL
|
|
|
expect(pageApiModule.canHandle(originalUrl)).toBe(true);
|
|
expect(pageApiModule.canHandle(originalUrl)).toBe(true);
|
|
@@ -130,12 +137,14 @@ describe('pageApiModule', () => {
|
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
expect(result).toEqual({
|
|
|
- 'http.target': '/_api/v3/page/get-page-paths-with-descendant-count?paths=%5B%22%5BANONYMIZED%5D%22%5D',
|
|
|
|
|
|
|
+ 'http.target':
|
|
|
|
|
+ '/_api/v3/page/get-page-paths-with-descendant-count?paths=%5B%22%5BANONYMIZED%5D%22%5D',
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should handle encoded paths parameter', () => {
|
|
it('should handle encoded paths parameter', () => {
|
|
|
- const originalUrl = '/_api/v3/page/get-page-paths-with-descendant-count?paths=%5B%22%2Fdocs%22%5D';
|
|
|
|
|
|
|
+ const originalUrl =
|
|
|
|
|
+ '/_api/v3/page/get-page-paths-with-descendant-count?paths=%5B%22%2Fdocs%22%5D';
|
|
|
|
|
|
|
|
// Verify canHandle returns true for this URL
|
|
// Verify canHandle returns true for this URL
|
|
|
expect(pageApiModule.canHandle(originalUrl)).toBe(true);
|
|
expect(pageApiModule.canHandle(originalUrl)).toBe(true);
|
|
@@ -143,12 +152,14 @@ describe('pageApiModule', () => {
|
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
expect(result).toEqual({
|
|
|
- 'http.target': '/_api/v3/page/get-page-paths-with-descendant-count?paths=%5B%22%5BANONYMIZED%5D%22%5D',
|
|
|
|
|
|
|
+ 'http.target':
|
|
|
|
|
+ '/_api/v3/page/get-page-paths-with-descendant-count?paths=%5B%22%5BANONYMIZED%5D%22%5D',
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should return null when no paths parameter is present', () => {
|
|
it('should return null when no paths parameter is present', () => {
|
|
|
- const url = '/_api/v3/page/get-page-paths-with-descendant-count?includeEmpty=true';
|
|
|
|
|
|
|
+ const url =
|
|
|
|
|
+ '/_api/v3/page/get-page-paths-with-descendant-count?includeEmpty=true';
|
|
|
|
|
|
|
|
// Verify canHandle returns true for this URL
|
|
// Verify canHandle returns true for this URL
|
|
|
expect(pageApiModule.canHandle(url)).toBe(true);
|
|
expect(pageApiModule.canHandle(url)).toBe(true);
|
|
@@ -217,12 +228,14 @@ describe('pageApiModule', () => {
|
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
expect(result).toEqual({
|
|
|
- 'http.target': '/_api/v3/page/check-page-existence?path=%5BANONYMIZED%5D',
|
|
|
|
|
|
|
+ 'http.target':
|
|
|
|
|
+ '/_api/v3/page/check-page-existence?path=%5BANONYMIZED%5D',
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should handle empty paths array parameter', () => {
|
|
it('should handle empty paths array parameter', () => {
|
|
|
- const originalUrl = '/_api/v3/page/get-page-paths-with-descendant-count?paths=[]';
|
|
|
|
|
|
|
+ const originalUrl =
|
|
|
|
|
+ '/_api/v3/page/get-page-paths-with-descendant-count?paths=[]';
|
|
|
|
|
|
|
|
// Verify canHandle returns true for this URL
|
|
// Verify canHandle returns true for this URL
|
|
|
expect(pageApiModule.canHandle(originalUrl)).toBe(true);
|
|
expect(pageApiModule.canHandle(originalUrl)).toBe(true);
|
|
@@ -230,7 +243,8 @@ describe('pageApiModule', () => {
|
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
const result = pageApiModule.handle(mockRequest, originalUrl);
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
expect(result).toEqual({
|
|
|
- 'http.target': '/_api/v3/page/get-page-paths-with-descendant-count?paths=%5BANONYMIZED%5D',
|
|
|
|
|
|
|
+ 'http.target':
|
|
|
|
|
+ '/_api/v3/page/get-page-paths-with-descendant-count?paths=%5BANONYMIZED%5D',
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|