Skip to content

Commit 6afdbd6

Browse files
committed
Add test: vulnerable settings should fail importing
1 parent d8668ed commit 6afdbd6

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

app/src/test/java/org/schabi/newpipe/settings/ImportExportManagerTest.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.schabi.newpipe.settings
33
import android.content.SharedPreferences
44
import org.junit.Assert.assertEquals
55
import org.junit.Assert.assertFalse
6+
import org.junit.Assert.assertThrows
67
import org.junit.Assert.assertTrue
78
import org.junit.Assume
89
import 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
}
3.45 KB
Binary file not shown.

0 commit comments

Comments
 (0)