3131import jakarta .enterprise .context .ApplicationScoped ;
3232import jakarta .enterprise .inject .Vetoed ;
3333import jakarta .inject .Inject ;
34+ import jakarta .security .enterprise .AuthenticationStatus ;
35+ import jakarta .security .enterprise .authentication .mechanism .http .HttpMessageContext ;
3436import jakarta .security .enterprise .authentication .mechanism .http .OpenIdAuthenticationMechanismDefinition ;
3537import jakarta .security .enterprise .authentication .mechanism .http .openid .DisplayType ;
3638import jakarta .security .enterprise .authentication .mechanism .http .openid .PromptType ;
4042import static org .junit .Assert .assertEquals ;
4143import static org .junit .Assert .assertThrows ;
4244import static org .junit .Assert .assertTrue ;
45+ import static org .mockito .Mockito .mock ;
4346import static org .mockito .Mockito .when ;
4447
4548@ Vetoed
4649@ RunWith (ApplicationComposer .class )
47- @ Classes (cdi = true , value = {OpenIdAuthenticationMechanism .class , TomEEOpenIdContext .class , OpenIdAuthenticationMechanismTest .SimpleStorageHandler .class })
50+ @ Classes (cdi = true , value = {OpenIdAuthenticationMechanismTest . TestOpenIdAuthenticationMechanism .class , TomEEOpenIdContext .class , OpenIdAuthenticationMechanismTest .SimpleStorageHandler .class })
4851public class OpenIdAuthenticationMechanismTest {
4952
5053 @ Inject
@@ -72,6 +75,8 @@ public void configureMockedDefinition() {
7275 when (definition .display ()).thenReturn (null );
7376 when (definition .prompt ()).thenReturn (new PromptType [0 ]);
7477 when (definition .extraParameters ()).thenReturn (new String [0 ]);
78+ when (definition .logout ().notifyProvider ()).thenReturn (false );
79+ when (definition .logout ().redirectURI ()).thenReturn ("" );
7580 }
7681
7782 @ Test
@@ -140,6 +145,25 @@ public void authorizationExtraParametersMalformed() {
140145 assertThrows (IllegalArgumentException .class , () -> authenticationMechanism .buildAuthorizationUri (null , null ));
141146 }
142147
148+ @ Test
149+ public void refreshTokenFailureDoesNotThrow () {
150+ HttpServletRequest request = mock (HttpServletRequest .class );
151+ HttpServletResponse response = mock (HttpServletResponse .class );
152+ HttpMessageContext messageContext = mock (HttpMessageContext .class , Answers .RETURNS_DEEP_STUBS );
153+ when (request .getRequestURL ()).thenReturn (new StringBuffer ("https://example.com/app" ));
154+
155+ assertEquals (AuthenticationStatus .SEND_FAILURE ,
156+ authenticationMechanism .refreshTokens (request , response , messageContext ));
157+ }
158+
159+ @ ApplicationScoped
160+ public static class TestOpenIdAuthenticationMechanism extends OpenIdAuthenticationMechanism {
161+ @ Override
162+ public void cleanSubject (HttpServletRequest request , HttpServletResponse response , HttpMessageContext httpMessageContext ) {
163+ // no-op for this focused failure-path test
164+ }
165+ }
166+
143167 @ ApplicationScoped
144168 protected static class SimpleStorageHandler extends OpenIdStorageHandler {
145169
@@ -170,4 +194,4 @@ public void delete(HttpServletRequest request, HttpServletResponse response, Str
170194
171195 }
172196 }
173- }
197+ }
0 commit comments