-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ | |
<w>quiro91</w> | ||
<w>tarekkma</w> | ||
<w>vianey</w> | ||
<w>voczi</w> | ||
<w>zanki</w> | ||
</words> | ||
</dictionary> | ||
|
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
65 changes: 65 additions & 0 deletions
65
AnkiDroid/src/test/java/com/ichi2/anki/CrashReportServiceTest.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,65 @@ | ||
/* | ||
* Copyright (c) 2024 voczi <dev@voczi.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free Software | ||
* Foundation; either version 3 of the License, or (at your option) any later | ||
* version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.ichi2.anki | ||
|
||
import androidx.core.content.edit | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import anki.backend.BackendError | ||
import com.ichi2.anki.CrashReportService.removePII | ||
import com.ichi2.anki.preferences.sharedPrefs | ||
import net.ankiweb.rsdroid.exceptions.BackendDeckIsFilteredException | ||
import net.ankiweb.rsdroid.exceptions.BackendSyncException.BackendSyncServerMessageException | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mockito.mock | ||
import kotlin.Throwable | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotNull | ||
import kotlin.test.assertNull | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class CrashReportServiceTest : RobolectricTest() { | ||
@Test | ||
fun `Normal exceptions are untouched`() { | ||
val message = "This is a test message which should not be filtered nor blocked" | ||
val processed = BackendDeckIsFilteredException(BackendError.newBuilder().setMessage(message).build()).removePII() | ||
|
||
assertNotNull(processed, "Returned exception should not be null") | ||
assertEquals(processed.message!!, message, "Returned exception's message should stay the same") | ||
} | ||
|
||
@Test | ||
fun `Backend sync server messages are blocked`() { | ||
assertNull(mock(BackendSyncServerMessageException::class.java).removePII(), "Returned exception is null") | ||
} | ||
|
||
@Test | ||
fun `Emails are filtered out`() { | ||
val msg = Throwable("Lorem ipsum 123 email@domain.tld Lorem ipsum.").removePII()!!.message!! | ||
assertThat("Exception message does not contain the email", !msg.contains("email@domain.tld")) | ||
} | ||
|
||
@Test | ||
fun `Username is filtered out`() { | ||
val preferences = targetContext.sharedPrefs() | ||
preferences.edit() { putString(SyncPreferences.USERNAME, "MyUser") } | ||
|
||
val msg = Throwable("Lorem ipsum 123 MyUser Lorem ipsum.").removePII()!!.message!! | ||
assertThat("Exception message not contain the username", !msg.contains("MyUser")) | ||
} | ||
} |