generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BWA-10] Sanitize launch intents before processing (#128)
- Loading branch information
1 parent
7ca1eab
commit f912e00
Showing
3 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
app/src/main/kotlin/com/bitwarden/authenticator/data/platform/util/IntentExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.bitwarden.authenticator.data.platform.util | ||
|
||
import android.content.Intent | ||
|
||
/** | ||
* Returns true if this intent contains unexpected or suspicious data. | ||
*/ | ||
val Intent.isSuspicious: Boolean | ||
get() { | ||
val containsSuspiciousExtras = extras?.isEmpty?.not() ?: false | ||
val containsSuspiciousData = data != null | ||
return containsSuspiciousData || containsSuspiciousExtras | ||
} |
64 changes: 64 additions & 0 deletions
64
app/src/test/java/com/bitwarden/authenticator/data/platform/util/IntentExtensionsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.bitwarden.authenticator.data.platform.util | ||
|
||
import android.content.Intent | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import org.junit.jupiter.api.Assertions.assertFalse | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
|
||
class IntentExtensionsTest { | ||
@Test | ||
fun `isSuspicious should return true when extras are not empty`() { | ||
val intent = mockk<Intent> { | ||
every { data } returns mockk() | ||
every { extras } returns mockk { | ||
every { isEmpty } returns false | ||
} | ||
} | ||
|
||
assertTrue(intent.isSuspicious) | ||
} | ||
|
||
@Test | ||
fun `isSuspicious should return true when extras are null`() { | ||
val intent = mockk<Intent> { | ||
every { data } returns mockk() | ||
every { extras } returns null | ||
} | ||
|
||
assertTrue(intent.isSuspicious) | ||
} | ||
|
||
@Test | ||
fun `isSuspicious should return true when data is not null`() { | ||
val intent = mockk<Intent> { | ||
every { data } returns mockk() | ||
every { extras } returns null | ||
} | ||
|
||
assertTrue(intent.isSuspicious) | ||
} | ||
|
||
@Test | ||
fun `isSuspicious should return false when data and extras are null`() { | ||
val intent = mockk<Intent> { | ||
every { data } returns null | ||
every { extras } returns null | ||
} | ||
|
||
assertFalse(intent.isSuspicious) | ||
} | ||
|
||
@Test | ||
fun `isSuspicious should return false when data is null and extras are empty`() { | ||
val intent = mockk<Intent> { | ||
every { data } returns null | ||
every { extras } returns mockk { | ||
every { isEmpty } returns true | ||
} | ||
} | ||
|
||
assertFalse(intent.isSuspicious) | ||
} | ||
} |