feat/CR-2026-CSV File is taken from upload section,updates it and store the tmp path in runtime variable#126
Conversation
…ath in runtime variable
WalkthroughThis pull request introduces a new Maven project configuration for Changes
Sequence Diagram(s)sequenceDiagram
actor Tester as Test Runner
participant Action as WriteCsvFileandStorePath
participant FS as File System
participant CSV as CSVReader/CSVWriter
participant Runtime as Runtime Variable Store
Tester->>Action: execute(test data)
Action->>FS: convertToFile(path or URL)
FS-->>Action: Return file reference
Action->>CSV: Read CSV data
CSV-->>Action: Return CSV content
Action->>CSV: Update cell & write to temporary file
CSV-->>Action: Confirm write success
Action->>Runtime: Store updated file path
Action->>Tester: Return success result
Possibly related PRs
Suggested reviewers
Poem
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
csv_file_update_from_upload_section/pom.xml (2)
12-15: Consider reviewing the compiler source/target versions if a newer Java version is desired.You're currently using Java 11. This is perfectly acceptable, but if you plan to migrate in the near future, you can adjust
<maven.compiler.source>and<maven.compiler.target>accordingly.
24-47: Unify or clarify usage of JUnit and TestNG test frameworks.Your POM includes both JUnit 5 (Milestone release 5.8.0-M1) and TestNG (6.14.3). Mixing two testing frameworks can cause confusion and extra overhead. Consider choosing one framework and upgrading to its stable, more modern version to simplify maintenance.
- <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-api</artifactId> - <version>${junit.jupiter.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <version>6.14.3</version> - </dependency> + <!-- Choose either JUnit 5 or TestNG and remove the other to avoid confusion -->csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/WriteCsvFileandStorePath.java (1)
132-153: Optional file type validation and adjustable timeouts.
- File extension checks: You may want to verify the file extension if you want to strictly handle CSV only, especially for remote downloads.
- Timeout settings: The 10s read/connect timeouts could be too short or too generous depending on network conditions. Consider externalizing them as config so they are easier to modify.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
csv_file_update_from_upload_section/pom.xml(1 hunks)csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/WriteCsvFileandStorePath.java(1 hunks)csv_file_update_from_upload_section/src/main/resources/testsigma-sdk.properties(1 hunks)
🧰 Additional context used
🪛 Gitleaks (8.21.2)
csv_file_update_from_upload_section/src/main/resources/testsigma-sdk.properties
1-1: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.
(jwt)
🔇 Additional comments (3)
csv_file_update_from_upload_section/pom.xml (2)
2-9: Good project metadata definition.Your groupId, artifactId, and version are clearly defined. The initial setup appears standard and well-structured.
88-119: Build plugin configurations look correct.The Maven Shade Plugin and Source Plugin sections are properly set up to shade dependencies and attach sources. This should meet the packaging requirements for your new module.
csv_file_update_from_upload_section/src/main/java/com/testsigma/addons/web/WriteCsvFileandStorePath.java (1)
30-44: Clear parameter definitions.The
@TestDatafields are well-labeled, indicating row, column, file path, data to write, and runtime variable name. This helps maintain clarity in your test setup.
| @@ -0,0 +1 @@ | |||
| testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyMjMyMmM2Ni04NWYzLWIyN2UtN2FiOS0zM2U2M2Q4OWM1MGIiLCJ1bmlxdWVJZCI6IjQ0NTgiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiMzUifQ.atlDcaLnjdkUwsm9carKsEeRawxn9fNzRaxcn_5itgen2xFPovxDR7QlyzG_HmdlRmxHp8vmjEXH2Y-6A1xszQ No newline at end of file | |||
There was a problem hiding this comment.
Remove or mask the JWT from the public code to avoid critical security leaks.
Embedding JWTs in source code can lead to unauthorized access. Instead, store this secret in an environment variable or a secure secrets manager.
Below is a possible diff that demonstrates how to replace the inline token with an environment-based property (adjust the key name as needed):
- testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9...
+ testsigma-sdk.api.key=${TESTSIGMA_SDK_API_KEY}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyMjMyMmM2Ni04NWYzLWIyN2UtN2FiOS0zM2U2M2Q4OWM1MGIiLCJ1bmlxdWVJZCI6IjQ0NTgiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiMzUifQ.atlDcaLnjdkUwsm9carKsEeRawxn9fNzRaxcn_5itgen2xFPovxDR7QlyzG_HmdlRmxHp8vmjEXH2Y-6A1xszQ | |
| testsigma-sdk.api.key=${TESTSIGMA_SDK_API_KEY} |
🧰 Tools
🪛 Gitleaks (8.21.2)
1-1: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.
(jwt)
| public com.testsigma.sdk.Result execute() throws NoSuchElementException { | ||
| logger.info("Initiating execution"); | ||
|
|
||
| com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS; | ||
|
|
||
| String filePathString = filePath.getValue().toString(); | ||
| String replace = testData.getValue().toString(); | ||
| int targetRow = Integer.parseInt(row.getValue().toString()); | ||
| int targetColumn = Integer.parseInt(column.getValue().toString()); | ||
|
|
||
| File csvFile = null; | ||
| File tempCsvFile = null; | ||
|
|
||
| try { | ||
| csvFile = convertToFile(filePathString); | ||
| logger.info("CSV file path: " + csvFile.getAbsolutePath()); | ||
|
|
||
| if (csvFile == null || !csvFile.exists()) { | ||
| setErrorMessage("CSV File not found or could not be downloaded: " + filePathString); | ||
| return com.testsigma.sdk.Result.FAILED; | ||
| } | ||
|
|
||
| // Create a unique temp file each time | ||
| String uniqueFileName = "updated_" + System.currentTimeMillis() + ".csv"; | ||
| tempCsvFile = new File(csvFile.getParentFile(), uniqueFileName); | ||
| logger.info("Temp file path: " + tempCsvFile.getAbsolutePath()); | ||
| Files.copy(csvFile.toPath(), tempCsvFile.toPath(), StandardCopyOption.REPLACE_EXISTING); | ||
|
|
||
| CSVReader csvReader = null; | ||
| CSVWriter writer = null; | ||
| try { | ||
| csvReader = new CSVReader(new FileReader(tempCsvFile)); | ||
| List<String[]> data = csvReader.readAll(); | ||
|
|
||
| int rowIndex = targetRow - 1; | ||
| int columnIndex = targetColumn - 1; | ||
|
|
||
| while (data.size() <= rowIndex) { | ||
| data.add(new String[Math.max(columnIndex + 1, 0)]); | ||
| } | ||
| String[] targetRowData = data.get(rowIndex); | ||
| if (targetRowData.length <= columnIndex) { | ||
| String[] newRow = new String[columnIndex + 1]; | ||
| System.arraycopy(targetRowData, 0, newRow, 0, targetRowData.length); | ||
| data.set(rowIndex, newRow); | ||
| targetRowData = newRow; | ||
| } | ||
| targetRowData[columnIndex] = replace; | ||
|
|
||
| writer = new CSVWriter(new FileWriter(tempCsvFile)); | ||
| writer.writeAll(data); | ||
| writer.flush(); | ||
| } finally { | ||
| if (csvReader != null) { | ||
| try { | ||
| csvReader.close(); | ||
| } catch (IOException e) { | ||
| logger.warn("Error closing CSVReader: " + e.getMessage() + e); | ||
| } | ||
| } | ||
| if (writer != null) { | ||
| try { | ||
| writer.close(); | ||
| } catch (IOException e) { | ||
| logger.warn("Error closing CSVWriter: " + e.getMessage() + e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Store the path of the new updated file | ||
| runTimeData.setKey(variableName.getValue().toString()); | ||
| runTimeData.setValue(tempCsvFile.getAbsolutePath()); // Store absolute path of the new file | ||
|
|
||
| setSuccessMessage("Data is updated successfully in the CSV file. Updated data is " + replace + ". File path stored in runtime variable: " + variableName.getValue().toString() + " = " + tempCsvFile.getAbsolutePath()); | ||
| } catch (Exception e) { | ||
| result = com.testsigma.sdk.Result.FAILED; | ||
| setErrorMessage("Operation Failed: " + e.getMessage()); | ||
| logger.warn("Error during CSV processing: " + e.getMessage() + e); | ||
| } | ||
|
|
||
| return result; |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Validate row/column inputs and consider large CSV read performance.
- Boundary checks: Ensure
rowandcolumnare positive, or handle negative or zero values with clear error messages. - Memory usage:
csvReader.readAll()loads the entire CSV into memory, which can be problematic for large files. Consider streaming or incremental reading if large files are common. - Resource handling: Switching to try-with-resources for CSVReader and CSVWriter can simplify cleanup and reduce error-prone boilerplate.
try (CSVReader csvReader = new CSVReader(new FileReader(tempCsvFile));
CSVWriter writer = new CSVWriter(new FileWriter(tempCsvFile))) {
- List<String[]> data = csvReader.readAll();
+ // Example boundary checks
+ if (targetRow <= 0 || targetColumn <= 0) {
+ setErrorMessage("Row and Column must be positive integers.");
+ return com.testsigma.sdk.Result.FAILED;
+ }
List<String[]> data = csvReader.readAll();
// ... proceed with updates
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public com.testsigma.sdk.Result execute() throws NoSuchElementException { | |
| logger.info("Initiating execution"); | |
| com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS; | |
| String filePathString = filePath.getValue().toString(); | |
| String replace = testData.getValue().toString(); | |
| int targetRow = Integer.parseInt(row.getValue().toString()); | |
| int targetColumn = Integer.parseInt(column.getValue().toString()); | |
| File csvFile = null; | |
| File tempCsvFile = null; | |
| try { | |
| csvFile = convertToFile(filePathString); | |
| logger.info("CSV file path: " + csvFile.getAbsolutePath()); | |
| if (csvFile == null || !csvFile.exists()) { | |
| setErrorMessage("CSV File not found or could not be downloaded: " + filePathString); | |
| return com.testsigma.sdk.Result.FAILED; | |
| } | |
| // Create a unique temp file each time | |
| String uniqueFileName = "updated_" + System.currentTimeMillis() + ".csv"; | |
| tempCsvFile = new File(csvFile.getParentFile(), uniqueFileName); | |
| logger.info("Temp file path: " + tempCsvFile.getAbsolutePath()); | |
| Files.copy(csvFile.toPath(), tempCsvFile.toPath(), StandardCopyOption.REPLACE_EXISTING); | |
| CSVReader csvReader = null; | |
| CSVWriter writer = null; | |
| try { | |
| csvReader = new CSVReader(new FileReader(tempCsvFile)); | |
| List<String[]> data = csvReader.readAll(); | |
| int rowIndex = targetRow - 1; | |
| int columnIndex = targetColumn - 1; | |
| while (data.size() <= rowIndex) { | |
| data.add(new String[Math.max(columnIndex + 1, 0)]); | |
| } | |
| String[] targetRowData = data.get(rowIndex); | |
| if (targetRowData.length <= columnIndex) { | |
| String[] newRow = new String[columnIndex + 1]; | |
| System.arraycopy(targetRowData, 0, newRow, 0, targetRowData.length); | |
| data.set(rowIndex, newRow); | |
| targetRowData = newRow; | |
| } | |
| targetRowData[columnIndex] = replace; | |
| writer = new CSVWriter(new FileWriter(tempCsvFile)); | |
| writer.writeAll(data); | |
| writer.flush(); | |
| } finally { | |
| if (csvReader != null) { | |
| try { | |
| csvReader.close(); | |
| } catch (IOException e) { | |
| logger.warn("Error closing CSVReader: " + e.getMessage() + e); | |
| } | |
| } | |
| if (writer != null) { | |
| try { | |
| writer.close(); | |
| } catch (IOException e) { | |
| logger.warn("Error closing CSVWriter: " + e.getMessage() + e); | |
| } | |
| } | |
| } | |
| // Store the path of the new updated file | |
| runTimeData.setKey(variableName.getValue().toString()); | |
| runTimeData.setValue(tempCsvFile.getAbsolutePath()); // Store absolute path of the new file | |
| setSuccessMessage("Data is updated successfully in the CSV file. Updated data is " + replace + ". File path stored in runtime variable: " + variableName.getValue().toString() + " = " + tempCsvFile.getAbsolutePath()); | |
| } catch (Exception e) { | |
| result = com.testsigma.sdk.Result.FAILED; | |
| setErrorMessage("Operation Failed: " + e.getMessage()); | |
| logger.warn("Error during CSV processing: " + e.getMessage() + e); | |
| } | |
| return result; | |
| public com.testsigma.sdk.Result execute() throws NoSuchElementException { | |
| logger.info("Initiating execution"); | |
| com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS; | |
| String filePathString = filePath.getValue().toString(); | |
| String replace = testData.getValue().toString(); | |
| int targetRow = Integer.parseInt(row.getValue().toString()); | |
| int targetColumn = Integer.parseInt(column.getValue().toString()); | |
| File csvFile = null; | |
| File tempCsvFile = null; | |
| try { | |
| csvFile = convertToFile(filePathString); | |
| logger.info("CSV file path: " + csvFile.getAbsolutePath()); | |
| if (csvFile == null || !csvFile.exists()) { | |
| setErrorMessage("CSV File not found or could not be downloaded: " + filePathString); | |
| return com.testsigma.sdk.Result.FAILED; | |
| } | |
| // Create a unique temp file each time | |
| String uniqueFileName = "updated_" + System.currentTimeMillis() + ".csv"; | |
| tempCsvFile = new File(csvFile.getParentFile(), uniqueFileName); | |
| logger.info("Temp file path: " + tempCsvFile.getAbsolutePath()); | |
| Files.copy(csvFile.toPath(), tempCsvFile.toPath(), StandardCopyOption.REPLACE_EXISTING); | |
| try (CSVReader csvReader = new CSVReader(new FileReader(tempCsvFile)); | |
| CSVWriter writer = new CSVWriter(new FileWriter(tempCsvFile))) { | |
| // Example boundary checks | |
| if (targetRow <= 0 || targetColumn <= 0) { | |
| setErrorMessage("Row and Column must be positive integers."); | |
| return com.testsigma.sdk.Result.FAILED; | |
| } | |
| List<String[]> data = csvReader.readAll(); | |
| int rowIndex = targetRow - 1; | |
| int columnIndex = targetColumn - 1; | |
| while (data.size() <= rowIndex) { | |
| data.add(new String[Math.max(columnIndex + 1, 0)]); | |
| } | |
| String[] targetRowData = data.get(rowIndex); | |
| if (targetRowData.length <= columnIndex) { | |
| String[] newRow = new String[columnIndex + 1]; | |
| System.arraycopy(targetRowData, 0, newRow, 0, targetRowData.length); | |
| data.set(rowIndex, newRow); | |
| targetRowData = newRow; | |
| } | |
| targetRowData[columnIndex] = replace; | |
| writer.writeAll(data); | |
| writer.flush(); | |
| } | |
| // Store the path of the new updated file | |
| runTimeData.setKey(variableName.getValue().toString()); | |
| runTimeData.setValue(tempCsvFile.getAbsolutePath()); // Store absolute path of the new file | |
| setSuccessMessage("Data is updated successfully in the CSV file. Updated data is " + replace + ". File path stored in runtime variable: " + variableName.getValue().toString() + " = " + tempCsvFile.getAbsolutePath()); | |
| } catch (Exception e) { | |
| result = com.testsigma.sdk.Result.FAILED; | |
| setErrorMessage("Operation Failed: " + e.getMessage()); | |
| logger.warn("Error during CSV processing: " + e.getMessage() + e); | |
| } | |
| return result; | |
| } |
JIRA
https://testsigma.atlassian.net/browse/CR-2026
Fix
CSV File is taken from upload section, updates it and store the tmp path in runtime variable.
Summary by CodeRabbit
New Features
Chores