-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android] Select the highest priority threat from SafetyNetClient.loo… (
#26195) * [Android] Select the highest priority threat from SafetyNetClient.lookupUri response fixes brave/brave-browser#41581 --------- Co-authored-by: Francois Marier <francois@brave.com>
- Loading branch information
1 parent
8476a91
commit 7c79b15
Showing
4 changed files
with
108 additions
and
19 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
android/javatests/org/chromium/chrome/browser/BraveSafetyNetThreatsPrioritiesTest.java
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 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.chromium.chrome.browser; | ||
|
||
import androidx.test.filters.SmallTest; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.chromium.base.test.BaseJUnit4ClassRunner; | ||
import org.chromium.base.test.util.Batch; | ||
import org.chromium.components.safe_browsing.BraveSafeBrowsingUtils; | ||
import org.chromium.components.safe_browsing.BraveSafeBrowsingUtils.SafetyNetJavaThreatType; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
@Batch(Batch.PER_CLASS) | ||
@RunWith(BaseJUnit4ClassRunner.class) | ||
public class BraveSafetyNetThreatsPrioritiesTest { | ||
|
||
@Test | ||
@SmallTest | ||
public void testPriorities() throws Exception { | ||
// Fail safe option for empty input, consider it is safe | ||
Assert.assertEquals( | ||
BraveSafeBrowsingUtils.getHighestPriorityThreat(new ArrayList<>()), | ||
SafetyNetJavaThreatType.MAX_VALUE); | ||
|
||
// Single input must return the same value | ||
Assert.assertEquals( | ||
BraveSafeBrowsingUtils.getHighestPriorityThreat( | ||
Arrays.asList(new Integer[] {SafetyNetJavaThreatType.SOCIAL_ENGINEERING})), | ||
SafetyNetJavaThreatType.SOCIAL_ENGINEERING); | ||
|
||
// Several threats as input - return the most priority one | ||
Assert.assertEquals( | ||
BraveSafeBrowsingUtils.getHighestPriorityThreat( | ||
Arrays.asList( | ||
new Integer[] { | ||
SafetyNetJavaThreatType.UNWANTED_SOFTWARE, | ||
SafetyNetJavaThreatType.SUBRESOURCE_FILTER, | ||
SafetyNetJavaThreatType.SOCIAL_ENGINEERING, | ||
SafetyNetJavaThreatType.BILLING, | ||
SafetyNetJavaThreatType.POTENTIALLY_HARMFUL_APPLICATION, | ||
})), | ||
SafetyNetJavaThreatType.SOCIAL_ENGINEERING); | ||
|
||
Assert.assertEquals( | ||
BraveSafeBrowsingUtils.getHighestPriorityThreat( | ||
Arrays.asList( | ||
new Integer[] { | ||
SafetyNetJavaThreatType.SUBRESOURCE_FILTER, | ||
SafetyNetJavaThreatType.CSD_ALLOWLIST, | ||
SafetyNetJavaThreatType.POTENTIALLY_HARMFUL_APPLICATION, | ||
SafetyNetJavaThreatType.UNWANTED_SOFTWARE, | ||
})), | ||
SafetyNetJavaThreatType.POTENTIALLY_HARMFUL_APPLICATION); | ||
} | ||
} |
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
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