@@ -37,7 +37,9 @@ class TestExtensionsScanner extends mock<ExtensionsScanner>() {
3737
3838class TestExtensionSignatureVerificationService extends mock < IExtensionSignatureVerificationService > ( ) {
3939
40- constructor ( private readonly verificationResult : string | boolean ) {
40+ constructor (
41+ private readonly verificationResult : string | boolean ,
42+ private readonly didExecute : boolean ) {
4143 super ( ) ;
4244 }
4345
@@ -47,6 +49,7 @@ class TestExtensionSignatureVerificationService extends mock<IExtensionSignature
4749 }
4850 const error = Error ( this . verificationResult ) ;
4951 ( error as any ) . code = this . verificationResult ;
52+ ( error as any ) . didExecute = this . didExecute ;
5053 throw error ;
5154 }
5255}
@@ -89,7 +92,7 @@ suite('InstallGalleryExtensionTask Tests', () => {
8992 teardown ( ( ) => disposables . clear ( ) ) ;
9093
9194 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 } ) ) ;
9396
9497 await testObject . run ( ) ;
9598
@@ -98,7 +101,7 @@ suite('InstallGalleryExtensionTask Tests', () => {
98101 } ) ;
99102
100103 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' } ) ) ;
102105
103106 await testObject . run ( ) ;
104107
@@ -107,7 +110,7 @@ suite('InstallGalleryExtensionTask Tests', () => {
107110 } ) ;
108111
109112 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 } ) ) ;
111114
112115 await testObject . run ( ) ;
113116
@@ -116,7 +119,17 @@ suite('InstallGalleryExtensionTask Tests', () => {
116119 } ) ;
117120
118121 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 } ) ) ;
120133
121134 await testObject . run ( ) ;
122135
@@ -127,7 +140,7 @@ suite('InstallGalleryExtensionTask Tests', () => {
127140 test ( 'if verification fails, the task throws' , async ( ) => {
128141 const errorCode = 'IntegrityCheckFailed' ;
129142
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 } ) ) ;
131144
132145 try {
133146 await testObject . run ( ) ;
@@ -141,11 +154,10 @@ suite('InstallGalleryExtensionTask Tests', () => {
141154 }
142155
143156 assert . fail ( 'It should have thrown.' ) ;
144-
145157 } ) ;
146158
147159 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 } ) ) ;
149161
150162 await testObject . run ( ) ;
151163
@@ -154,7 +166,7 @@ suite('InstallGalleryExtensionTask Tests', () => {
154166 } ) ;
155167
156168 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 } ) ) ;
158170
159171 await testObject . run ( ) ;
160172
@@ -163,22 +175,22 @@ suite('InstallGalleryExtensionTask Tests', () => {
163175 } ) ;
164176
165177 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 } ) ) ;
167179
168180 await testObject . run ( ) ;
169181
170182 assert . strictEqual ( testObject . verificationStatus , ExtensionVerificationStatus . Unverified ) ;
171183 assert . strictEqual ( testObject . installed , true ) ;
172184 } ) ;
173185
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 {
175187 const logService = new NullLogService ( ) ;
176188 const fileService = disposables . add ( new FileService ( logService ) ) ;
177189 const fileSystemProvider = disposables . add ( new InMemoryFileSystemProvider ( ) ) ;
178190 fileService . registerProvider ( ROOT . scheme , fileSystemProvider ) ;
179191
180192 const instantiationService = new TestInstantiationService ( ) ;
181- instantiationService . stub ( IProductService , { quality : quality ?? 'insiders' } ) ;
193+ instantiationService . stub ( IProductService , { quality : options . quality ?? 'insiders' } ) ;
182194 instantiationService . stub ( IFileService , fileService ) ;
183195 instantiationService . stub ( ILogService , logService ) ;
184196 instantiationService . stub ( INativeEnvironmentService , < Partial < INativeEnvironmentService > > { extensionsDownloadLocation : joinPath ( ROOT , 'CachedExtensionVSIXs' ) } ) ;
@@ -190,8 +202,8 @@ suite('InstallGalleryExtensionTask Tests', () => {
190202 await fileService . writeFile ( location , VSBuffer . fromString ( 'extension signature' ) ) ;
191203 } ,
192204 } ) ;
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 ) ) ;
195207 return instantiationService . createInstance ( ExtensionsDownloader ) ;
196208 }
197209
0 commit comments