-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
4 changed files
with
127 additions
and
2 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
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
66 changes: 66 additions & 0 deletions
66
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,66 @@ | ||
/* | ||
* Copyright (c) 2024 voczi <[email protected]> | ||
* | ||
* 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 com.ichi2.anki.CrashReportService.processThrowable | ||
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 e = Throwable(message, mock(BackendDeckIsFilteredException::class.java)) | ||
val processed = processThrowable(e) | ||
|
||
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(processThrowable(Throwable("test", mock(BackendSyncServerMessageException::class.java))), "Returned exception is null") | ||
} | ||
|
||
@Test | ||
fun `Emails are filtered out`() { | ||
val msg = processThrowable(Throwable("Lorem ipsum 123 [email protected] Lorem ipsum."))!!.message!! | ||
assertThat("Exception message does not contain the email", !msg.contains("[email protected]")) | ||
} | ||
|
||
@Test | ||
fun `Username is filtered out`() { | ||
val preferences = targetContext.sharedPrefs() | ||
preferences.edit() { putString(SyncPreferences.USERNAME, "MyUser") } | ||
CrashReportService.mPreferences = preferences | ||
|
||
val msg = processThrowable(Throwable("Lorem ipsum 123 MyUser Lorem ipsum."))!!.message!! | ||
assertThat("Exception message not contain the username", !msg.contains("MyUser")) | ||
} | ||
} |