From 6475c392fc10d9b97181990b1495a3985931193a Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Tue, 13 Jun 2023 20:20:32 +0200 Subject: [PATCH] chore: add tests for testCanWeReadThisEnvironmentVariable --- .../security/SecurityProfileTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/net/sourceforge/plantuml/security/SecurityProfileTest.java diff --git a/test/net/sourceforge/plantuml/security/SecurityProfileTest.java b/test/net/sourceforge/plantuml/security/SecurityProfileTest.java new file mode 100644 index 000000000..8f7c31a8b --- /dev/null +++ b/test/net/sourceforge/plantuml/security/SecurityProfileTest.java @@ -0,0 +1,58 @@ +package net.sourceforge.plantuml.security; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +/** + * Checks some aspects in {@link SecurityUtils}. + */ +class SecurityProfileTest { + + + @ParameterizedTest + @CsvSource( + value = { + // SecurityProfile variable, expected result + " SANDBOX, path.separator, true", + " ALLOWLIST, path.separator, true", + " INTERNET, path.separator, true", + " LEGACY, path.separator, true", + " UNSECURE, path.separator, true", + + " SANDBOX, line.separator, true", + " ALLOWLIST, line.separator, true", + " INTERNET, line.separator, true", + " LEGACY, line.separator, true", + " UNSECURE, line.separator, true", + + " SANDBOX, plantuml.security.foo, false", + " ALLOWLIST, plantuml.security.foo, false", + " INTERNET, plantuml.security.foo, false", + " LEGACY, plantuml.security.foo, false", + " UNSECURE, plantuml.security.foo, false", + + " SANDBOX, plantuml.dummy, true", + " ALLOWLIST, plantuml.dummy, true", + " INTERNET, plantuml.dummy, true", + " LEGACY, plantuml.dummy, true", + " UNSECURE, plantuml.dummy, true", + + " SANDBOX, custom.name, false", + " ALLOWLIST, custom.name, false", + " INTERNET, custom.name, false", + " LEGACY, custom.name, false", + " UNSECURE, custom.name, true", + + }, + nullValues = { "NULL" }) + void testCanWeReadThisEnvironmentVariable(String profileName, String variableName, String expected) { + SecurityProfile profile = SecurityProfile.valueOf(profileName); + if ("true".equalsIgnoreCase(expected)) + assertTrue(profile.canWeReadThisEnvironmentVariable(variableName)); + else + assertFalse(profile.canWeReadThisEnvironmentVariable(variableName)); + } + +}