Do not overwrite findings_by_commits hash
What does this MR do and why?
The pre-receive secret detection CLI message should include all occurrences of leaked secrets in all files in the commit.
For example, in test.txt:2
I include a glpat
. In asdf.txt:1
I include a glrt
. I attempt to push with pre-receive secret detection enabled. The expected CLI message should include both secrets, one in each file. However, the actual behavior is that only the glrt
in asdf.txt
was shown in the CLI message. See the Screenshots section below.
The findings_by_commits
hash was being overwritten when merging the new finding hash because they share a commit id sha. When merging two hashes, entries with duplicate keys get overwritten with the values from the other hash (ruby docs: https://apidock.com/ruby/Hash/merge%21). This MR fixes the merge logic so the original findings_by_commits
hash isn't overwritten by new_findings
.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
- Check out the gitlab master branch. Make sure you have an Ultimate license. Then in rails console:
pry(main)> Gitlab::CurrentSettings.update!(pre_receive_secret_detection_enabled: true) # to ensure feature is enabled instance-wide
pry(main)> project = Project.find(PROJECT_ID)
pry(main)> Feature.enable(:pre_receive_secret_detection_push_check, project)
- Make a new local branch in the PROJECT_ID project. Create 2 new files,
test.txt
andasdf.txt
(or whatever you want) - In each file, include a secret.
- Some examples:
glpat-12312312312312312312
,glrt-12312312312312312312
,glft-12312312312312312312
- Git add both files, commit them, attempt to push. You will see a message like the "Before" screenshot above, with only 1 file and 1 secret listed.
- Check out this MR's branch, then try to push again. You will see a message the "After" screenshot above, with 2 files and 2 secrets listed.