@@ -58,6 +58,7 @@ public void testUninstallPluginPathNormalization() throws IOException {
5858 Mockito .when (context .getRealPath (Mockito .contains ("pluginsConfig.json" ))).thenReturn (tempConfig .getAbsolutePath ());
5959 File tempExtensions = TestUtils .copyToTemp (ConfigControllerTest .class , "/extensionsWithPlugin.json" );
6060 File tempDist = TestUtils .getDataDir ();
61+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (tempDist );
6162
6263 // Mock a legitimate folder inside the base directory
6364 Mockito .when (context .getRealPath (Mockito .contains ("extensions.json" ))).thenReturn (tempExtensions .getAbsolutePath ());
@@ -89,6 +90,7 @@ public void testUploadValidBundle() throws IOException {
8990 Mockito .when (context .getRealPath (Mockito .endsWith ("pluginsConfig.json" ))).thenReturn (tempConfig .getAbsolutePath ());
9091 File tempExtensions = TestUtils .copyToTemp (ConfigControllerTest .class , "/extensions.json" );
9192 File tempDist = TestUtils .getDataDir ();
93+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (tempDist );
9294 Mockito .when (context .getRealPath (Mockito .contains ("extensions.json" ))).thenReturn (tempExtensions .getAbsolutePath ());
9395 Mockito .when (context .getRealPath (Mockito .contains ("My" ))).thenAnswer (
9496 (Answer <String >) invocation -> {
@@ -112,6 +114,7 @@ public void testUploadValidBundleReplace() throws IOException {
112114 Mockito .when (context .getRealPath (Mockito .endsWith ("pluginsConfig.json" ))).thenReturn (tempConfig .getAbsolutePath ());
113115 File tempExtensions = TestUtils .copyToTemp (ConfigControllerTest .class , "/extensionsWithPlugin.json" );
114116 File tempDist = TestUtils .getDataDir ();
117+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (tempDist );
115118 Mockito .when (context .getRealPath (Mockito .contains ("extensions.json" ))).thenReturn (tempExtensions .getAbsolutePath ());
116119 Mockito .when (context .getRealPath (Mockito .contains ("My" ))).thenAnswer (
117120 (Answer <String >) invocation -> {
@@ -139,6 +142,7 @@ public void testUploadValidBundleUsingPatch() throws IOException {
139142 Mockito .when (context .getRealPath (Mockito .endsWith (".patch" ))).thenReturn (tempDir .getAbsolutePath () + "/pluginsConfig.json.patch" );
140143 File tempExtensions = TestUtils .copyToTemp (ConfigControllerTest .class , "/extensions.json" );
141144 File tempDist = TestUtils .getDataDir ();
145+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (tempDist );
142146 Mockito .when (context .getRealPath (Mockito .contains ("extensions.json" ))).thenReturn (tempExtensions .getAbsolutePath ());
143147 Mockito .when (context .getRealPath (Mockito .contains ("dist/extensions/" ))).thenAnswer (
144148 (Answer <String >) invocation -> {
@@ -162,6 +166,7 @@ public void testCustomBundlesPath() throws IOException {
162166 Mockito .when (context .getRealPath (Mockito .endsWith ("pluginsConfig.json" ))).thenReturn (tempConfig .getAbsolutePath ());
163167 File tempExtensions = TestUtils .copyToTemp (ConfigControllerTest .class , "/extensions.json" );
164168 File tempDist = TestUtils .getDataDir ();
169+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (tempDist );
165170 controller .setBundlesPath ("custom" );
166171 Mockito .when (context .getRealPath (Mockito .contains ("extensions.json" ))).thenReturn (tempExtensions .getAbsolutePath ());
167172 Mockito .when (context .getRealPath (Mockito .contains ("custom/" ))).thenAnswer (
@@ -184,6 +189,7 @@ public void testUploadInvalidBundle() throws IOException {
184189 Mockito .when (context .getRealPath (Mockito .contains ("pluginsConfig.json" ))).thenReturn (tempConfig .getAbsolutePath ());
185190 File tempExtensions = TestUtils .copyToTemp (ConfigControllerTest .class , "/extensions.json" );
186191 File tempDist = TestUtils .getDataDir ();
192+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (tempDist );
187193 Mockito .when (context .getRealPath (Mockito .contains ("extensions.json" ))).thenReturn (tempExtensions .getAbsolutePath ());
188194 Mockito .when (context .getRealPath (Mockito .contains ("/extensions/" ))).thenAnswer (
189195 (Answer <String >) invocation -> {
@@ -206,6 +212,7 @@ public void testUploadValidBundleWithDataDir() throws IOException {
206212 controller .setDataDir (dataDir .getAbsolutePath ());
207213 ServletContext context = Mockito .mock (ServletContext .class );
208214 controller .setContext (context );
215+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (dataDir );
209216 File tempConfig = TestUtils .copyTo (UploadPluginControllerTest .class .getResourceAsStream ("/pluginsConfig.json" ), dataDir , "/configs/pluginsConfig.json" );
210217 File tempExtensions = TestUtils .copyTo (UploadPluginControllerTest .class .getResourceAsStream ("/extensions.json" ), dataDir , "/extensions/extensions.json" );
211218 InputStream zipStream = UploadPluginControllerTest .class .getResourceAsStream ("/plugin.zip" );
@@ -222,6 +229,7 @@ public void testUploadValidBundleWithMultipleDataDir() throws IOException {
222229 controller .setDataDir (dataDir1 .getAbsolutePath () + "," + dataDir2 .getAbsolutePath ());
223230 ServletContext context = Mockito .mock (ServletContext .class );
224231 controller .setContext (context );
232+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (dataDir1 );
225233 // we load from dataDir2 (less priority)
226234 File tempConfig = TestUtils .copyTo (
227235 UploadPluginControllerTest .class .getResourceAsStream ("/pluginsConfig.json" ),
@@ -245,6 +253,7 @@ public void testUninstallPlugin() throws IOException {
245253 Mockito .when (context .getRealPath (Mockito .contains ("pluginsConfig.json" ))).thenReturn (tempConfig .getAbsolutePath ());
246254 File tempExtensions = TestUtils .copyToTemp (ConfigControllerTest .class , "/extensionsWithPlugin.json" );
247255 File tempDist = TestUtils .getDataDir ();
256+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (tempDist );
248257 Mockito .when (context .getRealPath (Mockito .contains ("extensions.json" ))).thenReturn (tempExtensions .getAbsolutePath ());
249258 Mockito .when (context .getRealPath (Mockito .contains ("My" ))).thenAnswer (
250259 (Answer <String >) invocation -> {
@@ -305,6 +314,7 @@ public void testUploadBlocksZipSlip_DotDotInAssets() throws IOException {
305314 Mockito .when (context .getRealPath (Mockito .contains ("extensions.json" ))).thenReturn (tempExtensions .getAbsolutePath ());
306315
307316 File tempDist = TestUtils .getDataDir ();
317+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (tempDist );
308318 Mockito .when (context .getRealPath (Mockito .contains ("dist/extensions/" ))).thenAnswer (
309319 (Answer <String >) invocation -> {
310320 String path = (String ) invocation .getArguments ()[0 ];
@@ -329,6 +339,7 @@ public void testUploadBlocksZipSlip_AbsoluteUnixEntry() throws IOException {
329339 Mockito .when (context .getRealPath (Mockito .contains ("extensions.json" ))).thenReturn (tempExtensions .getAbsolutePath ());
330340
331341 File tempDist = TestUtils .getDataDir ();
342+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (tempDist );
332343 Mockito .when (context .getRealPath (Mockito .contains ("dist/extensions/" ))).thenReturn (
333344 tempDist .getAbsolutePath () + File .separator + "ignored"
334345 );
@@ -349,6 +360,7 @@ public void testUploadBlocksZipSlip_WindowsDriveEntry() throws IOException {
349360 Mockito .when (context .getRealPath (Mockito .endsWith ("pluginsConfig.json" ))).thenReturn (tempConfig .getAbsolutePath ());
350361 File tempExtensions = TestUtils .copyToTemp (ConfigControllerTest .class , "/extensions.json" );
351362 Mockito .when (context .getRealPath (Mockito .contains ("extensions.json" ))).thenReturn (tempExtensions .getAbsolutePath ());
363+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (TestUtils .getDataDir ());
352364
353365 Map <String , byte []> extras = new HashMap <>();
354366 extras .put ("C:\\ evil.js" , "drv" .getBytes (StandardCharsets .UTF_8 ));
@@ -368,6 +380,7 @@ public void testUploadBlocksZipSlip_BackslashTraversalInAssets() throws IOExcept
368380 Mockito .when (context .getRealPath (Mockito .contains ("extensions.json" ))).thenReturn (tempExtensions .getAbsolutePath ());
369381
370382 File tempDist = TestUtils .getDataDir ();
383+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (tempDist );
371384 Mockito .when (context .getRealPath (Mockito .contains ("dist/extensions/" ))).thenAnswer (
372385 (Answer <String >) invocation -> {
373386 String path = (String ) invocation .getArguments ()[0 ];
@@ -390,6 +403,7 @@ public void testUploadBlocksZipSlip_TraversalInBundleName() throws IOException {
390403 Mockito .when (context .getRealPath (Mockito .endsWith ("pluginsConfig.json" ))).thenReturn (tempConfig .getAbsolutePath ());
391404 File tempExtensions = TestUtils .copyToTemp (ConfigControllerTest .class , "/extensions.json" );
392405 Mockito .when (context .getRealPath (Mockito .contains ("extensions.json" ))).thenReturn (tempExtensions .getAbsolutePath ());
406+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (TestUtils .getDataDir ());
393407
394408 Map <String , byte []> extras = new HashMap <>();
395409 // no extra assets needed; bundle name itself is malicious
@@ -408,6 +422,7 @@ public void testUploadAllowsNestedAssets() throws IOException {
408422 Mockito .when (context .getRealPath (Mockito .contains ("extensions.json" ))).thenReturn (tempExtensions .getAbsolutePath ());
409423
410424 final File tempDist = TestUtils .getDataDir ();
425+ Mockito .when (context .getAttribute (ServletContext .TEMPDIR )).thenReturn (tempDist );
411426
412427 // Cover both likely extension roots
413428 Mockito .when (context .getRealPath (Mockito .contains ("dist/extensions/" ))).thenAnswer (
0 commit comments