-
-
Notifications
You must be signed in to change notification settings - Fork 290
Expand file tree
/
Copy pathBypassUniversalTest.kt
More file actions
65 lines (55 loc) · 2.88 KB
/
Copy pathBypassUniversalTest.kt
File metadata and controls
65 lines (55 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.celzero.bravedns.service
import org.junit.Test
import org.junit.Assert.assertEquals
/**
* Test for Bypass Universal functionality to ensure bypassed apps are not blocked
* by universal firewall rules. This test verifies the fix for issue #2148 where
* bypass universal setting was not respected in background blocking and device lock rules.
*/
class BypassUniversalTest {
@Test
fun testFirewallStatusBypassUniversal() {
// Test that BYPASS_UNIVERSAL status returns true for bypassUniversal()
val bypassStatus = FirewallManager.FirewallStatus.BYPASS_UNIVERSAL
assertEquals(true, bypassStatus.bypassUniversal())
// Test that other statuses return false
assertEquals(false, FirewallManager.FirewallStatus.NONE.bypassUniversal())
assertEquals(false, FirewallManager.FirewallStatus.EXCLUDE.bypassUniversal())
assertEquals(false, FirewallManager.FirewallStatus.ISOLATE.bypassUniversal())
}
@Test
fun testFirewallStatusIds() {
// Verify firewall status IDs are correctly defined
assertEquals(2, FirewallManager.FirewallStatus.BYPASS_UNIVERSAL.id)
assertEquals(3, FirewallManager.FirewallStatus.EXCLUDE.id)
assertEquals(4, FirewallManager.FirewallStatus.ISOLATE.id)
assertEquals(5, FirewallManager.FirewallStatus.NONE.id)
assertEquals(6, FirewallManager.FirewallStatus.UNTRACKED.id)
assertEquals(7, FirewallManager.FirewallStatus.BYPASS_DNS_FIREWALL.id)
}
@Test
fun testFirewallRulesetBypassRules() {
// Test that RULE8 is the correct bypass rule
assertEquals("Whitelist", FirewallRuleset.RULE8.id)
assertEquals(true, FirewallRuleset.isBypassRule(FirewallRuleset.RULE8))
// Test that blocking rules are not bypass rules
assertEquals(false, FirewallRuleset.isBypassRule(FirewallRuleset.RULE3)) // Device lock
assertEquals(false, FirewallRuleset.isBypassRule(FirewallRuleset.RULE4)) // Background
}
/**
* This test documents the expected behavior for the fix to issue #2148.
* The bug was that apps with BYPASS_UNIVERSAL status were still being blocked
* by universal rules like background blocking and device lock.
*/
@Test
fun testBypassUniversalBehaviorDocumentation() {
// This test documents that when an app has BYPASS_UNIVERSAL status:
// 1. It should not be blocked by background data rules (RULE4)
// 2. It should not be blocked by device lock rules (RULE3)
// 3. It should return RULE8 (Whitelist) from the main bypass check
// The fix ensures that blockBackgroundData() and device lock check
// both respect the bypass universal setting before applying blocking rules.
val bypassStatus = FirewallManager.FirewallStatus.BYPASS_UNIVERSAL
assertEquals(true, bypassStatus.bypassUniversal())
}
}