-
Notifications
You must be signed in to change notification settings - Fork 922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add blocking algorithm (isMalicious) #5376
base: feature/cris/malicious-site-protection/load-initial-dataset
Are you sure you want to change the base?
Add blocking algorithm (isMalicious) #5376
Conversation
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
41dbcee
to
45d1aaa
Compare
11f793b
to
3f61183
Compare
45d1aaa
to
ca1717c
Compare
79521f7
to
0974e8e
Compare
ca1717c
to
212e3b7
Compare
872e9ff
to
9097bc2
Compare
212e3b7
to
7c5e5c2
Compare
9097bc2
to
bf19279
Compare
7c5e5c2
to
54f233d
Compare
bf19279
to
8b35a0e
Compare
54f233d
to
0f7697a
Compare
e771493
to
46d5fc0
Compare
0f7697a
to
7c8c545
Compare
a1f08e1
to
3f18b3e
Compare
fun isMalicious_invokesOnSiteBlockedAsync_whenUrlIsMaliciousAndNeedsToGoToNetwork() = runTest { | ||
val url = Uri.parse("https://malicious.com") | ||
val hostname = url.host!! | ||
val hash = messageDigest.digest(hostname.toByteArray()).joinToString("") { "%02x".format(it) } | ||
val hashPrefix = hash.substring(0, 8) | ||
val filter = Filter(hash, ".*whatever.*") | ||
var onSiteBlockedAsyncCalled = false | ||
|
||
whenever(maliciousSiteRepository.containsHashPrefix(hashPrefix)).thenReturn(true) | ||
whenever(maliciousSiteRepository.getFilter(hash)).thenReturn(filter) | ||
whenever(maliciousSiteRepository.matches(hashPrefix)) | ||
.thenReturn(listOf(Match(hostname, url.toString(), ".*malicious.*", hash))) | ||
|
||
realMaliciousSiteProtection.isMalicious(url) { | ||
onSiteBlockedAsyncCalled = true | ||
} | ||
|
||
assertTrue(onSiteBlockedAsyncCalled) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test assertion needs to wait for the coroutine to complete. Add advanceUntilIdle()
after calling isMalicious()
to ensure the async callback has a chance to execute before checking onSiteBlockedAsyncCalled
. Without this, the test may fail intermittently since it's racing against the coroutine.
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
d585fa1
to
e310dad
Compare
3fec1c3
to
0aef382
Compare
1ea8bd3
to
768449f
Compare
0aef382
to
0d79e69
Compare
768449f
to
d6c864d
Compare
cbc7bf5
to
0c8a08a
Compare
ef6e36e
to
75f7e5d
Compare
Task/Issue URL: https://app.asana.com/0/72649045549333/1207151848931036/f
Description
Add algorithm to determine whether a URL is malicious or not. Details are described here (Approach A, "Implement MaliciousSiteDetection client library that" section). API was discussed here
Steps to test this PR
Feature 1
UI changes
n/a, toast is temporary, an error page will be added in the next PR