@@ -3,6 +3,7 @@ package org.schabi.newpipe.settings
33import android.content.SharedPreferences
44import org.junit.Assert.assertEquals
55import org.junit.Assert.assertFalse
6+ import org.junit.Assert.assertThrows
67import org.junit.Assert.assertTrue
78import org.junit.Assume
89import org.junit.Before
@@ -192,4 +193,22 @@ class ImportExportManagerTest {
192193 verify(editor, atLeastOnce()).putString(anyString(), anyString())
193194 verify(editor, atLeastOnce()).putInt(anyString(), anyInt())
194195 }
196+
197+ @Test
198+ fun `Importing preferences with a serialization injected class should fail` () {
199+ val settings = File .createTempFile(" newpipe_" , " " )
200+ `when `(fileLocator.settings).thenReturn(settings)
201+
202+ val emptyZip = File (classloader.getResource(" settings/vulnerable_serialization.zip" )?.file!! )
203+ `when `(storedFileHelper.stream).thenReturn(FileStream (emptyZip))
204+ Assume .assumeTrue(ImportExportManager (fileLocator).extractSettings(storedFileHelper))
205+
206+ val preferences = Mockito .mock(SharedPreferences ::class .java, withSettings().stubOnly())
207+ val editor = Mockito .mock(SharedPreferences .Editor ::class .java)
208+ `when `(preferences.edit()).thenReturn(editor)
209+
210+ assertThrows(ClassNotFoundException ::class .java) {
211+ ImportExportManager (fileLocator).loadSharedPreferences(preferences)
212+ }
213+ }
195214}
0 commit comments