@vscode/test-web 0.0.26 → 0.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,12 +1,13 @@
1
1
  # Changelog
2
-
2
+ ## 0.0.28
3
+ * new option `--coi` to enable cross origin isolation.
3
4
 
4
5
  ## 0.0.22
5
- * new option `--printServerLog` replacing `--hideServerLog`
6
- * new option `--browser` replacing `--browserType`
6
+ * new option `--printServerLog` replacing `--hideServerLog`.
7
+ * new option `--browser` replacing `--browserType`.
7
8
 
8
9
  ## 0.0.20
9
- * new option `--extensionId publisher.name[@prerelease]` to include one or more extensions
10
+ * new option `--extensionId publisher.name[@prerelease]` to include one or more extensions.
10
11
 
11
12
  ## 0.0.18
12
13
  * new option `--browserType none` to start the server without opening a browser.
@@ -17,7 +18,7 @@
17
18
 
18
19
  ## 0.0.16
19
20
  * new option `--sourcesPath`: If provided, runs the server from VS Code sources at the given location.
20
- * option `--version` is deprecated and replaced with `quality`. Supported values: `stable`, `insiders`. Instead of `sources` use `--insiders`
21
+ * option `--version` is deprecated and replaced with `quality`. Supported values: `stable`, `insiders`. Instead of `sources` use `--insiders`.
21
22
 
22
23
  ## 0.0.14
23
24
  * new option `--extensionPath` : A path pointing to a folder containing additional extensions to include. Argument can be provided multiple times.
package/README.md CHANGED
@@ -74,6 +74,7 @@ CLI options:
74
74
  | --sourcesPath | If set, runs the server from VS Code sources located at the given path. Make sure the sources and extensions are compiled (`yarn compile` and `yarn compile-web`). |
75
75
  | --headless | If set, hides the browser. Defaults to true when an extensionTestsPath is provided, otherwise false. |
