Skip to content

Commit 644dae9

Browse files
Fix: Route authentication logs to Eclipse Error Log (AST-136023) (#244)
* Fix AST-136023: Route authentication logs to Eclipse Error Log Replace SLF4J log calls in Authenticator.doAuthentication() with CxLogger so auth success/failure messages appear in .metadata/.log and the Eclipse Error Log UI instead of being silently dropped. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> * Fix AST-136023: Update unit tests to verify CxLogger static calls Replace SLF4J mockLogger verification with MockedStatic<CxLogger> to match the updated Authenticator.doAuthentication() which now routes log output through CxLogger instead of the SLF4J instance. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> * Refactor AST-136023: Use String.format for authentication status log message Replace string concatenation (AUTH_STATUS + cxValidateOutput) with String.format(PluginConstants.INFO_AUTHENTICATION_STATUS, cxValidateOutput) to be consistent with the error logging pattern. Updated the unit test assertion to verify the formatted string accordingly. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 1b94a50 commit 644dae9

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/unit/runner/AuthenticatorTest.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
import org.junit.jupiter.api.Test;
99
import org.mockito.MockedConstruction;
10+
import org.mockito.MockedStatic;
1011
import org.mockito.Mockito;
1112
import org.slf4j.Logger;
1213

1314
import com.checkmarx.ast.wrapper.CxException;
1415
import com.checkmarx.ast.wrapper.CxWrapper;
1516
import com.checkmarx.eclipse.runner.Authenticator;
17+
import com.checkmarx.eclipse.utils.CxLogger;
1618
import com.checkmarx.eclipse.utils.PluginConstants;
1719

1820
class AuthenticatorTest {
@@ -24,14 +26,15 @@ void testDoAuthenticationSuccess() throws Exception {
2426

2527
try (MockedConstruction<CxWrapper> mocked =
2628
Mockito.mockConstruction(CxWrapper.class,
27-
(mock, context) -> when(mock.authValidate()).thenReturn("SUCCESS"))) {
29+
(mock, context) -> when(mock.authValidate()).thenReturn("SUCCESS"));
30+
MockedStatic<CxLogger> mockedCxLogger = Mockito.mockStatic(CxLogger.class)) {
2831

2932
Authenticator authenticator = new Authenticator(mockLogger);
3033

3134
String result = authenticator.doAuthentication("dummyKey", "--param");
3235

3336
assertEquals("SUCCESS", result);
34-
verify(mockLogger).info("Authentication Status: SUCCESS");
37+
mockedCxLogger.verify(() -> CxLogger.info(String.format(PluginConstants.INFO_AUTHENTICATION_STATUS, "SUCCESS")));
3538
}
3639
}
3740

@@ -43,17 +46,18 @@ void testDoAuthenticationIOException() throws Exception {
4346
try (MockedConstruction<CxWrapper> mocked =
4447
Mockito.mockConstruction(CxWrapper.class,
4548
(mock, context) -> when(mock.authValidate())
46-
.thenThrow(new IOException("IO error")))) {
49+
.thenThrow(new IOException("IO error")));
50+
MockedStatic<CxLogger> mockedCxLogger = Mockito.mockStatic(CxLogger.class)) {
4751

4852
Authenticator authenticator = new Authenticator(mockLogger);
4953

5054
String result = authenticator.doAuthentication("dummyKey", "--param");
5155

5256
assertEquals("IO error", result);
53-
verify(mockLogger).error(
54-
eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "IO error")),
55-
any(IOException.class)
56-
);
57+
mockedCxLogger.verify(() -> CxLogger.error(
58+
eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "IO error")),
59+
any(IOException.class)
60+
));
5761
}
5862
}
5963

@@ -65,17 +69,18 @@ void testDoAuthenticationInterruptedException() throws Exception {
6569
try (MockedConstruction<CxWrapper> mocked =
6670
Mockito.mockConstruction(CxWrapper.class,
6771
(mock, context) -> when(mock.authValidate())
68-
.thenThrow(new InterruptedException("Interrupted")))) {
72+
.thenThrow(new InterruptedException("Interrupted")));
73+
MockedStatic<CxLogger> mockedCxLogger = Mockito.mockStatic(CxLogger.class)) {
6974

7075
Authenticator authenticator = new Authenticator(mockLogger);
7176

7277
String result = authenticator.doAuthentication("dummyKey", "--param");
7378

7479
assertEquals("Interrupted", result);
75-
verify(mockLogger).error(
76-
eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "Interrupted")),
77-
any(InterruptedException.class)
78-
);
80+
mockedCxLogger.verify(() -> CxLogger.error(
81+
eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "Interrupted")),
82+
any(InterruptedException.class)
83+
));
7984
}
8085
}
8186

@@ -87,17 +92,18 @@ void testDoAuthenticationCxException() throws Exception {
8792
try (MockedConstruction<CxWrapper> mocked =
8893
Mockito.mockConstruction(CxWrapper.class,
8994
(mock, context) -> when(mock.authValidate())
90-
.thenThrow(new CxException(1, "Cx error")))) {
95+
.thenThrow(new CxException(1, "Cx error")));
96+
MockedStatic<CxLogger> mockedCxLogger = Mockito.mockStatic(CxLogger.class)) {
9197

9298
Authenticator authenticator = new Authenticator(mockLogger);
9399

94100
String result = authenticator.doAuthentication("dummyKey", "--param");
95101

96102
assertEquals("Cx error", result);
97-
verify(mockLogger).error(
98-
eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "Cx error")),
99-
any(CxException.class)
100-
);
103+
mockedCxLogger.verify(() -> CxLogger.error(
104+
eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "Cx error")),
105+
any(CxException.class)
106+
));
101107
}
102108
}
103109

checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/runner/Authenticator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public String doAuthentication(String apiKey, String additionalParams) {
3333
try {
3434
CxWrapper wrapper = new CxWrapper(config, log);
3535
String cxValidateOutput = wrapper.authValidate();
36-
log.info(AUTH_STATUS + cxValidateOutput);
36+
CxLogger.info(String.format(PluginConstants.INFO_AUTHENTICATION_STATUS, cxValidateOutput));
3737
return cxValidateOutput;
3838
} catch (IOException | InterruptedException | CxException e) {
39-
log.error(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, e.getMessage()), e);
39+
CxLogger.error(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, e.getMessage()), e);
4040
return e.getMessage();
4141
}
4242
}

0 commit comments

Comments
 (0)