Repository: oscal-compass/compliance-trestle (python)

Issue:
` _CsvMgr.get_rule_key() ` is supplied with incorrect argument
## Describe the bug

<img width="904" alt="image" src="https://github.com/oscal-compass/compliance-trestle/assets/78010183/a7126df8-fcba-4b15-820f-c555101a60f7">
The above code snippet is from `csv-to-oscal-cd.py`.  The highlighted portion has a potential bug. The `get_rule_key()` expects `component_title`, but `component_description` is passed in. But, this error somehow doesn't generate any serious bug whether when  `component_title` has the same value as `component_description`(in the majority cases) or when they are different. However, the expected key is not in the `_csv_rules_map` dict.

## To Reproduce

Steps to reproduce the behavior:
1. Refer to the below test case:

```
def test_execute_different_component_title_and_description(tmp_path: pathlib.Path) -> None:
    """Test execute missing value."""
    _, section = _get_config_section_init(tmp_path, 'test-csv-to-oscal-cd.config')
    # inject error
    rows = _get_rows('tests/data/csv/ocp4-user.v2.csv')
    row = rows[2]
    assert row[7] == 'OSCO'
    assert row[8] == 'OSCO'
    row[8] = 'IAM'
    assert row[8] == 'IAM'
    component_title = row[7]
    component_description = row[8]
    component_type = row[5]
    rule_id = row[1]
    with mock.patch('trestle.tasks.csv_to_oscal_cd.csv.reader') as mock_csv_reader:
        mock_csv_reader.return_value = rows
        expected_key = (component_title, component_type, rule_id)
        wrong_key = (component_description, component_type, rule_id)
        tgt = csv_to_oscal_cd.CsvToOscalComponentDefinition(section)
        retval = tgt.execute()
        assert retval == TaskOutcome.SUCCESS
        assert wrong_key in tgt._csv_mgr.get_rule_keys()
        assert expected_key in tgt._csv_mgr.get_rule_keys()
```

## Expected behavior

A clear and concise description of what you expected to happen.

## Screenshots / Logs.

If applicable, add screenshots to help explain your problem.

## Environment

- OS: \[e.g. iOS\]
- Python version:
- Installed packages:


Pull request:
fix: correct the argument for get_rule_key in csv_to_oscal_cd.py
## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

- [ ] Hot fix (emergency fix and release)
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Documentation (change which affects the documentation site)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Release (`develop` -> `main`)

## Quality assurance (all should be covered).

- [x] My code follows the code style of this project.
- [x] Documentation for my change is up to date?
- [x] My PR meets testing requirements.
- [x] All new and existing tests passed.
- [x] All commits are signed-off.

## Summary

## Key links:

Resolved #1576

# Before you merge

- Ensure it is a 'squash commit' if not a release.
- Ensure CI is currently passing
- Check sonar. If you are working for a fork a maintainer will reach out, if required.


Patch:
diff --git a/trestle/tasks/csv_to_oscal_cd.py b/trestle/tasks/csv_to_oscal_cd.py
index 455b6131..367359ca 100644
--- a/trestle/tasks/csv_to_oscal_cd.py
+++ b/trestle/tasks/csv_to_oscal_cd.py
@@ -1545,7 +1545,7 @@ class _CsvMgr():
             component_description = self.get_row_value(row, f'{COMPONENT_DESCRIPTION}')
             rule_id = self.get_row_value(row, f'{RULE_ID}')
             # rule sets
-            key = _CsvMgr.get_rule_key(component_description, component_type, rule_id)
+            key = _CsvMgr.get_rule_key(component_title, component_type, rule_id)
             if key in self._csv_rules_map:
                 text = f'row "{row_num}" contains duplicate {RULE_ID} "{rule_id}"'
                 raise RuntimeError(text)


Test patch:
diff --git a/tests/trestle/tasks/csv_to_oscal_cd_test.py b/tests/trestle/tasks/csv_to_oscal_cd_test.py
index e1d075ec..e2ebc1fa 100644
--- a/tests/trestle/tasks/csv_to_oscal_cd_test.py
+++ b/tests/trestle/tasks/csv_to_oscal_cd_test.py
@@ -885,6 +885,34 @@ def test_execute_param_duplicate_value(tmp_path: pathlib.Path) -> None:
         assert retval == TaskOutcome.FAILURE
 
 
+def test_execute_correct_rule_key(tmp_path: pathlib.Path) -> None:
+    """Test execute missing value."""
+    _, section = _get_config_section_init(tmp_path, 'test-csv-to-oscal-cd.config')
+    rows = _get_rows('tests/data/csv/ocp4-user.v2.csv')
+    row = rows[2]
+    # ensure component_title and component_description are different
+    assert row[7] == 'OSCO'
+    assert row[8] == 'OSCO'
+    row[8] = 'IAM'
+    assert row[8] == 'IAM'
+    component_title = row[7]
+    component_description = row[8]
+    component_type = row[5]
+    rule_id = row[1]
+    with mock.patch('trestle.tasks.csv_to_oscal_cd.csv.reader') as mock_csv_reader:
+        mock_csv_reader.return_value = rows
+        # perform transformation
+        tgt = csv_to_oscal_cd.CsvToOscalComponentDefinition(section)
+        retval = tgt.execute()
+        assert retval == TaskOutcome.SUCCESS
+        # insure expected key exists
+        expected_key = (component_title, component_type, rule_id)
+        assert expected_key in tgt._csv_mgr.get_rule_keys()
+        # insure unexpected key does not exist
+        unexpected_key = (component_description, component_type, rule_id)
+        assert unexpected_key not in tgt._csv_mgr.get_rule_keys()
+
+
 def test_execute_missing_param_default_value(tmp_path: pathlib.Path) -> None:
     """Test execute missing param default_value."""
     _, section = _get_config_section_init(tmp_path, 'test-csv-to-oscal-cd-bp.config')