@theia/workspace 1.68.0-next.7 → 1.68.0-next.79
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/lib/browser/quick-open-workspace.js +3 -4
- package/lib/browser/quick-open-workspace.js.map +1 -1
- package/lib/browser/workspace-breadcrumbs-contribution.js +3 -3
- package/lib/browser/workspace-breadcrumbs-contribution.js.map +1 -1
- package/lib/browser/workspace-commands.d.ts +1 -0
- package/lib/browser/workspace-commands.d.ts.map +1 -1
- package/lib/browser/workspace-commands.js +6 -2
- package/lib/browser/workspace-commands.js.map +1 -1
- package/lib/browser/workspace-frontend-contribution.d.ts +5 -1
- package/lib/browser/workspace-frontend-contribution.d.ts.map +1 -1
- package/lib/browser/workspace-frontend-contribution.js +48 -7
- package/lib/browser/workspace-frontend-contribution.js.map +1 -1
- package/lib/browser/workspace-frontend-module.d.ts +1 -0
- package/lib/browser/workspace-frontend-module.d.ts.map +1 -1
- package/lib/browser/workspace-frontend-module.js +2 -0
- package/lib/browser/workspace-frontend-module.js.map +1 -1
- package/lib/browser/workspace-schema-updater.d.ts.map +1 -1
- package/lib/browser/workspace-service.js +3 -5
- package/lib/browser/workspace-service.js.map +1 -1
- package/lib/browser/workspace-trust-dialog.d.ts +13 -0
- package/lib/browser/workspace-trust-dialog.d.ts.map +1 -0
- package/lib/browser/workspace-trust-dialog.js +66 -0
- package/lib/browser/workspace-trust-dialog.js.map +1 -0
- package/lib/browser/workspace-trust-service.d.ts +77 -1
- package/lib/browser/workspace-trust-service.d.ts.map +1 -1
- package/lib/browser/workspace-trust-service.js +322 -12
- package/lib/browser/workspace-trust-service.js.map +1 -1
- package/lib/browser/workspace-trust-service.spec.d.ts +2 -0
- package/lib/browser/workspace-trust-service.spec.d.ts.map +1 -0
- package/lib/browser/workspace-trust-service.spec.js +357 -0
- package/lib/browser/workspace-trust-service.spec.js.map +1 -0
- package/lib/browser/workspace-uri-contribution.js +1 -2
- package/lib/browser/workspace-uri-contribution.js.map +1 -1
- package/lib/browser/workspace-user-working-directory-provider.js +6 -5
- package/lib/browser/workspace-user-working-directory-provider.js.map +1 -1
- package/lib/common/untitled-workspace-service.d.ts +8 -1
- package/lib/common/untitled-workspace-service.d.ts.map +1 -1
- package/lib/common/untitled-workspace-service.js +22 -3
- package/lib/common/untitled-workspace-service.js.map +1 -1
- package/lib/common/workspace-preferences.js +3 -3
- package/lib/common/workspace-preferences.js.map +1 -1
- package/lib/common/workspace-trust-preferences.d.ts +2 -0
- package/lib/common/workspace-trust-preferences.d.ts.map +1 -1
- package/lib/common/workspace-trust-preferences.js +13 -3
- package/lib/common/workspace-trust-preferences.js.map +1 -1
- package/lib/node/default-workspace-server.d.ts +0 -1
- package/lib/node/default-workspace-server.d.ts.map +1 -1
- package/lib/node/default-workspace-server.js +2 -3
- package/lib/node/default-workspace-server.js.map +1 -1
- package/package.json +5 -5
- package/src/browser/style/index.css +75 -0
- package/src/browser/workspace-commands.ts +5 -0
- package/src/browser/workspace-frontend-contribution.ts +45 -2
- package/src/browser/workspace-frontend-module.ts +4 -1
- package/src/browser/workspace-trust-dialog.tsx +90 -0
- package/src/browser/workspace-trust-service.spec.ts +462 -0
- package/src/browser/workspace-trust-service.ts +381 -15
- package/src/common/untitled-workspace-service.ts +21 -2
- package/src/common/workspace-trust-preferences.ts +11 -0
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { expect } from 'chai';
|
|
18
|
+
import * as sinon from 'sinon';
|
|
19
|
+
import { PreferenceChange, PreferenceScope } from '@theia/core/lib/common/preferences';
|
|
20
|
+
import { WorkspaceTrustService } from './workspace-trust-service';
|
|
21
|
+
import {
|
|
22
|
+
WORKSPACE_TRUST_EMPTY_WINDOW,
|
|
23
|
+
WORKSPACE_TRUST_ENABLED,
|
|
24
|
+
WORKSPACE_TRUST_STARTUP_PROMPT,
|
|
25
|
+
WORKSPACE_TRUST_TRUSTED_FOLDERS,
|
|
26
|
+
WorkspaceTrustPrompt
|
|
27
|
+
} from '../common/workspace-trust-preferences';
|
|
28
|
+
import URI from '@theia/core/lib/common/uri';
|
|
29
|
+
|
|
30
|
+
class TestableWorkspaceTrustService extends WorkspaceTrustService {
|
|
31
|
+
public async testHandlePreferenceChange(change: PreferenceChange): Promise<void> {
|
|
32
|
+
return this.handlePreferenceChange(change);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public async testHandleWorkspaceChanged(): Promise<void> {
|
|
36
|
+
return this.handleWorkspaceChanged();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public setCurrentTrust(trust: boolean | undefined): void {
|
|
40
|
+
this.currentTrust = trust;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public getCurrentTrust(): boolean | undefined {
|
|
44
|
+
return this.currentTrust;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public override isWorkspaceTrustResolved(): boolean {
|
|
48
|
+
return super.isWorkspaceTrustResolved();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public async testCalculateWorkspaceTrust(): Promise<boolean | undefined> {
|
|
52
|
+
return this.calculateWorkspaceTrust();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe('WorkspaceTrustService', () => {
|
|
57
|
+
let service: TestableWorkspaceTrustService;
|
|
58
|
+
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
service = new TestableWorkspaceTrustService();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
sinon.restore();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('calculateWorkspaceTrust', () => {
|
|
68
|
+
let workspaceTrustPrefStub: { [key: string]: unknown };
|
|
69
|
+
let workspaceServiceStub: {
|
|
70
|
+
tryGetRoots: () => Array<{ resource: URI }>;
|
|
71
|
+
workspace: { resource: URI } | undefined;
|
|
72
|
+
saved: boolean;
|
|
73
|
+
};
|
|
74
|
+
let untitledWorkspaceServiceStub: {
|
|
75
|
+
isUntitledWorkspace: (uri?: URI, configDirUri?: URI) => boolean;
|
|
76
|
+
};
|
|
77
|
+
let envVariablesServerStub: {
|
|
78
|
+
getConfigDirUri: () => Promise<string>;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
beforeEach(() => {
|
|
82
|
+
workspaceTrustPrefStub = {
|
|
83
|
+
[WORKSPACE_TRUST_ENABLED]: true,
|
|
84
|
+
[WORKSPACE_TRUST_EMPTY_WINDOW]: false,
|
|
85
|
+
[WORKSPACE_TRUST_STARTUP_PROMPT]: WorkspaceTrustPrompt.NEVER,
|
|
86
|
+
[WORKSPACE_TRUST_TRUSTED_FOLDERS]: []
|
|
87
|
+
};
|
|
88
|
+
workspaceServiceStub = {
|
|
89
|
+
tryGetRoots: () => [],
|
|
90
|
+
workspace: undefined,
|
|
91
|
+
saved: false
|
|
92
|
+
};
|
|
93
|
+
untitledWorkspaceServiceStub = {
|
|
94
|
+
isUntitledWorkspace: () => false
|
|
95
|
+
};
|
|
96
|
+
envVariablesServerStub = {
|
|
97
|
+
getConfigDirUri: async () => 'file:///home/user/.theia'
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
(service as unknown as { workspaceTrustPref: typeof workspaceTrustPrefStub }).workspaceTrustPref = workspaceTrustPrefStub;
|
|
101
|
+
(service as unknown as { workspaceService: typeof workspaceServiceStub }).workspaceService = workspaceServiceStub;
|
|
102
|
+
(service as unknown as { untitledWorkspaceService: typeof untitledWorkspaceServiceStub }).untitledWorkspaceService = untitledWorkspaceServiceStub;
|
|
103
|
+
(service as unknown as { envVariablesServer: typeof envVariablesServerStub }).envVariablesServer = envVariablesServerStub;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('should return true when trust is disabled', async () => {
|
|
107
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_ENABLED] = false;
|
|
108
|
+
|
|
109
|
+
expect(await service.testCalculateWorkspaceTrust()).to.be.true;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('empty workspace', () => {
|
|
113
|
+
it('should return emptyWindow setting when no workspace is open', async () => {
|
|
114
|
+
workspaceServiceStub.workspace = undefined;
|
|
115
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_EMPTY_WINDOW] = true;
|
|
116
|
+
|
|
117
|
+
expect(await service.testCalculateWorkspaceTrust()).to.be.true;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should return false when emptyWindow is false and no workspace', async () => {
|
|
121
|
+
workspaceServiceStub.workspace = undefined;
|
|
122
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_EMPTY_WINDOW] = false;
|
|
123
|
+
|
|
124
|
+
expect(await service.testCalculateWorkspaceTrust()).to.be.false;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should return emptyWindow setting for untitled workspace with no folders', async () => {
|
|
128
|
+
workspaceServiceStub.workspace = { resource: new URI('file:///home/user/.theia/workspaces/Untitled-123.theia-workspace') };
|
|
129
|
+
workspaceServiceStub.tryGetRoots = () => [];
|
|
130
|
+
untitledWorkspaceServiceStub.isUntitledWorkspace = () => true;
|
|
131
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_EMPTY_WINDOW] = true;
|
|
132
|
+
|
|
133
|
+
expect(await service.testCalculateWorkspaceTrust()).to.be.true;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should not treat saved workspace with no folders as empty', async () => {
|
|
137
|
+
workspaceServiceStub.workspace = { resource: new URI('file:///home/user/my.theia-workspace') };
|
|
138
|
+
workspaceServiceStub.tryGetRoots = () => [];
|
|
139
|
+
workspaceServiceStub.saved = true;
|
|
140
|
+
untitledWorkspaceServiceStub.isUntitledWorkspace = () => false;
|
|
141
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_EMPTY_WINDOW] = true;
|
|
142
|
+
|
|
143
|
+
// Should return false because saved workspace with 0 folders is not "empty"
|
|
144
|
+
// and the workspace file is not trusted
|
|
145
|
+
expect(await service.testCalculateWorkspaceTrust()).to.be.false;
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe('single-root workspace', () => {
|
|
150
|
+
it('should return true when folder is in trusted folders', async () => {
|
|
151
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_TRUSTED_FOLDERS] = ['file:///home/user/project'];
|
|
152
|
+
workspaceServiceStub.workspace = { resource: new URI('file:///home/user/project') };
|
|
153
|
+
workspaceServiceStub.tryGetRoots = () => [
|
|
154
|
+
{ resource: new URI('file:///home/user/project') }
|
|
155
|
+
];
|
|
156
|
+
|
|
157
|
+
expect(await service.testCalculateWorkspaceTrust()).to.be.true;
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('should return true when parent folder is trusted', async () => {
|
|
161
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_TRUSTED_FOLDERS] = ['file:///home/user'];
|
|
162
|
+
workspaceServiceStub.workspace = { resource: new URI('file:///home/user/project') };
|
|
163
|
+
workspaceServiceStub.tryGetRoots = () => [
|
|
164
|
+
{ resource: new URI('file:///home/user/project') }
|
|
165
|
+
];
|
|
166
|
+
|
|
167
|
+
expect(await service.testCalculateWorkspaceTrust()).to.be.true;
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('should return false when folder is not trusted', async () => {
|
|
171
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_TRUSTED_FOLDERS] = ['file:///home/other'];
|
|
172
|
+
workspaceServiceStub.workspace = { resource: new URI('file:///home/user/project') };
|
|
173
|
+
workspaceServiceStub.tryGetRoots = () => [
|
|
174
|
+
{ resource: new URI('file:///home/user/project') }
|
|
175
|
+
];
|
|
176
|
+
|
|
177
|
+
expect(await service.testCalculateWorkspaceTrust()).to.be.false;
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe('multi-root workspace', () => {
|
|
182
|
+
it('should return true when all folders are trusted', async () => {
|
|
183
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_TRUSTED_FOLDERS] = [
|
|
184
|
+
'file:///home/user/project1',
|
|
185
|
+
'file:///home/user/project2'
|
|
186
|
+
];
|
|
187
|
+
workspaceServiceStub.workspace = { resource: new URI('file:///home/user/my.theia-workspace') };
|
|
188
|
+
workspaceServiceStub.tryGetRoots = () => [
|
|
189
|
+
{ resource: new URI('file:///home/user/project1') },
|
|
190
|
+
{ resource: new URI('file:///home/user/project2') }
|
|
191
|
+
];
|
|
192
|
+
|
|
193
|
+
expect(await service.testCalculateWorkspaceTrust()).to.be.true;
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('should return false when one folder is not trusted', async () => {
|
|
197
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_TRUSTED_FOLDERS] = ['file:///home/user/project1'];
|
|
198
|
+
workspaceServiceStub.workspace = { resource: new URI('file:///home/user/my.theia-workspace') };
|
|
199
|
+
workspaceServiceStub.tryGetRoots = () => [
|
|
200
|
+
{ resource: new URI('file:///home/user/project1') },
|
|
201
|
+
{ resource: new URI('file:///home/user/project2') }
|
|
202
|
+
];
|
|
203
|
+
|
|
204
|
+
expect(await service.testCalculateWorkspaceTrust()).to.be.false;
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('should return true when parent folder covers all roots', async () => {
|
|
208
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_TRUSTED_FOLDERS] = ['file:///home/user'];
|
|
209
|
+
workspaceServiceStub.workspace = { resource: new URI('file:///home/user/my.theia-workspace') };
|
|
210
|
+
workspaceServiceStub.tryGetRoots = () => [
|
|
211
|
+
{ resource: new URI('file:///home/user/project1') },
|
|
212
|
+
{ resource: new URI('file:///home/user/project2') }
|
|
213
|
+
];
|
|
214
|
+
|
|
215
|
+
expect(await service.testCalculateWorkspaceTrust()).to.be.true;
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe('saved workspace file trust', () => {
|
|
220
|
+
it('should require workspace file to be trusted for saved workspaces', async () => {
|
|
221
|
+
// Folder is trusted but workspace file location is not
|
|
222
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_TRUSTED_FOLDERS] = ['file:///home/user/project'];
|
|
223
|
+
workspaceServiceStub.workspace = { resource: new URI('file:///other/location/my.theia-workspace') };
|
|
224
|
+
workspaceServiceStub.saved = true;
|
|
225
|
+
workspaceServiceStub.tryGetRoots = () => [
|
|
226
|
+
{ resource: new URI('file:///home/user/project') }
|
|
227
|
+
];
|
|
228
|
+
|
|
229
|
+
expect(await service.testCalculateWorkspaceTrust()).to.be.false;
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('should return true when both folder and workspace file are trusted', async () => {
|
|
233
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_TRUSTED_FOLDERS] = ['file:///home/user'];
|
|
234
|
+
workspaceServiceStub.workspace = { resource: new URI('file:///home/user/my.theia-workspace') };
|
|
235
|
+
workspaceServiceStub.saved = true;
|
|
236
|
+
workspaceServiceStub.tryGetRoots = () => [
|
|
237
|
+
{ resource: new URI('file:///home/user/project') }
|
|
238
|
+
];
|
|
239
|
+
|
|
240
|
+
expect(await service.testCalculateWorkspaceTrust()).to.be.true;
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('should not require workspace file trust for unsaved workspaces', async () => {
|
|
244
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_TRUSTED_FOLDERS] = ['file:///home/user/project'];
|
|
245
|
+
workspaceServiceStub.workspace = { resource: new URI('file:///tmp/untitled.theia-workspace') };
|
|
246
|
+
workspaceServiceStub.saved = false;
|
|
247
|
+
workspaceServiceStub.tryGetRoots = () => [
|
|
248
|
+
{ resource: new URI('file:///home/user/project') }
|
|
249
|
+
];
|
|
250
|
+
|
|
251
|
+
expect(await service.testCalculateWorkspaceTrust()).to.be.true;
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
describe('handleWorkspaceChanged', () => {
|
|
257
|
+
let resolveWorkspaceTrustStub: sinon.SinonStub;
|
|
258
|
+
let getWorkspaceTrustStub: sinon.SinonStub;
|
|
259
|
+
let updateRestrictedModeIndicatorStub: sinon.SinonStub;
|
|
260
|
+
|
|
261
|
+
beforeEach(() => {
|
|
262
|
+
resolveWorkspaceTrustStub = sinon.stub(service as unknown as { resolveWorkspaceTrust: () => Promise<void> }, 'resolveWorkspaceTrust').resolves();
|
|
263
|
+
getWorkspaceTrustStub = sinon.stub(service, 'getWorkspaceTrust').resolves(true);
|
|
264
|
+
updateRestrictedModeIndicatorStub = sinon.stub(
|
|
265
|
+
service as unknown as { updateRestrictedModeIndicator: (trust: boolean) => void },
|
|
266
|
+
'updateRestrictedModeIndicator'
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('should reset trust state when workspace changes', async () => {
|
|
271
|
+
service.setCurrentTrust(true);
|
|
272
|
+
|
|
273
|
+
await service.testHandleWorkspaceChanged();
|
|
274
|
+
|
|
275
|
+
expect(service.getCurrentTrust()).to.be.undefined;
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('should re-evaluate trust when workspace changes', async () => {
|
|
279
|
+
service.setCurrentTrust(true);
|
|
280
|
+
|
|
281
|
+
await service.testHandleWorkspaceChanged();
|
|
282
|
+
|
|
283
|
+
expect(resolveWorkspaceTrustStub.calledOnce).to.be.true;
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('should update restricted mode indicator after workspace change if not trusted', async () => {
|
|
287
|
+
getWorkspaceTrustStub.resolves(false);
|
|
288
|
+
|
|
289
|
+
await service.testHandleWorkspaceChanged();
|
|
290
|
+
|
|
291
|
+
expect(updateRestrictedModeIndicatorStub.calledOnceWith(false)).to.be.true;
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('should reset workspaceTrust deferred to unresolved state', async () => {
|
|
295
|
+
// First resolve the trust
|
|
296
|
+
service.setCurrentTrust(true);
|
|
297
|
+
|
|
298
|
+
await service.testHandleWorkspaceChanged();
|
|
299
|
+
|
|
300
|
+
// After workspace change, it should be reset and resolved again via resolveWorkspaceTrust
|
|
301
|
+
expect(resolveWorkspaceTrustStub.calledOnce).to.be.true;
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
describe('handlePreferenceChange', () => {
|
|
306
|
+
let areAllWorkspaceUrisTrustedStub: sinon.SinonStub;
|
|
307
|
+
let setWorkspaceTrustStub: sinon.SinonStub;
|
|
308
|
+
let isEmptyWorkspaceStub: sinon.SinonStub;
|
|
309
|
+
let workspaceTrustPrefStub: { [key: string]: unknown };
|
|
310
|
+
|
|
311
|
+
beforeEach(() => {
|
|
312
|
+
areAllWorkspaceUrisTrustedStub = sinon.stub(service as unknown as { areAllWorkspaceUrisTrusted: () => Promise<boolean> }, 'areAllWorkspaceUrisTrusted');
|
|
313
|
+
setWorkspaceTrustStub = sinon.stub(service, 'setWorkspaceTrust');
|
|
314
|
+
isEmptyWorkspaceStub = sinon.stub(service as unknown as { isEmptyWorkspace: () => Promise<boolean> }, 'isEmptyWorkspace');
|
|
315
|
+
// Mock workspaceTrustPref - default emptyWindow to false so trusted folders logic runs
|
|
316
|
+
workspaceTrustPrefStub = { [WORKSPACE_TRUST_EMPTY_WINDOW]: false };
|
|
317
|
+
(service as unknown as { workspaceTrustPref: { [key: string]: unknown } }).workspaceTrustPref = workspaceTrustPrefStub;
|
|
318
|
+
// Default to non-empty workspace
|
|
319
|
+
isEmptyWorkspaceStub.resolves(false);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('should update trust to true when all workspace URIs become trusted', async () => {
|
|
323
|
+
service.setCurrentTrust(false);
|
|
324
|
+
areAllWorkspaceUrisTrustedStub.resolves(true);
|
|
325
|
+
|
|
326
|
+
const change: PreferenceChange = {
|
|
327
|
+
preferenceName: WORKSPACE_TRUST_TRUSTED_FOLDERS,
|
|
328
|
+
scope: PreferenceScope.User,
|
|
329
|
+
domain: [],
|
|
330
|
+
affects: () => true
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
await service.testHandlePreferenceChange(change);
|
|
334
|
+
|
|
335
|
+
expect(setWorkspaceTrustStub.calledOnceWith(true)).to.be.true;
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it('should update trust to false when not all workspace URIs are trusted', async () => {
|
|
339
|
+
service.setCurrentTrust(true);
|
|
340
|
+
areAllWorkspaceUrisTrustedStub.resolves(false);
|
|
341
|
+
|
|
342
|
+
const change: PreferenceChange = {
|
|
343
|
+
preferenceName: WORKSPACE_TRUST_TRUSTED_FOLDERS,
|
|
344
|
+
scope: PreferenceScope.User,
|
|
345
|
+
domain: [],
|
|
346
|
+
affects: () => true
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
await service.testHandlePreferenceChange(change);
|
|
350
|
+
|
|
351
|
+
expect(setWorkspaceTrustStub.calledOnceWith(false)).to.be.true;
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it('should not update trust when trustedFolders change does not affect trust status', async () => {
|
|
355
|
+
service.setCurrentTrust(false);
|
|
356
|
+
areAllWorkspaceUrisTrustedStub.resolves(false);
|
|
357
|
+
|
|
358
|
+
const change: PreferenceChange = {
|
|
359
|
+
preferenceName: WORKSPACE_TRUST_TRUSTED_FOLDERS,
|
|
360
|
+
scope: PreferenceScope.User,
|
|
361
|
+
domain: [],
|
|
362
|
+
affects: () => true
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
await service.testHandlePreferenceChange(change);
|
|
366
|
+
|
|
367
|
+
expect(setWorkspaceTrustStub.called).to.be.false;
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
describe('emptyWindow setting changes', () => {
|
|
371
|
+
beforeEach(() => {
|
|
372
|
+
// Reset to empty workspace for empty window tests
|
|
373
|
+
isEmptyWorkspaceStub.resolves(true);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it('should update trust to true when emptyWindow setting changes to true for empty window', async () => {
|
|
377
|
+
service.setCurrentTrust(false);
|
|
378
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_EMPTY_WINDOW] = true;
|
|
379
|
+
|
|
380
|
+
const change: PreferenceChange = {
|
|
381
|
+
preferenceName: WORKSPACE_TRUST_EMPTY_WINDOW,
|
|
382
|
+
scope: PreferenceScope.User,
|
|
383
|
+
domain: [],
|
|
384
|
+
affects: () => true
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
await service.testHandlePreferenceChange(change);
|
|
388
|
+
|
|
389
|
+
expect(setWorkspaceTrustStub.calledOnceWith(true)).to.be.true;
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it('should update trust to false when emptyWindow setting changes to false for empty window', async () => {
|
|
393
|
+
service.setCurrentTrust(true);
|
|
394
|
+
|
|
395
|
+
const change: PreferenceChange = {
|
|
396
|
+
preferenceName: WORKSPACE_TRUST_EMPTY_WINDOW,
|
|
397
|
+
scope: PreferenceScope.User,
|
|
398
|
+
domain: [],
|
|
399
|
+
affects: () => true
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
await service.testHandlePreferenceChange(change);
|
|
403
|
+
|
|
404
|
+
expect(setWorkspaceTrustStub.calledOnceWith(false)).to.be.true;
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it('should not update trust when emptyWindow setting changes but workspace has roots', async () => {
|
|
408
|
+
service.setCurrentTrust(false);
|
|
409
|
+
isEmptyWorkspaceStub.resolves(false);
|
|
410
|
+
|
|
411
|
+
const change: PreferenceChange = {
|
|
412
|
+
preferenceName: WORKSPACE_TRUST_EMPTY_WINDOW,
|
|
413
|
+
scope: PreferenceScope.User,
|
|
414
|
+
domain: [],
|
|
415
|
+
affects: () => true
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
await service.testHandlePreferenceChange(change);
|
|
419
|
+
|
|
420
|
+
expect(setWorkspaceTrustStub.called).to.be.false;
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it('should not update trust when emptyWindow setting changes but trust already matches', async () => {
|
|
424
|
+
service.setCurrentTrust(true);
|
|
425
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_EMPTY_WINDOW] = true;
|
|
426
|
+
|
|
427
|
+
const change: PreferenceChange = {
|
|
428
|
+
preferenceName: WORKSPACE_TRUST_EMPTY_WINDOW,
|
|
429
|
+
scope: PreferenceScope.User,
|
|
430
|
+
domain: [],
|
|
431
|
+
affects: () => true
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
await service.testHandlePreferenceChange(change);
|
|
435
|
+
|
|
436
|
+
expect(setWorkspaceTrustStub.called).to.be.false;
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
describe('trustedFolders change for empty window with emptyWindow enabled', () => {
|
|
441
|
+
beforeEach(() => {
|
|
442
|
+
isEmptyWorkspaceStub.resolves(true);
|
|
443
|
+
workspaceTrustPrefStub[WORKSPACE_TRUST_EMPTY_WINDOW] = true;
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it('should not change trust when trustedFolders change for empty window with emptyWindow enabled', async () => {
|
|
447
|
+
service.setCurrentTrust(true);
|
|
448
|
+
|
|
449
|
+
const change: PreferenceChange = {
|
|
450
|
+
preferenceName: WORKSPACE_TRUST_TRUSTED_FOLDERS,
|
|
451
|
+
scope: PreferenceScope.User,
|
|
452
|
+
domain: [],
|
|
453
|
+
affects: () => true
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
await service.testHandlePreferenceChange(change);
|
|
457
|
+
|
|
458
|
+
expect(setWorkspaceTrustStub.called).to.be.false;
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
});
|