From e3f5b91177e20d95f231abc595944b1f885acd95 Mon Sep 17 00:00:00 2001 From: Emmanuel Duchastenier Date: Fri, 12 Apr 2024 16:31:49 +0200 Subject: [PATCH] fix(merge): restore test class proper location that were mixed up when reporting change from web -> engine --- .../properties/SecurityPropertiesTest.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 bpm/bonita-web-server/src/test/java/org/bonitasoft/console/common/server/preferences/properties/SecurityPropertiesTest.java diff --git a/bpm/bonita-web-server/src/test/java/org/bonitasoft/console/common/server/preferences/properties/SecurityPropertiesTest.java b/bpm/bonita-web-server/src/test/java/org/bonitasoft/console/common/server/preferences/properties/SecurityPropertiesTest.java new file mode 100644 index 00000000000..816adeb811f --- /dev/null +++ b/bpm/bonita-web-server/src/test/java/org/bonitasoft/console/common/server/preferences/properties/SecurityPropertiesTest.java @@ -0,0 +1,47 @@ +/** + * Copyright (C) 2024 Bonitasoft S.A. + * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble + * This library is free software; you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Foundation + * version 2.1 of the License. + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301, USA. + **/ +package org.bonitasoft.console.common.server.preferences.properties; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.bonitasoft.console.common.server.preferences.properties.SecurityProperties.SANITIZER_PROTECTION; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; + +import org.junit.Test; + +public class SecurityPropertiesTest { + + private final SecurityProperties securityProperties = spy(new SecurityProperties()); + + @Test + public void invalid_or_absent_sanitizer_conf_should_be_disabled() { + doReturn(null).when(securityProperties).getPlatformProperty(SANITIZER_PROTECTION); + assertThat(securityProperties.isSanitizerProtectionEnabled()).isFalse(); + + doReturn("").when(securityProperties).getPlatformProperty(SANITIZER_PROTECTION); + assertThat(securityProperties.isSanitizerProtectionEnabled()).isFalse(); + + doReturn("false").when(securityProperties).getPlatformProperty(SANITIZER_PROTECTION); + assertThat(securityProperties.isSanitizerProtectionEnabled()).isFalse(); + } + + @Test + public void sanitizer_should_be_enabled_for_true_value_whatever_the_case() { + doReturn("true").when(securityProperties).getPlatformProperty(SANITIZER_PROTECTION); + assertThat(securityProperties.isSanitizerProtectionEnabled()).isTrue(); + + doReturn("trUE").when(securityProperties).getPlatformProperty(SANITIZER_PROTECTION); + assertThat(securityProperties.isSanitizerProtectionEnabled()).isTrue(); + } +}