Skip to content

Commit 82d6c66

Browse files
Remove masked secrets functionality from codebase
1 parent 97c6c69 commit 82d6c66

File tree

6 files changed

+1
-351
lines changed

6 files changed

+1
-351
lines changed

src/main/java/com/checkmarx/ast/secretsrealtime/MaskResult.java

Lines changed: 0 additions & 96 deletions
This file was deleted.

src/main/java/com/checkmarx/ast/secretsrealtime/MaskedSecret.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/main/java/com/checkmarx/ast/wrapper/CxConstants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,4 @@ public final class CxConstants {
8080
static final String SUB_CMD_IAC_REALTIME = "iac-realtime";
8181
static final String SUB_CMD_SECRETS_REALTIME = "secrets-realtime";
8282
static final String SUB_CMD_CONTAINERS_REALTIME = "containers-realtime";
83-
static final String CMD_MASK_SECRETS = "mask";
8483
}

src/main/java/com/checkmarx/ast/wrapper/CxWrapper.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.checkmarx.ast.learnMore.LearnMore;
77
import com.checkmarx.ast.ossrealtime.OssRealtimeResults;
88
import com.checkmarx.ast.secretsrealtime.SecretsRealtimeResults;
9-
import com.checkmarx.ast.secretsrealtime.MaskResult;
9+
1010
import com.checkmarx.ast.iacrealtime.IacRealtimeResults;
1111
import com.checkmarx.ast.containersrealtime.ContainersRealtimeResults;
1212
import com.checkmarx.ast.predicate.CustomState;
@@ -442,22 +442,7 @@ public SecretsRealtimeResults secretsRealtimeScan(@NonNull String sourcePath, St
442442
return realtimeScan(CxConstants.SUB_CMD_SECRETS_REALTIME, sourcePath, ignoredFilePath, SecretsRealtimeResults::fromLine);
443443
}
444444

445-
/**
446-
* Executes mask secrets command to obfuscate/redact secrets in a file
447-
* @param filePath path to the file to mask
448-
* @return MaskResult containing masked secrets and masked file content
449-
*/
450-
public MaskResult maskSecrets(@NonNull String filePath) throws IOException, InterruptedException, CxException {
451-
this.logger.info("Executing 'mask' command using the CLI for file: {}", filePath);
452445

453-
List<String> arguments = new ArrayList<>();
454-
arguments.add(CxConstants.CMD_MASK_SECRETS);
455-
arguments.add(CxConstants.SOURCE);
456-
arguments.add(filePath);
457-
458-
String output = Execution.executeCommand(withConfigArguments(arguments), logger, line -> line);
459-
return MaskResult.fromJsonString(output);
460-
}
461446

462447
// Containers Realtime
463448
public ContainersRealtimeResults containersRealtimeScan(@NonNull String sourcePath, String ignoredFilePath)

src/test/java/com/checkmarx/ast/SecretsRealtimeResultsTest.java

Lines changed: 0 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import com.checkmarx.ast.realtime.RealtimeLocation;
44
import com.checkmarx.ast.secretsrealtime.SecretsRealtimeResults;
5-
import com.checkmarx.ast.secretsrealtime.MaskResult;
6-
import com.checkmarx.ast.secretsrealtime.MaskedSecret;
75
import com.checkmarx.ast.wrapper.CxException;
86
import org.junit.jupiter.api.*;
97

@@ -206,187 +204,6 @@ void secretsScanMultipleFileTypes() {
206204
}
207205
}
208206

