From 425a00c37f9faa60eff9dbf0fd4988c4c1ba9807 Mon Sep 17 00:00:00 2001 From: maximthomas Date: Tue, 20 Oct 2026 15:21:54 +0300 Subject: [PATCH 1/4] [#1187] Install the scripting tests' empty Guice module loader before the suite InjectorHolder builds the first injector of the JVM from the module loader in place at that moment and never reads the loader again. GroovyValidatorTest, JavaScriptValidatorTest and GroovyAstTransformEscapeTest set the empty loader from a @BeforeMethod, so any class that reached the holder earlier left it built from the default loader, which cannot build an injector on this classpath, and all three classes then failed in setupGuiceModules. Set the loader from @BeforeSuite(alwaysRun = true) in each of the three classes, so a single-class run is covered too, and drop the overrides that only set the loader before calling super. --- .../GroovyAstTransformEscapeTest.java | 18 ++++++++++---- .../openam/scripting/GroovyValidatorTest.java | 24 +++++++++++++------ .../scripting/JavaScriptValidatorTest.java | 17 +++++++------ 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyAstTransformEscapeTest.java b/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyAstTransformEscapeTest.java index 29cd6ecddd..817b5a0515 100644 --- a/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyAstTransformEscapeTest.java +++ b/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyAstTransformEscapeTest.java @@ -25,6 +25,7 @@ import org.forgerock.openam.shared.guice.SharedGuiceModule; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import java.lang.annotation.Annotation; @@ -46,16 +47,25 @@ public class GroovyAstTransformEscapeTest extends GuiceTestCase { /** System property the malicious payloads attempt to set; if it is ever non-null the escape executed. */ private static final String CANARY = "openam.test.ghsa_5hgj_6j53_p729.executed"; - @BeforeMethod - @Override - public void setupGuiceModules() throws Exception { - // Mirror GroovyValidatorTest: don't let other Guice modules on the classpath load. + /** + * Have the injector built from no modules before any test of the suite runs, for the reasons and with the limits + * given on {@link GroovyValidatorTest#setupGuiceModuleLoader()}. This class needs its own copy: when it runs alone, + * as with {@code -Dtest=GroovyAstTransformEscapeTest} or from an IDE, the other classes' {@code @BeforeSuite} + * methods do not run. + */ + @BeforeSuite(alwaysRun = true) + public void setupGuiceModuleLoader() { InjectorConfiguration.setGuiceModuleLoader(new GuiceModuleLoader() { @Override public Set> getGuiceModules(Class aClass) { return new HashSet<>(); } }); + } + + @BeforeMethod + @Override + public void setupGuiceModules() throws Exception { super.setupGuiceModules(); System.clearProperty(CANARY); } diff --git a/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyValidatorTest.java b/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyValidatorTest.java index 24fa355514..fd12da31d7 100644 --- a/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyValidatorTest.java +++ b/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyValidatorTest.java @@ -12,6 +12,7 @@ * information: "Portions copyright [year] [name of copyright owner]". * * Copyright 2014-2015 ForgeRock AS. + * Portions Copyright 2026 3A Systems, LLC. */ package org.forgerock.openam.scripting; @@ -24,7 +25,7 @@ import org.forgerock.guice.core.InjectorHolder; import org.forgerock.openam.scripting.guice.ScriptingGuiceModule; import org.forgerock.openam.shared.guice.SharedGuiceModule; -import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import java.lang.annotation.Annotation; @@ -40,18 +41,27 @@ @GuiceModules({SharedGuiceModule.class, ScriptingGuiceModule.class}) public class GroovyValidatorTest extends GuiceTestCase { - @BeforeMethod - @Override - public void setupGuiceModules() throws Exception { - //This ensures that the other Guice modules on the classpath don't get - //loaded as Guice will balk. + /** + * Before each test, {@link GuiceTestCase#setupGuiceModules()} asks {@link InjectorHolder} for its injector. The + * holder builds the first injector of the JVM from the module loader in place at that moment and never consults the + * loader again. The default loader collects every Guice module on the test classpath, Guice cannot build an + * injector from those, and the holder class then stays broken for every later test in the same JVM. Ask for an + * injector built from no modules instead, before any test of the suite runs: a {@code @BeforeMethod} or + * {@code @BeforeClass} comes too late whenever surefire happens to run another class that touches the holder ahead + * of this one. + * + * Two limits remain. TestNG creates the instances of all test classes before any {@code @BeforeSuite} method runs, + * so a constructor or field initializer that reaches the holder still goes first. And this method covers other + * classes only while the whole suite runs in one JVM ({@code forkCount=1}, {@code reuseForks=true}). + */ + @BeforeSuite(alwaysRun = true) + public void setupGuiceModuleLoader() { InjectorConfiguration.setGuiceModuleLoader(new GuiceModuleLoader() { @Override public Set> getGuiceModules(Class aClass) { return new HashSet<>(); } }); - super.setupGuiceModules(); } @Test(expectedExceptions = NullPointerException.class) diff --git a/openam-scripting/src/test/java/org/forgerock/openam/scripting/JavaScriptValidatorTest.java b/openam-scripting/src/test/java/org/forgerock/openam/scripting/JavaScriptValidatorTest.java index cbfbb792c7..2d785c11a5 100644 --- a/openam-scripting/src/test/java/org/forgerock/openam/scripting/JavaScriptValidatorTest.java +++ b/openam-scripting/src/test/java/org/forgerock/openam/scripting/JavaScriptValidatorTest.java @@ -12,6 +12,7 @@ * information: "Portions copyright [year] [name of copyright owner]". * * Copyright 2014-2015 ForgeRock AS. + * Portions Copyright 2026 3A Systems, LLC. */ package org.forgerock.openam.scripting; @@ -23,7 +24,7 @@ import org.forgerock.guice.core.InjectorConfiguration; import org.forgerock.openam.scripting.guice.ScriptingGuiceModule; import org.forgerock.openam.shared.guice.SharedGuiceModule; -import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import java.lang.annotation.Annotation; @@ -36,18 +37,20 @@ @GuiceModules({SharedGuiceModule.class, ScriptingGuiceModule.class}) public class JavaScriptValidatorTest extends GuiceTestCase { - @BeforeMethod - @Override - public void setupGuiceModules() throws Exception { - //This ensures that the other Guice modules on the classpath don't get - //loaded as Guice will balk. + /** + * Have the injector built from no modules before any test of the suite runs, for the reasons and with the limits + * given on {@link GroovyValidatorTest#setupGuiceModuleLoader()}. This class needs its own copy: when it runs alone, + * as with {@code -Dtest=JavaScriptValidatorTest} or from an IDE, the other classes' {@code @BeforeSuite} methods do + * not run. + */ + @BeforeSuite(alwaysRun = true) + public void setupGuiceModuleLoader() { InjectorConfiguration.setGuiceModuleLoader(new GuiceModuleLoader() { @Override public Set> getGuiceModules(Class aClass) { return new HashSet<>(); } }); - super.setupGuiceModules(); } @Test(expectedExceptions = NullPointerException.class) From 8d8e4d2edfc3273304c9ca788c41de153bbd13cb Mon Sep 17 00:00:00 2001 From: maximthomas Date: Tue, 20 Oct 2026 15:26:31 +0300 Subject: [PATCH 2/4] [#1187] Install the audit context test's Guice module loader before the suite AuditContextFilter reads its TransactionIdConfiguration from InjectorHolder. AuditContextFilterTest is not a GuiceTestCase, so the binding has to be in the holder's own injector, the first injector of the JVM, which the holder builds from the module loader in place at that moment. The test set its loader from a @BeforeClass, which comes too late whenever another class reaches the holder first. Set the loader, still with TestGuiceModule, from @BeforeSuite(alwaysRun = true). --- .../openam/audit/AuditContextFilterTest.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/openam-audit/openam-audit-context/src/test/java/org/forgerock/openam/audit/AuditContextFilterTest.java b/openam-audit/openam-audit-context/src/test/java/org/forgerock/openam/audit/AuditContextFilterTest.java index ea82d00a56..7422e7a774 100644 --- a/openam-audit/openam-audit-context/src/test/java/org/forgerock/openam/audit/AuditContextFilterTest.java +++ b/openam-audit/openam-audit-context/src/test/java/org/forgerock/openam/audit/AuditContextFilterTest.java @@ -12,7 +12,7 @@ * information: "Portions copyright [year] [name of copyright owner]". * * Copyright 2015 ForgeRock AS. - * Portions Copyrighted 2025 3A Systems LLC. + * Portions Copyrighted 2025-2026 3A Systems LLC. */ package org.forgerock.openam.audit; @@ -35,8 +35,8 @@ import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import jakarta.servlet.FilterChain; @@ -55,8 +55,22 @@ public class AuditContextFilterTest { @Mock private HttpServletResponse httpServletResponse; @Mock private FilterChain filterChain; - @BeforeClass - public void setUpSuite() throws Exception { + /** + * {@link AuditContextFilter} asks {@link org.forgerock.guice.core.InjectorHolder} for a + * {@link TransactionIdConfiguration}, which no module the default loader finds on this classpath binds. This class + * is not a {@code GuiceTestCase}, so no per-test injector is registered: the binding from {@link TestGuiceModule} + * has to be in the holder's own injector, the first injector of the JVM. The holder builds that injector from the + * module loader in place at that moment and never consults the loader again, so ask for {@link TestGuiceModule} + * before any test of the suite runs: a {@code @BeforeClass} comes too late whenever surefire happens to run another + * class that touches the holder ahead of this one. + * + * Two limits remain. TestNG creates the instances of all test classes before any {@code @BeforeSuite} method runs, + * so a constructor or field initializer that reaches the holder still goes first. And the loader is set for the + * whole JVM: every other class in it that reaches the holder sees this binding, and a second class that sets a + * different loader from its own {@code @BeforeSuite} would make the winner depend on class order again. + */ + @BeforeSuite(alwaysRun = true) + public void setupGuiceModuleLoader() { InjectorConfiguration.setGuiceModuleLoader(new GuiceModuleLoader() { @Override public Set> getGuiceModules(Class aClass) { From ebf306f22d56ecd164ca7cc4b39df60ee6bb99b8 Mon Sep 17 00:00:00 2001 From: maximthomas Date: Tue, 20 Oct 2026 17:19:27 +0300 Subject: [PATCH 3/4] [#1187] Install the scripting tests' empty Guice module loader from a TestNG execution listener The three @BeforeSuite copies covered only runs that included one of the three classes, and came after TestNG had already created every test instance. A TestNG IExecutionListener registered through META-INF/services/org.testng.ITestNGListener runs before any test instance is created, in every TestNG run of the module, so one listener replaces the three hooks and covers constructors, field initializers and runs of any other class too. GroovyAstTransformEscapeTest no longer overrides setupGuiceModules() just to clear its canary: clearCanary() now runs before and after each test. --- .../EmptyGuiceModuleLoaderListener.java | 48 +++++++++++++++++++ .../GroovyAstTransformEscapeTest.java | 29 ----------- .../openam/scripting/GroovyValidatorTest.java | 31 ------------ .../scripting/JavaScriptValidatorTest.java | 23 --------- .../services/org.testng.ITestNGListener | 16 +++++++ 5 files changed, 64 insertions(+), 83 deletions(-) create mode 100644 openam-scripting/src/test/java/org/forgerock/openam/scripting/EmptyGuiceModuleLoaderListener.java create mode 100644 openam-scripting/src/test/resources/META-INF/services/org.testng.ITestNGListener diff --git a/openam-scripting/src/test/java/org/forgerock/openam/scripting/EmptyGuiceModuleLoaderListener.java b/openam-scripting/src/test/java/org/forgerock/openam/scripting/EmptyGuiceModuleLoaderListener.java new file mode 100644 index 0000000000..21eefbdd2f --- /dev/null +++ b/openam-scripting/src/test/java/org/forgerock/openam/scripting/EmptyGuiceModuleLoaderListener.java @@ -0,0 +1,48 @@ +/* + * The contents of this file are subject to the terms of the Common Development and + * Distribution License (the License). You may not use this file except in compliance with the + * License. + * + * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the + * specific language governing permission and limitations under the License. + * + * When distributing Covered Software, include this CDDL Header Notice in each file and include + * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL + * Header, with the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions copyright [year] [name of copyright owner]". + * + * Copyright 2026 3A Systems, LLC. + */ + +package org.forgerock.openam.scripting; + +import java.util.Collections; + +import org.forgerock.guice.core.InjectorConfiguration; +import org.forgerock.guice.core.InjectorHolder; +import org.testng.IExecutionListener; + +/** + * Has {@link InjectorHolder} build its injector from no modules in every TestNG run of this module. + * + *

The {@code GuiceTestCase} subclasses here ask the holder for its injector before each test, and then register an + * injector of their own built from {@code @GuiceModules}. The holder builds the first injector of the JVM from the + * module loader in place at that moment and never consults the loader again. The default loader collects every Guice + * module on the test classpath, Guice cannot build an injector from those, and the holder class then stays broken for + * every later test in the same JVM. So the empty loader has to be in place before any class reaches the holder.

+ * + *

TestNG loads this listener through {@code META-INF/services/org.testng.ITestNGListener} and calls + * {@link #onExecutionStart()} before it creates any test instance. That covers constructors and field initializers, + * and every run of the module, whichever classes it includes and however surefire forks it.

+ */ +public class EmptyGuiceModuleLoaderListener implements IExecutionListener { + + @Override + public void onExecutionStart() { + InjectorConfiguration.setGuiceModuleLoader(moduleAnnotation -> Collections.emptySet()); + } + + @Override + public void onExecutionFinish() { + } +} diff --git a/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyAstTransformEscapeTest.java b/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyAstTransformEscapeTest.java index 817b5a0515..8a8d89e487 100644 --- a/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyAstTransformEscapeTest.java +++ b/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyAstTransformEscapeTest.java @@ -16,22 +16,15 @@ package org.forgerock.openam.scripting; -import com.google.inject.Module; -import org.forgerock.guice.core.GuiceModuleLoader; import org.forgerock.guice.core.GuiceModules; import org.forgerock.guice.core.GuiceTestCase; -import org.forgerock.guice.core.InjectorConfiguration; import org.forgerock.openam.scripting.guice.ScriptingGuiceModule; import org.forgerock.openam.shared.guice.SharedGuiceModule; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; -import java.lang.annotation.Annotation; -import java.util.HashSet; import java.util.List; -import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; @@ -47,29 +40,7 @@ public class GroovyAstTransformEscapeTest extends GuiceTestCase { /** System property the malicious payloads attempt to set; if it is ever non-null the escape executed. */ private static final String CANARY = "openam.test.ghsa_5hgj_6j53_p729.executed"; - /** - * Have the injector built from no modules before any test of the suite runs, for the reasons and with the limits - * given on {@link GroovyValidatorTest#setupGuiceModuleLoader()}. This class needs its own copy: when it runs alone, - * as with {@code -Dtest=GroovyAstTransformEscapeTest} or from an IDE, the other classes' {@code @BeforeSuite} - * methods do not run. - */ - @BeforeSuite(alwaysRun = true) - public void setupGuiceModuleLoader() { - InjectorConfiguration.setGuiceModuleLoader(new GuiceModuleLoader() { - @Override - public Set> getGuiceModules(Class aClass) { - return new HashSet<>(); - } - }); - } - @BeforeMethod - @Override - public void setupGuiceModules() throws Exception { - super.setupGuiceModules(); - System.clearProperty(CANARY); - } - @AfterMethod public void clearCanary() { System.clearProperty(CANARY); diff --git a/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyValidatorTest.java b/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyValidatorTest.java index fd12da31d7..bf4307e2a4 100644 --- a/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyValidatorTest.java +++ b/openam-scripting/src/test/java/org/forgerock/openam/scripting/GroovyValidatorTest.java @@ -17,21 +17,13 @@ package org.forgerock.openam.scripting; -import com.google.inject.Module; -import org.forgerock.guice.core.GuiceModuleLoader; import org.forgerock.guice.core.GuiceModules; import org.forgerock.guice.core.GuiceTestCase; -import org.forgerock.guice.core.InjectorConfiguration; -import org.forgerock.guice.core.InjectorHolder; import org.forgerock.openam.scripting.guice.ScriptingGuiceModule; import org.forgerock.openam.shared.guice.SharedGuiceModule; -import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; -import java.lang.annotation.Annotation; -import java.util.HashSet; import java.util.List; -import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; @@ -41,29 +33,6 @@ @GuiceModules({SharedGuiceModule.class, ScriptingGuiceModule.class}) public class GroovyValidatorTest extends GuiceTestCase { - /** - * Before each test, {@link GuiceTestCase#setupGuiceModules()} asks {@link InjectorHolder} for its injector. The - * holder builds the first injector of the JVM from the module loader in place at that moment and never consults the - * loader again. The default loader collects every Guice module on the test classpath, Guice cannot build an - * injector from those, and the holder class then stays broken for every later test in the same JVM. Ask for an - * injector built from no modules instead, before any test of the suite runs: a {@code @BeforeMethod} or - * {@code @BeforeClass} comes too late whenever surefire happens to run another class that touches the holder ahead - * of this one. - * - * Two limits remain. TestNG creates the instances of all test classes before any {@code @BeforeSuite} method runs, - * so a constructor or field initializer that reaches the holder still goes first. And this method covers other - * classes only while the whole suite runs in one JVM ({@code forkCount=1}, {@code reuseForks=true}). - */ - @BeforeSuite(alwaysRun = true) - public void setupGuiceModuleLoader() { - InjectorConfiguration.setGuiceModuleLoader(new GuiceModuleLoader() { - @Override - public Set> getGuiceModules(Class aClass) { - return new HashSet<>(); - } - }); - } - @Test(expectedExceptions = NullPointerException.class) public void shouldRejectNullScript() { SupportedScriptingLanguage.GROOVY.getScriptValidator().validateScript(null); diff --git a/openam-scripting/src/test/java/org/forgerock/openam/scripting/JavaScriptValidatorTest.java b/openam-scripting/src/test/java/org/forgerock/openam/scripting/JavaScriptValidatorTest.java index 2d785c11a5..c7b0afc176 100644 --- a/openam-scripting/src/test/java/org/forgerock/openam/scripting/JavaScriptValidatorTest.java +++ b/openam-scripting/src/test/java/org/forgerock/openam/scripting/JavaScriptValidatorTest.java @@ -17,42 +17,19 @@ package org.forgerock.openam.scripting; -import com.google.inject.Module; -import org.forgerock.guice.core.GuiceModuleLoader; import org.forgerock.guice.core.GuiceModules; import org.forgerock.guice.core.GuiceTestCase; -import org.forgerock.guice.core.InjectorConfiguration; import org.forgerock.openam.scripting.guice.ScriptingGuiceModule; import org.forgerock.openam.shared.guice.SharedGuiceModule; -import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; -import java.lang.annotation.Annotation; -import java.util.HashSet; import java.util.List; -import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; @GuiceModules({SharedGuiceModule.class, ScriptingGuiceModule.class}) public class JavaScriptValidatorTest extends GuiceTestCase { - /** - * Have the injector built from no modules before any test of the suite runs, for the reasons and with the limits - * given on {@link GroovyValidatorTest#setupGuiceModuleLoader()}. This class needs its own copy: when it runs alone, - * as with {@code -Dtest=JavaScriptValidatorTest} or from an IDE, the other classes' {@code @BeforeSuite} methods do - * not run. - */ - @BeforeSuite(alwaysRun = true) - public void setupGuiceModuleLoader() { - InjectorConfiguration.setGuiceModuleLoader(new GuiceModuleLoader() { - @Override - public Set> getGuiceModules(Class aClass) { - return new HashSet<>(); - } - }); - } - @Test(expectedExceptions = NullPointerException.class) public void shouldRejectNullScript() { SupportedScriptingLanguage.JAVASCRIPT.getScriptValidator().validateScript(null); diff --git a/openam-scripting/src/test/resources/META-INF/services/org.testng.ITestNGListener b/openam-scripting/src/test/resources/META-INF/services/org.testng.ITestNGListener new file mode 100644 index 0000000000..d1e4472465 --- /dev/null +++ b/openam-scripting/src/test/resources/META-INF/services/org.testng.ITestNGListener @@ -0,0 +1,16 @@ +# +# The contents of this file are subject to the terms of the Common Development and +# Distribution License (the License). You may not use this file except in compliance with the +# License. +# +# You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the +# specific language governing permission and limitations under the License. +# +# When distributing Covered Software, include this CDDL Header Notice in each file and include +# the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL +# Header, with the fields enclosed by brackets [] replaced by your own identifying +# information: "Portions copyright [year] [name of copyright owner]". +# +# Copyright 2026 3A Systems, LLC. +# +org.forgerock.openam.scripting.EmptyGuiceModuleLoaderListener From 72fdecfdeb61974a0465f0e9048b8704acb42b3e Mon Sep 17 00:00:00 2001 From: maximthomas Date: Tue, 20 Oct 2026 17:19:27 +0300 Subject: [PATCH 4/4] [#1187] Reset the audit context test's trust flag after each test TestGuiceModule now feeds the holder's injector for the whole JVM, so any other class that asks the holder for TransactionIdConfiguration would see whatever trustHeader value the last AuditContextFilterTest method left. Put it back to its default after each test. Install the loader with a lambda instead of an anonymous class. --- .../openam/audit/AuditContextFilterTest.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/openam-audit/openam-audit-context/src/test/java/org/forgerock/openam/audit/AuditContextFilterTest.java b/openam-audit/openam-audit-context/src/test/java/org/forgerock/openam/audit/AuditContextFilterTest.java index 7422e7a774..a488da3c5f 100644 --- a/openam-audit/openam-audit-context/src/test/java/org/forgerock/openam/audit/AuditContextFilterTest.java +++ b/openam-audit/openam-audit-context/src/test/java/org/forgerock/openam/audit/AuditContextFilterTest.java @@ -21,11 +21,8 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.when; -import java.lang.annotation.Annotation; import java.util.Collections; -import java.util.Set; -import org.forgerock.guice.core.GuiceModuleLoader; import org.forgerock.guice.core.InjectorConfiguration; import org.forgerock.http.header.TransactionIdHeader; import org.forgerock.openam.audit.context.AuditContextFilter; @@ -35,6 +32,7 @@ import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; @@ -44,7 +42,6 @@ import jakarta.servlet.http.HttpServletResponse; import com.google.inject.AbstractModule; -import com.google.inject.Module; /** * @since 13.0.0 @@ -71,12 +68,7 @@ public class AuditContextFilterTest { */ @BeforeSuite(alwaysRun = true) public void setupGuiceModuleLoader() { - InjectorConfiguration.setGuiceModuleLoader(new GuiceModuleLoader() { - @Override - public Set> getGuiceModules(Class aClass) { - return Collections.>singleton(TestGuiceModule.class); - } - }); + InjectorConfiguration.setGuiceModuleLoader(moduleAnnotation -> Collections.singleton(TestGuiceModule.class)); } @BeforeMethod @@ -84,6 +76,15 @@ public void setupTests() { MockitoAnnotations.initMocks(this); } + /** + * The binding from {@link TestGuiceModule} serves every class in the JVM, so put the flag the tests change back to + * its default. + */ + @AfterMethod(alwaysRun = true) + public void resetTrustHeader() { + TransactionIdConfigurationImpl.trustHeader = true; + } + @Test public void shouldSetTransactionIdFromHttpHeaderAndClearRequestContextWhenFinished() throws Exception { // Given