Skip to content

Commit 2e02a71

Browse files
committed
Add integration test for untrusted workspace
1 parent 7eb7b2d commit 2e02a71

File tree

10 files changed

+131
-2
lines changed

10 files changed

+131
-2
lines changed

.vscode/launch.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,38 @@
1111
"outFiles": ["${workspaceRoot}/dist/*.js"],
1212
"preLaunchTask": "packageDev"
1313
},
14+
{
15+
"name": "[Untrusted] Run Integration Test",
16+
"type": "extensionHost",
17+
"request": "launch",
18+
"runtimeExecutable": "${execPath}",
19+
"args": [
20+
// Launch VSCode using a specific profile to ensure that user settings are not used.
21+
// This profile must be imported into vscode before running this launch configuration.
22+
// The profile can be found under /test/csharp-test-profile.
23+
"--profile",
24+
"csharp-test-profile",
25+
"${workspaceRoot}/test/untrustedWorkspace/integrationTests/testAssets/empty/.vscode/empty.code-workspace",
26+
"--extensionDevelopmentPath=${workspaceRoot}",
27+
"--extensionTestsPath=${workspaceRoot}/out/test/untrustedWorkspace/integrationTests",
28+
"--log",
29+
"ms-dotnettools.csharp:trace"
30+
],
31+
"env": {
32+
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
33+
},
34+
"sourceMaps": true,
35+
"outFiles": [
36+
"${workspaceRoot}/dist/*.js",
37+
"${workspaceRoot}/out/test/**/*.js"
38+
],
39+
"resolveSourceMapLocations": [
40+
"${workspaceFolder}/**",
41+
"!**/node_modules/**"
42+
],
43+
"preLaunchTask": "packageDev",
44+
"internalConsoleOptions": "openOnSessionStart"
45+
},
1446
{
1547
"name": "[Roslyn] Run Current File Integration Tests",
1648
"type": "extensionHost",

azure-pipelines/test-matrix.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
RazorCohostTests:
3232
npmCommand: test:integration:razor:cohost
3333
isIntegration: true
34+
UntrustedWorkspaceTest:
35+
npmCommand: test:integration:untrusted
36+
isIntegration: true
3437
pool: ${{ parameters.pool }}
3538
${{ if parameters.containerName }}:
3639
container: ${{ parameters.containerName }}
@@ -41,4 +44,4 @@ jobs:
4144
installAdditionalLinuxDependencies: ${{ parameters.installAdditionalLinuxDependencies }}
4245
npmCommand: $(npmCommand)
4346
testVSCodeVersion: ${{ parameters.testVSCodeVersion }}
44-
isIntegration: $(isIntegration)
47+
isIntegration: $(isIntegration)

jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const config: Config = {
1313
'<rootDir>/test/omnisharp/omnisharpUnitTests/jest.config.ts',
1414
'<rootDir>/test/razor/razorIntegrationTests/jest.config.ts',
1515
'<rootDir>/test/razor/razorTests/jest.config.ts',
16+
'<rootDir>/test/untrustedWorkspace/integrationTests/jest.config.ts',
1617
],
1718
// Reporters are a global jest configuration property and cannot be set in the project jest config.
1819
// This configuration will create a 'junit.xml' file in the output directory, no matter which test project is running.

tasks/testTasks.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ function createIntegrationTestSubTasks() {
7474
gulp.series(integrationTestProjects.map((projectName) => `test:integration:devkit:${projectName}`))
7575
);
7676

77+
gulp.task('test:integration:untrusted', async () =>
78+
runIntegrationTest('empty', path.join('untrustedWorkspace', 'integrationTests'), `[C#][empty]`)
79+
);
80+
7781
for (const projectName of razorIntegrationTestProjects) {
7882
gulp.task(`test:integration:razor:${projectName}`, async () =>
7983
// Run DevKit tests because razor doesn't gracefully handle roslyn restarting
@@ -108,7 +112,12 @@ function createIntegrationTestSubTasks() {
108112

109113
gulp.task(
110114
'test:integration',
111-
gulp.series('test:integration:csharp', 'test:integration:devkit', 'test:integration:razor')
115+
gulp.series(
116+
'test:integration:csharp',
117+
'test:integration:devkit',
118+
'test:integration:razor',
119+
'test:integration:untrusted'
120+
)
112121
);
113122
}
114123

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { runIntegrationTests } from '../../runIntegrationTests';
7+
import { jestIntegrationTestProjectName } from './jest.config';
8+
9+
export async function run() {
10+
process.env.RUNNING_INTEGRATION_TESTS = 'true';
11+
12+
await runIntegrationTests(jestIntegrationTestProjectName);
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
import type { Config } from 'jest';
6+
import { baseProjectConfig } from '../../../baseJestConfig';
7+
8+
export const jestIntegrationTestProjectName = 'Untrusted Integration Tests';
9+
10+
/**
11+
* Defines a project configuration for jest integration tests.
12+
*/
13+
const integrationTestConfig: Config = {
14+
...baseProjectConfig,
15+
displayName: jestIntegrationTestProjectName,
16+
roots: ['<rootDir>'],
17+
testEnvironment: '<rootDir>/../../vsCodeEnvironment.ts',
18+
setupFilesAfterEnv: ['<rootDir>/../../vsCodeFramework.ts'],
19+
};
20+
21+
export default integrationTestConfig;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"folders": [
3+
{
4+
"path": ".."
5+
}
6+
],
7+
"settings": {
8+
"dotnet.server.useOmnisharp": false,
9+
"dotnet.preferCSharpExtension": false,
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"folders": [
3+
{
4+
"path": ".."
5+
}
6+
],
7+
"settings": {
8+
"dotnet.server.useOmnisharp": false,
9+
"dotnet.preferCSharpExtension": true,
10+
}
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This folder left empty so that the C# extension does not automatically activate.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { describe, expect, jest, test } from '@jest/globals';
7+
import * as vscode from 'vscode';
8+
import { CSharpExtensionExports, LimitedExtensionExports } from '../../../src/csharpExtensionExports';
9+
10+
describe(`Untrusted Workspace`, () => {
11+
test(`Limited activation in untrusted workspace`, async () => {
12+
// Simulate an untrusted workspace by setting isTrusted to false
13+
jest.spyOn(vscode.workspace, 'isTrusted', 'get').mockReturnValue(false);
14+
15+
const extension = vscode.extensions.getExtension<CSharpExtensionExports | LimitedExtensionExports>(
16+
'ms-dotnettools.csharp'
17+
);
18+
if (!extension) {
19+
throw new Error('Failed to find installation of ms-dotnettools.csharp');
20+
}
21+
22+
expect(extension.isActive).toBe(false);
23+
await extension.activate();
24+
25+
expect(extension.exports.isLimitedActivation).toBe(true);
26+
});
27+
});

0 commit comments

Comments
 (0)