Skip to content

Conversation

@JSCU-CNI
Copy link
Contributor

This PR improves RedHat, CentOS and Fedora OS detection.

@codecov
Copy link

codecov bot commented Apr 1, 2025

Codecov Report

Attention: Patch coverage is 89.65517% with 6 lines in your changes missing coverage. Please review.

Project coverage is 79.26%. Comparing base (c8c8a1c) to head (c065510).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
dissect/target/plugins/os/unix/_os.py 90.90% 3 Missing ⚠️
dissect/target/plugins/os/unix/bsd/openbsd/_os.py 80.00% 2 Missing ⚠️
dissect/target/plugins/os/unix/locale.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1079      +/-   ##
==========================================
- Coverage   79.27%   79.26%   -0.01%     
==========================================
  Files         348      348              
  Lines       31127    31127              
==========================================
- Hits        24676    24673       -3     
- Misses       6451     6454       +3     
Flag Coverage Δ
unittests 79.26% <89.65%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JSCU-CNI JSCU-CNI requested a review from Schamper April 1, 2025 16:13
Comment on lines 159 to 158
domain = self._hosts_dict["hostname", "localhost"]
domain = self._hosts_dict.get("hostname", "localhost")
Copy link
Member

@Schamper Schamper Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, that looked like a fun bug.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because we're here anyway, could you add a unit test that would cover this scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you ask the author of this piece of code instead (iirc @Horofic)? Not sure what the original purpose is of setting domain to "localhost".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof.

I've committed some small changes in 43505c6 and added a simple test. The second parameterised test case was my original intent. Which I believe, mimicked Debian, but not 100% clear on that anymore. This case intentionally fails now, feel free to implement it or take it in the direction you believe is more correct!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the content of /etc/hosts contains 127.0.0.1 mydomain (and no /etc/hostname is found) in my opinion the parsed hostname should be mydomain. In this limited context we have no way to safely determine the difference between a hostname and domain.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very fair. I adjusts the test case in 9394c1c and added some additional test cases just to be sure. Please see if you agree with them. I also adjusted some other tests to take into account some of the localhost behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I think leaving the domain to None makes more sense instead of assuming localhost.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ill change the behaviour back later today.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in 3f6f6bb and adjusted the behaviour in 343c12a. This should do the trick now.

@JSCU-CNI JSCU-CNI requested a review from Schamper April 1, 2025 16:45
Schamper
Schamper previously approved these changes Apr 1, 2025
@JSCU-CNI JSCU-CNI requested a review from Schamper April 1, 2025 17:11
Copy link
Member

@Schamper Schamper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind taking a look at this? #1079 (comment)

@JSCU-CNI JSCU-CNI requested a review from Schamper April 2, 2025 11:03
@Schamper Schamper requested a review from Copilot April 2, 2025 12:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves OS detection for RedHat, CentOS, Fedora, OpenBSD, and FreeBSD while refactoring hostname parsing to return a tuple instead of a dictionary. Key changes include updating tests to accommodate the new hostname parsing format, adding new tests for various OS detections, and refactoring detection and parsing logic within the Unix OS plugins.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/plugins/os/unix/test__os.py Updated hostname parsing assertions to match tuple return types.
tests/plugins/os/unix/linux/redhat/test__os.py Added tests to verify detection of RedHat and related releases.
tests/plugins/os/unix/bsd/openbsd/test__os.py Added tests for OpenBSD detection.
tests/plugins/os/unix/bsd/freebsd/test__os.py Added tests for FreeBSD detection.
dissect/target/plugins/os/unix/locale.py Changed language collection from a list to a set to avoid duplicates.
dissect/target/plugins/os/unix/linux/redhat/_os.py Refactored detection signature and added future import.
dissect/target/plugins/os/unix/bsd/openbsd/_os.py Updated detection logic and refactored hostname and domain properties.
dissect/target/plugins/os/unix/bsd/freebsd/_os.py Updated detection logic using a generator for file existence checks.
dissect/target/plugins/os/unix/_os.py Refactored _parse_hostname_string to return a tuple and improved hosts parsing logic.
Comments suppressed due to low confidence (1)

dissect/target/plugins/os/unix/_os.py:189

  • [nitpick] The variable name 'callable' shadows the built-in function 'callable'. Consider renaming it (for example, to 'parser') to improve code clarity.
for path, callable in paths:

@JSCU-CNI JSCU-CNI requested a review from Horofic April 7, 2025 12:12
@Schamper Schamper merged commit ae72d52 into fox-it:main Apr 10, 2025
20 of 23 checks passed
@JSCU-CNI JSCU-CNI deleted the improvement/redhat-detection branch April 10, 2025 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants