-
Notifications
You must be signed in to change notification settings - Fork 123
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
James Cover jdcove2
committed
Sep 19, 2023
1 parent
0a26a76
commit 4f7a4c1
Showing
2 changed files
with
68 additions
and
9 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
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,49 @@ | ||
package emissary.core; | ||
|
||
import emissary.config.ServiceConfigGuide; | ||
import emissary.test.core.junit5.UnitTest; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class SafeUsageCheckerTest extends UnitTest { | ||
@Test | ||
void testDifferentConfigs() { | ||
assertTrue(SafeUsageChecker.ENABLED_FROM_CONFIGURATION, "Enabled from config file should be false"); | ||
|
||
final ServiceConfigGuide scg = new ServiceConfigGuide(); | ||
|
||
scg.addEntry(SafeUsageChecker.ENABLED_KEY, Boolean.toString(false)); | ||
|
||
assertFalse(new SafeUsageChecker(scg).enabled, "Enabled should be false!"); | ||
|
||
scg.removeAllEntries(SafeUsageChecker.ENABLED_KEY); | ||
scg.addEntry(SafeUsageChecker.ENABLED_KEY, Boolean.toString(true)); | ||
|
||
assertTrue(new SafeUsageChecker(scg).enabled, "Enabled should be true!"); | ||
} | ||
|
||
@Test | ||
void testDisabled() { | ||
final ServiceConfigGuide scg = new ServiceConfigGuide(); | ||
|
||
scg.addEntry(SafeUsageChecker.ENABLED_KEY, Boolean.toString(false)); | ||
|
||
final SafeUsageChecker suc = new SafeUsageChecker(scg); | ||
final byte[] bytes0 = new byte[10]; | ||
final byte[] bytes1 = new byte[10]; | ||
|
||
suc.reset(); | ||
suc.resetCacheThenRecordSnapshot(bytes0); | ||
suc.recordSnapshot(bytes1); | ||
|
||
Arrays.fill(bytes0, (byte) 10); | ||
Arrays.fill(bytes1, (byte) 20); | ||
|
||
assertFalse(suc.checkForUnsafeDataChanges(), "Disabled SafeUsageChecker should return false!"); | ||
} | ||
} |