@@ -37,7 +37,9 @@ class TestExtensionsScanner extends mock<ExtensionsScanner>() {
37
37
38
38
class TestExtensionSignatureVerificationService extends mock < IExtensionSignatureVerificationService > ( ) {
39
39
40
- constructor ( private readonly verificationResult : string | boolean ) {
40
+ constructor (
41
+ private readonly verificationResult : string | boolean ,
42
+ private readonly didExecute : boolean ) {
41
43
super ( ) ;
42
44
}
43
45
@@ -47,6 +49,7 @@ class TestExtensionSignatureVerificationService extends mock<IExtensionSignature
47
49
}
48
50
const error = Error ( this . verificationResult ) ;
49
51
( error as any ) . code = this . verificationResult ;
52
+ ( error as any ) . didExecute = this . didExecute ;
50
53
throw error ;
51
54
}
52
55
}
@@ -89,7 +92,7 @@ suite('InstallGalleryExtensionTask Tests', () => {
89
92
teardown ( ( ) => disposables . clear ( ) ) ;
90
93
91
94
test ( 'if verification is enabled by default, the task completes' , async ( ) => {
92
- const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : true } ) , anExtensionsDownloader ( true ) ) ;
95
+ const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : true } ) , anExtensionsDownloader ( { isSignatureVerificationEnabled : true , verificationResult : true , didExecute : true } ) ) ;
93
96
94
97
await testObject . run ( ) ;
95
98
@@ -98,7 +101,7 @@ suite('InstallGalleryExtensionTask Tests', () => {
98
101
} ) ;
99
102
100
103
test ( 'if verification is disabled in stable, the task completes' , async ( ) => {
101
- const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : true } ) , anExtensionsDownloader ( 'error' , undefined , 'stable' ) ) ;
104
+ const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : true } ) , anExtensionsDownloader ( { isSignatureVerificationEnabled : false , verificationResult : 'error' , didExecute : true , quality : 'stable' } ) ) ;
102
105
103
106
await testObject . run ( ) ;
104
107
@@ -107,7 +110,7 @@ suite('InstallGalleryExtensionTask Tests', () => {
107
110
} ) ;
108
111
109
112
test ( 'if verification is disabled by setting set to false, the task skips verification' , async ( ) => {
110
- const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : true } ) , anExtensionsDownloader ( 'error' , false ) ) ;
113
+ const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : true } ) , anExtensionsDownloader ( { isSignatureVerificationEnabled : false , verificationResult : 'error' , didExecute : false } ) ) ;
111
114
112
115
await testObject . run ( ) ;
113
116
@@ -116,7 +119,17 @@ suite('InstallGalleryExtensionTask Tests', () => {
116
119
} ) ;
117
120
118
121
test ( 'if verification is disabled because the module is not loaded, the task skips verification' , async ( ) => {
119
- const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : true } ) , anExtensionsDownloader ( false , true ) ) ;
122
+ const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : true } ) , anExtensionsDownloader ( { isSignatureVerificationEnabled : true , verificationResult : false , didExecute : false } ) ) ;
123
+
124
+ await testObject . run ( ) ;
125
+
126
+ assert . strictEqual ( testObject . verificationStatus , ExtensionVerificationStatus . Unverified ) ;
127
+ assert . strictEqual ( testObject . installed , true ) ;
128
+ } ) ;
129
+
130
+ test ( 'if verification fails to execute, the task completes' , async ( ) => {
131
+ const errorCode = 'ENOENT' ;
132
+ const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : true } ) , anExtensionsDownloader ( { isSignatureVerificationEnabled : true , verificationResult : errorCode , didExecute : false } ) ) ;
120
133
121
134
await testObject . run ( ) ;
122
135
@@ -127,7 +140,7 @@ suite('InstallGalleryExtensionTask Tests', () => {
127
140
test ( 'if verification fails, the task throws' , async ( ) => {
128
141
const errorCode = 'IntegrityCheckFailed' ;
129
142
130
- const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : true } ) , anExtensionsDownloader ( errorCode , true ) ) ;
143
+ const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : true } ) , anExtensionsDownloader ( { isSignatureVerificationEnabled : true , verificationResult : errorCode , didExecute : true } ) ) ;
131
144
132
145
try {
133
146
await testObject . run ( ) ;
@@ -141,11 +154,10 @@ suite('InstallGalleryExtensionTask Tests', () => {
141
154
}
142
155
143
156
assert . fail ( 'It should have thrown.' ) ;
144
-
145
157
} ) ;
146
158
147
159
test ( 'if verification succeeds, the task completes' , async ( ) => {
148
- const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : true } ) , anExtensionsDownloader ( true , true ) ) ;
160
+ const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : true } ) , anExtensionsDownloader ( { isSignatureVerificationEnabled : true , verificationResult : true , didExecute : true } ) ) ;
149
161
150
162
await testObject . run ( ) ;
151
163
@@ -154,7 +166,7 @@ suite('InstallGalleryExtensionTask Tests', () => {
154
166
} ) ;
155
167
156
168
test ( 'task completes for unsigned extension' , async ( ) => {
157
- const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : false } ) , anExtensionsDownloader ( true , true ) ) ;
169
+ const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : false } ) , anExtensionsDownloader ( { isSignatureVerificationEnabled : true , verificationResult : true , didExecute : false } ) ) ;
158
170
159
171
await testObject . run ( ) ;
160
172
@@ -163,22 +175,22 @@ suite('InstallGalleryExtensionTask Tests', () => {
163
175
} ) ;
164
176
165
177
test ( 'task completes for an unsigned extension even when signature verification throws error' , async ( ) => {
166
- const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : false } ) , anExtensionsDownloader ( 'error' , true ) ) ;
178
+ const testObject = new TestInstallGalleryExtensionTask ( aGalleryExtension ( 'a' , { isSigned : false } ) , anExtensionsDownloader ( { isSignatureVerificationEnabled : true , verificationResult : 'error' , didExecute : true } ) ) ;
167
179
168
180
await testObject . run ( ) ;
169
181
170
182
assert . strictEqual ( testObject . verificationStatus , ExtensionVerificationStatus . Unverified ) ;
171
183
assert . strictEqual ( testObject . installed , true ) ;
172
184
} ) ;
173
185
174
- function anExtensionsDownloader ( verificationResult : string | boolean , isSignatureVerificationEnabled ? : boolean , quality ?: string ) : ExtensionsDownloader {
186
+ function anExtensionsDownloader ( options : { isSignatureVerificationEnabled : boolean ; verificationResult : boolean | string ; didExecute : boolean ; quality ?: string } ) : ExtensionsDownloader {
175
187
const logService = new NullLogService ( ) ;
176
188
const fileService = disposables . add ( new FileService ( logService ) ) ;
177
189
const fileSystemProvider = disposables . add ( new InMemoryFileSystemProvider ( ) ) ;
178
190
fileService . registerProvider ( ROOT . scheme , fileSystemProvider ) ;
179
191
180
192
const instantiationService = new TestInstantiationService ( ) ;
181
- instantiationService . stub ( IProductService , { quality : quality ?? 'insiders' } ) ;
193
+ instantiationService . stub ( IProductService , { quality : options . quality ?? 'insiders' } ) ;
182
194
instantiationService . stub ( IFileService , fileService ) ;
183
195
instantiationService . stub ( ILogService , logService ) ;
184
196
instantiationService . stub ( INativeEnvironmentService , < Partial < INativeEnvironmentService > > { extensionsDownloadLocation : joinPath ( ROOT , 'CachedExtensionVSIXs' ) } ) ;
@@ -190,8 +202,8 @@ suite('InstallGalleryExtensionTask Tests', () => {
190
202
await fileService . writeFile ( location , VSBuffer . fromString ( 'extension signature' ) ) ;
191
203
} ,
192
204
} ) ;
193
- instantiationService . stub ( IConfigurationService , new TestConfigurationService ( isBoolean ( isSignatureVerificationEnabled ) ? { extensions : { verifySignature : isSignatureVerificationEnabled } } : undefined ) ) ;
194
- instantiationService . stub ( IExtensionSignatureVerificationService , new TestExtensionSignatureVerificationService ( verificationResult ) ) ;
205
+ instantiationService . stub ( IConfigurationService , new TestConfigurationService ( isBoolean ( options . isSignatureVerificationEnabled ) ? { extensions : { verifySignature : options . isSignatureVerificationEnabled } } : undefined ) ) ;
206
+ instantiationService . stub ( IExtensionSignatureVerificationService , new TestExtensionSignatureVerificationService ( options . verificationResult , ! ! options . didExecute ) ) ;
195
207
return instantiationService . createInstance ( ExtensionsDownloader ) ;
196
208
}
197
209
0 commit comments