From b72f1447a097289b0c49130241472713d8b6c930 Mon Sep 17 00:00:00 2001 From: Sergey Beryozkin Date: Thu, 5 Dec 2024 10:48:50 +0000 Subject: [PATCH] Make sure OidcRequestContextProperties are always modifiable --- .../common/OidcRequestContextProperties.java | 3 +- .../OidcRequestContextPropertiesTest.java | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 extensions/oidc-common/runtime/src/test/java/io/quarkus/oidc/common/runtime/OidcRequestContextPropertiesTest.java diff --git a/extensions/oidc-common/runtime/src/main/java/io/quarkus/oidc/common/OidcRequestContextProperties.java b/extensions/oidc-common/runtime/src/main/java/io/quarkus/oidc/common/OidcRequestContextProperties.java index eda5b00cd66d3..45c0918cc7bef 100644 --- a/extensions/oidc-common/runtime/src/main/java/io/quarkus/oidc/common/OidcRequestContextProperties.java +++ b/extensions/oidc-common/runtime/src/main/java/io/quarkus/oidc/common/OidcRequestContextProperties.java @@ -1,6 +1,7 @@ package io.quarkus.oidc.common; import java.util.Collections; +import java.util.HashMap; import java.util.Map; public class OidcRequestContextProperties { @@ -16,7 +17,7 @@ public OidcRequestContextProperties() { } public OidcRequestContextProperties(Map properties) { - this.properties = properties; + this.properties = new HashMap<>(properties); } /** diff --git a/extensions/oidc-common/runtime/src/test/java/io/quarkus/oidc/common/runtime/OidcRequestContextPropertiesTest.java b/extensions/oidc-common/runtime/src/test/java/io/quarkus/oidc/common/runtime/OidcRequestContextPropertiesTest.java new file mode 100644 index 0000000000000..4402fe3e6e6a9 --- /dev/null +++ b/extensions/oidc-common/runtime/src/test/java/io/quarkus/oidc/common/runtime/OidcRequestContextPropertiesTest.java @@ -0,0 +1,31 @@ +package io.quarkus.oidc.common.runtime; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import io.quarkus.oidc.common.OidcRequestContextProperties; + +public class OidcRequestContextPropertiesTest { + + @Test + public void testModifyPropertiesDefaultConstructor() throws Exception { + OidcRequestContextProperties props = new OidcRequestContextProperties(); + assertNull(props.get("a")); + props.put("a", "value"); + assertEquals("value", props.get("a")); + } + + @Test + public void testModifyExistinProperties() throws Exception { + OidcRequestContextProperties props = new OidcRequestContextProperties(Map.of("a", "value")); + assertEquals("value", props.get("a")); + props.put("a", "avalue"); + assertEquals("avalue", props.get("a")); + props.put("b", "bvalue"); + assertEquals("bvalue", props.get("b")); + } +}