76
76
  | --permission | Permission granted to the opened browser: e.g. `clipboard-read`, `clipboard-write`. See [full list of options](https://playwright.dev/docs/api/class-browsercontext#browser-context-grant-permissions). Argument can be provided multiple times. |
77
+ | --coi | If set, enables cross origin isolation. Defaults to false. |
77
78
  | --folder-uri | URI of the workspace to open VS Code on. Ignored when `folderPath` is provided. |
78
79
  | --extensionPath | A path pointing to a folder containing additional extensions to include. Argument can be provided multiple times. |
79
80
  | --extensionId | The id of an extension include. The format is `${publisher}.${name}`. Append `@prerelease` to use the prerelease version. |
package/out/index.d.ts CHANGED
@@ -50,6 +50,10 @@ export interface Options {
50
50
  * Do not show the browser. Defaults to `true` if a `extensionTestsPath` is provided, `false` otherwise.
51
51
  */
52
52
  headless?: boolean;
53
+ /**
54
+ * If set, opens the page with cross origin isolation enabled.
55
+ */
56
+ coi?: boolean;
53
57
  /**
54
58
  * @deprecated. Use `printServerLog` instead.
55
59
  */
package/out/index.js CHANGED
@@ -27,7 +27,8 @@ async function runTests(options) {
27
27
  folderMountPath: options.folderPath,
28
28
  printServerLog: (_a = options.printServerLog) !== null && _a !== void 0 ? _a : options.hideServerLog === false,
29
29
  extensionPaths: options.extensionPaths,
30
- extensionIds: options.extensionIds
30
+ extensionIds: options.extensionIds,
31
+ coi: !!options.coi
31
32
  };
32
33
  const host = (_b = options.host) !== null && _b !== void 0 ? _b : 'localhost';
33
34
  const port = (_c = options.port) !== null && _c !== void 0 ? _c : 3000;
@@ -84,7 +85,8 @@ async function open(options) {
84
85
  folderMountPath: options.folderPath,
85
86
  printServerLog: (_a = options.printServerLog) !== null && _a !== void 0 ? _a : options.hideServerLog === false,
86
87
  extensionPaths: options.extensionPaths,
87
- extensionIds: options.extensionIds
88
+ extensionIds: options.extensionIds,
89
+ coi: !!options.coi
88
90
  };
89
91
  const host = (_b = options.host) !== null && _b !== void 0 ? _b : 'localhost';
90
92
  const port = (_c = options.port) !== null && _c !== void 0 ? _c : 3000;
@@ -180,7 +182,7 @@ function validatePrintServerLog(options) {
180
182
  }
181
183
  return false;
182
184
  }
183
- function valdiateBrowserType(options) {
185
+ function validateBrowserType(options) {
184
186
  const browserType = options.browser || options.browserType;
185
187
  if (browserType === undefined) {
186
188
  return 'chromium';
@@ -195,7 +197,7 @@ function valdiateBrowserType(options) {
195
197
  showHelp();
196
198
  process.exit(-1);
197
199
  }
198
- function valdiatePermissions(permissions) {
200
+ function validatePermissions(permissions) {
199
201
  if (permissions === undefined) {
200
202
  return undefined;
201
203
  }
@@ -212,7 +214,7 @@ function valdiatePermissions(permissions) {
212
214
  showHelp();
213
215
  process.exit(-1);
214
216
  }
215
- async function valdiateExtensionPaths(extensionPaths) {
217
+ async function validateExtensionPaths(extensionPaths) {
216
218
  if (extensionPaths === undefined) {
217
219
  return undefined;
218
220
  }
@@ -236,7 +238,7 @@ async function valdiateExtensionPaths(extensionPaths) {
236
238
  process.exit(-1);
237
239
  }
238
240
  const EXTENSION_IDENTIFIER_PATTERN = /^([a-z0-9A-Z][a-z0-9-A-Z]*\.[a-z0-9A-Z][a-z0-9-A-Z]*)(@prerelease)?$/;
239
- async function valdiateExtensionIds(extensionIds) {
241
+ async function validateExtensionIds(extensionIds) {
240
242
  if (extensionIds === undefined) {
241
243
  return undefined;
242
244
  }
@@ -324,6 +326,7 @@ function showHelp() {
324
326
  console.log(` --open-devtools: If set, opens the dev tools. [Optional]`);
325
327
  console.log(` --headless: Whether to hide the browser. Defaults to true when an extensionTestsPath is provided, otherwise false. [Optional]`);
326
328
  console.log(` --permission: Permission granted in the opened browser: e.g. 'clipboard-read', 'clipboard-write'. [Optional, Multiple]`);
329
+ console.log(` --coi: Enables cross origin isolation [Optional]`);
327
330
  console.log(` --folder-uri: workspace to open VS Code on. Ignored when folderPath is provided. [Optional]`);
328
331
  console.log(` --extensionPath: A path pointing to a folder containing additional extensions to include [Optional, Multiple]`);
329
332
  console.log(` --extensionId: The id of an extension include. The format is '\${publisher}.\${name}'. Append '@prerelease' to use a prerelease version [Optional, Multiple]`);
@@ -340,7 +343,7 @@ async function cliMain() {
340
343
  console.log(`${manifest.name}: ${manifest.version}`);
341
344
  const options = {
342
345
  string: ['extensionDevelopmentPath', 'extensionTestsPath', 'browser', 'browserType', 'quality', 'version', 'waitForDebugger', 'folder-uri', 'permission', 'extensionPath', 'extensionId', 'sourcesPath', 'host', 'port'],
343
- boolean: ['open-devtools', 'headless', 'hideServerLog', 'printServerLog', 'help', 'verbose'],
346
+ boolean: ['open-devtools', 'headless', 'hideServerLog', 'printServerLog', 'help', 'verbose', 'coi'],
344
347
  unknown: arg => {
345
348
  if (arg.startsWith('-')) {
346
349
  console.log(`Unknown argument ${arg}`);
@@ -355,20 +358,21 @@ async function cliMain() {
355
358
  showHelp();
356
359
  process.exit();
357
360
  }
358
- const browserType = valdiateBrowserType(args);
361
+ const browserType = validateBrowserType(args);
359
362
  const extensionTestsPath = await validatePathOrUndefined(args, 'extensionTestsPath', true);
360
363
  const extensionDevelopmentPath = await validatePathOrUndefined(args, 'extensionDevelopmentPath');
361
- const extensionPaths = await valdiateExtensionPaths(args.extensionPath);
362
- const extensionIds = await valdiateExtensionIds(args.extensionId);
364
+ const extensionPaths = await validateExtensionPaths(args.extensionPath);
365
+ const extensionIds = await validateExtensionIds(args.extensionId);
363
366
  const vsCodeDevPath = await validatePathOrUndefined(args, 'sourcesPath');
364
367
  const quality = validateQuality(args.quality, args.version, vsCodeDevPath);
365
368
  const devTools = validateBooleanOrUndefined(args, 'open-devtools');
366
369
  const headless = validateBooleanOrUndefined(args, 'headless');
367
- const permissions = valdiatePermissions(args.permission);
370
+ const permissions = validatePermissions(args.permission);
368
371
  const printServerLog = validatePrintServerLog(args);
369
372
  const verbose = validateBooleanOrUndefined(args, 'verbose');
370
373
  const port = validatePortNumber(args.port);
371
374
  const host = validateStringOrUndefined(args, 'host');
375
+ const coi = validateBooleanOrUndefined(args, 'coi');
372
376
  const waitForDebugger = validatePortNumber(args.waitForDebugger);
373
377
  let folderUri = validateStringOrUndefined(args, 'folder-uri');
374
378
  let folderPath;
@@ -400,6 +404,7 @@ async function cliMain() {
400
404
  extensionIds,
401
405
  vsCodeDevPath,
402
406
  verbose,
407
+ coi,
403
408
  host,
404
409
  port
405
410
  }).catch(e => {
@@ -423,6 +428,7 @@ async function cliMain() {
423
428
  extensionIds,
424
429
  vsCodeDevPath,
425
430
  verbose,
431
+ coi,
426
432
  host,
427
433
  port
428
434
  });
package/out/server/app.js CHANGED
@@ -4,11 +4,13 @@
4
4
  * Licensed under the MIT License. See License.txt in the project root for license information.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ const fs_1 = require("fs");
7
8
  const Koa = require("koa");
8
9
  const morgan = require("koa-morgan");
9
10
  const kstatic = require("koa-static");
10
11
  const kmount = require("koa-mount");
11
12
  const cors = require("@koa/cors");
13
+ const getstream = require("get-stream");
12
14
  const path_1 = require("path");
13
15
  const workbench_1 = require("./workbench");
14
16
  const mounts_1 = require("./mounts");
@@ -21,17 +23,43 @@ async function createApp(config) {
21
23
  allowMethods: ['GET'],
22
24
  credentials: true,
23
25
  origin: (ctx) => {
24
- if (/^https:\/\/[^.]+\.vscode-webview\.net$/.test(ctx.get('Origin'))) {
26
+ if (/^https:\/\/[^.]+\.vscode-cdn\.net$/.test(ctx.get('Origin')) || // needed for the webviewContent
27
+ /^https:\/\/[^.]+\.vscode-webview\.net$/.test(ctx.get('Origin'))) {
25
28
  return ctx.get('Origin');
26
29
  }
27
30
  return undefined;
28
31
  },
29
32
  }));
30
- // this is here such that the iframe worker can fetch the extension files
33
+ if (config.build.type !== 'sources') {
34
+ // CSP: frame-ancestors
35
+ app.use((ctx, next) => {
36
+ ctx.set('Content-Security-Policy', `frame-ancestors 'none'`);
37
+ return next();
38
+ });
39
+ }
40
+ // COI
31
41
  app.use((ctx, next) => {
32
- ctx.set('Access-Control-Allow-Origin', '*');
42
+ const value = ctx.query['vscode-coi'];
43
+ if (value === '1') {
44
+ ctx.set('Cross-Origin-Opener-Policy', 'same-origin');
45
+ }
46
+ else if (value === '2') {
47
+ ctx.set('Cross-Origin-Embedder-Policy', 'require-corp');
48
+ }
49
+ else if (value === '3' || value === '') {
50
+ ctx.set('Cross-Origin-Opener-Policy', 'same-origin');
51
+ ctx.set('Cross-Origin-Embedder-Policy', 'require-corp');
52
+ }
33
53
  return next();
34
54
  });
55
+ // shift the line numbers of source maps in extensions by 2 as the content is wrapped by an anonymous function
56
+ app.use(async (ctx, next) => {
57
+ await next();
58
+ if (ctx.status === 200 && ctx.path.match(/\/(dev)?extensions\/.*\.js\.map$/) && ctx.body instanceof fs_1.ReadStream) {
59
+ // we know it's a ReadStream as that's what kstatic uses
60
+ ctx.response.body = `{"version":3,"file":"${(0, path_1.basename)(ctx.path)}","sections":[{"offset":{"line":2,"column":0},"map":${await getstream(ctx.body)} }]}`;
61
+ }
62
+ });
35
63
  const serveOptions = { hidden: true };
36
64
  if (config.extensionDevelopmentPath) {
37
65
  console.log('Serving dev extensions from ' + config.extensionDevelopmentPath);
@@ -117,6 +117,10 @@ function default_1(config) {
117
117
  router.get('/', async (ctx) => {
118
118
  const options = await getWorkbenchOptions(ctx, config);
119
119
  ctx.body = await ctx.state.workbench.render(options);
120
+ if (config.coi) {
121
+ ctx.set('Cross-Origin-Opener-Policy', 'same-origin');
122
+ ctx.set('Cross-Origin-Embedder-Policy', 'require-corp');
123
+ }
120
124
  });
121
125
  return router.routes();
122
126
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vscode/test-web",
3
- "version": "0.0.26",
3
+ "version": "0.0.29",
4
4
  "scripts": {
5
5
  "install-extensions": "yarn --cwd=fs-provider && yarn --cwd=sample",
6
6
  "compile": "tsc -p ./ && yarn compile-fs-provider",
@@ -35,7 +35,8 @@
35
35
  "http-proxy-agent": "^5.0.0",
36
36
  "https-proxy-agent": "^5.0.1",
37
37
  "decompress": "^4.2.1",
38
- "decompress-targz": "^4.1.1"
38
+ "decompress-targz": "^4.1.1",
39
+ "get-stream": "6.0.1"
39
40
  },
40
41
  "devDependencies": {
41
42
  "@types/koa": "^2.13.4",