209-
/* ------------------------------------------------------ */
210-
/* Integration tests for Secrets Masking functionality */
211-
/* ------------------------------------------------------ */
212-
213-
/**
214-
* Tests basic mask secrets functionality - successful case.
215-
* Similar to the JavaScript test, verifies that the mask command returns proper MaskResult
216-
* with masked secrets detected in a JSON file containing API keys and passwords.
217-
*/
218-
@Test
219-
@DisplayName("Mask secrets successful case - returns masked content")
220-
void maskSecretsSuccessfulCase() throws Exception {
221-
Assumptions.assumeTrue(isCliConfigured(), "PATH_TO_EXECUTABLE not configured - skipping integration test");
222-
String secretsFile = "src/test/resources/secrets-test.json";
223-
Assumptions.assumeTrue(Files.exists(Paths.get(secretsFile)), "Secrets test file not found - cannot test masking");
224-
225-
MaskResult result = wrapper.maskSecrets(secretsFile);
226-
227-
assertNotNull(result, "Mask result should not be null");
228-
assertNotNull(result.getMaskedSecrets(), "Masked secrets list should be initialized");
229-
assertNotNull(result.getMaskedFile(), "Masked file content should be provided");
230-
231-
// Expect at least one secret to be found in our test file
232-
assertFalse(result.getMaskedSecrets().isEmpty(), "Should find masked secrets in test file");
233-
234-
// Verify structure of masked secrets
235-
MaskedSecret firstSecret = result.getMaskedSecrets().get(0);
236-
assertNotNull(firstSecret.getMasked(), "Masked value should be provided");
237-
assertTrue(firstSecret.getLine() > 0, "Line number should be positive");
238-
239-
// Masked file should contain the original structure but with secrets redacted
240-
assertFalse(result.getMaskedFile().trim().isEmpty(), "Masked file content should not be empty");
241-
assertTrue(result.getMaskedFile().contains("{"), "Masked file should preserve JSON structure");
242-
}
243-
244-
/**
245-
* Tests mask functionality across different file types.
246-
* Verifies that the mask command can handle various file extensions and formats
247-
* without crashing and produces appropriate masked results.
248-
*/
249-
@Test
250-
@DisplayName("Mask secrets handles multiple file types correctly")
251-
void maskSecretsMultipleFileTypes() {
252-
Assumptions.assumeTrue(isCliConfigured(), "PATH_TO_EXECUTABLE not configured - skipping integration test");
253-
254-
String[] testFiles = {
255-
"src/test/resources/python-vul-file.py",
256-
"src/test/resources/csharp-file.cs"
257-
};
258-
259-
for (String filePath : testFiles) {
260-
if (Files.exists(Paths.get(filePath))) {
261-
assertDoesNotThrow(() -> {
262-
MaskResult result = wrapper.maskSecrets(filePath);
263-
assertNotNull(result, "Mask result should not be null for file: " + filePath);
264-
assertNotNull(result.getMaskedSecrets(), "Masked secrets should be initialized for: " + filePath);
265-
assertNotNull(result.getMaskedFile(), "Masked file should not be null for: " + filePath);
266-
}, "Mask command should handle file type gracefully: " + filePath);
267-
}
268-
}
269-
}
270-
271-
/**
272-
* Tests error handling when masking a non-existent file.
273-
* Verifies that the mask command properly throws a CxException with meaningful error message
274-
* when provided with invalid file paths.
275-
*/
276-
@Test
277-
@DisplayName("Mask secrets throws appropriate exception for non-existent file")
278-
void maskSecretsHandlesInvalidPath() {
279-
Assumptions.assumeTrue(isCliConfigured(), "PATH_TO_EXECUTABLE not configured - skipping integration test");
280-
281-
// Test with a non-existent file path
282-
String invalidPath = "src/test/resources/NonExistentFile.py";
283-
284-
// The CLI should throw a CxException with a meaningful error message for invalid paths
285-
CxException exception = assertThrows(CxException.class, () ->
286-
wrapper.maskSecrets(invalidPath)
287-
);
288-
289-
// Verify the exception contains information about the invalid file path
290-
String errorMessage = exception.getMessage();
291-
assertNotNull(errorMessage, "Exception should contain an error message");
292-
assertTrue(errorMessage.contains("invalid file path") || errorMessage.contains("file") || errorMessage.contains("path"),
293-
"Exception message should indicate the issue is related to file path: " + errorMessage);
294-
}
295-
296-
/**
297-
* Tests that masked file content differs from original when secrets are present.
298-
* Verifies that the masking process actually modifies the file content to redact secrets.
299-
*/
300-
@Test
301-
@DisplayName("Masked file content differs from original when secrets exist")
302-
void maskedContentDiffersFromOriginal() throws Exception {
303-
Assumptions.assumeTrue(isCliConfigured(), "PATH_TO_EXECUTABLE not configured - skipping integration test");
304-
String secretsFile = "src/test/resources/secrets-test.json";
305-
Assumptions.assumeTrue(Files.exists(Paths.get(secretsFile)), "Secrets test file not found - cannot test content masking");
306-
307-
// Read original file content
308-
String originalContent = Files.readString(Paths.get(secretsFile));
309-
310-
// Get masked content
311-
MaskResult result = wrapper.maskSecrets(secretsFile);
312-
assertNotNull(result, "Mask result should not be null");
313-
314-
String maskedContent = result.getMaskedFile();
315-
assertNotNull(maskedContent, "Masked content should not be null");
316-
317-
// Since our test file contains secrets, the content should be different after masking
318-
if (!result.getMaskedSecrets().isEmpty()) {
319-
assertNotEquals(originalContent, maskedContent,
320-
"Masked content should differ from original when secrets are present");
321-
322-
// Verify that original secrets are not present in masked content
323-
assertFalse(maskedContent.contains("sk-1234567890abcdef1234567890abcdef"),
324-
"Original API key should be masked in output");
325-
assertFalse(maskedContent.contains("SuperSecret123!"),
326-
"Original password should be masked in output");
327-
}
328-
}
329-
330-
/* ------------------------------------------------------ */
331-
/* Unit tests for Mask JSON parsing functionality */
332-
/* ------------------------------------------------------ */
333-
334-
/**
335-
* Tests MaskResult JSON parsing with valid mask command response.
336-
* Verifies that well-formed mask JSON is correctly parsed into MaskResult objects.
337-
*/
338-
@Test
339-
@DisplayName("Valid mask JSON response parsing creates correct MaskResult")
340-
void testMaskResultJsonParsing() {
341-
String json = "{" +
342-
"\"maskedSecrets\":[" +
343-
"{\"masked\":\"****\",\"secret\":\"password123\",\"line\":5}," +
344-
"{\"masked\":\"***\",\"secret\":\"key\",\"line\":10}" +
345-
"]," +
346-
"\"maskedFile\":\"const password = '****';\\nconst apiKey = '***';\"" +
347-
"}";
348-
349-
MaskResult result = MaskResult.fromJsonString(json);
350-
351-
assertNotNull(result, "MaskResult should not be null");
352-
assertEquals(2, result.getMaskedSecrets().size(), "Should parse 2 masked secrets");
353-
354-
MaskedSecret firstSecret = result.getMaskedSecrets().get(0);
355-
assertEquals("****", firstSecret.getMasked());
356-
assertEquals("password123", firstSecret.getSecret());
357-
assertEquals(5, firstSecret.getLine());
358-
359-
MaskedSecret secondSecret = result.getMaskedSecrets().get(1);
360-
assertEquals("***", secondSecret.getMasked());
361-
assertEquals("key", secondSecret.getSecret());
362-
assertEquals(10, secondSecret.getLine());
363-
364-
assertTrue(result.getMaskedFile().contains("const password = '****'"));
365-
assertTrue(result.getMaskedFile().contains("const apiKey = '***'"));
366-
}
367-
368-
/**
369-
* Tests MaskResult parsing robustness with edge cases.
370-
* Verifies that the parser gracefully handles various invalid input scenarios.
371-
*/
372-
@Test
373-
@DisplayName("MaskResult handles malformed JSON and edge cases gracefully")
374-
void testMaskResultEdgeCases() {
375-
// Blank/null inputs
376-
assertNull(MaskResult.fromJsonString(""));
377-
assertNull(MaskResult.fromJsonString(" "));
378-
assertNull(MaskResult.fromJsonString(null));
379-
380-
// Invalid JSON structures
381-
assertNull(MaskResult.fromJsonString("{"));
382-
assertNull(MaskResult.fromJsonString("not a json"));
383-
384-
// Empty but valid JSON
385-
MaskResult emptyResult = MaskResult.fromJsonString("{}");
386-
assertNotNull(emptyResult);
387-
assertTrue(emptyResult.getMaskedSecrets().isEmpty());
388-
assertNotNull(emptyResult.getMaskedFile());
389-
}
390207

391208
/* ------------------------------------------------------ */
392209
/* Unit tests for JSON parsing robustness */

src/test/resources/secrets-test.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)