-
Notifications
You must be signed in to change notification settings - Fork 12
Implement SHA256 authentication for Fronius firmware 1.38.6-1+ #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
996797c
Initial plan
Copilot 9af9356
Implement MD5 to SHA256 authentication for Fronius firmware 1.38.6-1+
Copilot e0e86ff
Fronius: align version-config usage
MaStr fac4df8
Increase Debugging, fixe Whitespace issues
MaStr 8ed7f18
Fronius: use strong cnonce
MaStr b178030
fronius, remove whitespace
MaStr ca981ce
Fronius: implement support for multiple password hash methods in auth…
MaStr 2c229ef
Fronius: enhance password hash method handling during login attempts
MaStr 9d2a86f
Remove unnecessary line in src/batcontrol/inverter/fronius.py
MaStr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| """Tests for Fronius inverter authentication functionality.""" | ||
| import unittest | ||
| import hashlib | ||
| from packaging import version | ||
|
|
||
| from batcontrol.inverter.fronius import hash_utf8, get_api_config, FroniusApiConfig | ||
|
|
||
|
|
||
| class TestFroniusAuthentication(unittest.TestCase): | ||
| """Test authentication algorithm selection based on firmware version.""" | ||
|
|
||
| def test_hash_utf8_md5_default(self): | ||
| """Test that hash_utf8 defaults to MD5.""" | ||
| test_string = "test_string" | ||
| result = hash_utf8(test_string) | ||
| expected = hashlib.md5(test_string.encode('utf-8')).hexdigest() | ||
| self.assertEqual(result, expected) | ||
|
|
||
| def test_hash_utf8_md5_explicit(self): | ||
| """Test hash_utf8 with explicit MD5 algorithm.""" | ||
| test_string = "test_string" | ||
| result = hash_utf8(test_string, "MD5") | ||
| expected = hashlib.md5(test_string.encode('utf-8')).hexdigest() | ||
| self.assertEqual(result, expected) | ||
|
|
||
| def test_hash_utf8_sha256(self): | ||
| """Test hash_utf8 with SHA256 algorithm.""" | ||
| test_string = "test_string" | ||
| result = hash_utf8(test_string, "SHA256") | ||
| expected = hashlib.sha256(test_string.encode('utf-8')).hexdigest() | ||
| self.assertEqual(result, expected) | ||
|
|
||
| def test_hash_utf8_case_insensitive(self): | ||
| """Test that algorithm parameter is case insensitive.""" | ||
| test_string = "test_string" | ||
| result_upper = hash_utf8(test_string, "SHA256") | ||
| result_lower = hash_utf8(test_string, "sha256") | ||
| result_mixed = hash_utf8(test_string, "Sha256") | ||
| self.assertEqual(result_upper, result_lower) | ||
| self.assertEqual(result_upper, result_mixed) | ||
|
|
||
| def test_api_config_version_before_1_38_6_1_uses_md5(self): | ||
| """Test that firmware versions before 1.38.6-1 use MD5.""" | ||
| test_versions = ["1.35.0", "1.36.0", "1.37.0", "1.38.5"] | ||
| for v in test_versions: | ||
| with self.subTest(version=v): | ||
| parsed_version = version.parse(v) | ||
| config = get_api_config(parsed_version) | ||
| self.assertEqual(config.auth_algorithm, "MD5") | ||
|
|
||
| def test_api_config_version_1_38_6_1_and_later_uses_sha256(self): | ||
| """Test that firmware version 1.38.6-1 and later use SHA256.""" | ||
| test_versions = ["1.38.6-1", "1.38.7", "1.39.0", "2.0.0"] | ||
| for v in test_versions: | ||
| with self.subTest(version=v): | ||
| parsed_version = version.parse(v) | ||
| config = get_api_config(parsed_version) | ||
| self.assertEqual(config.auth_algorithm, "SHA256") | ||
|
|
||
| def test_api_config_boundary_version(self): | ||
| """Test the exact boundary version 1.38.6-1.""" | ||
| # Version just before the boundary should use MD5 | ||
| version_before = version.parse("1.38.5") | ||
| config_before = get_api_config(version_before) | ||
| self.assertEqual(config_before.auth_algorithm, "MD5") | ||
|
|
||
| # The boundary version should use SHA256 | ||
| boundary_version = version.parse("1.38.6-1") | ||
| config_boundary = get_api_config(boundary_version) | ||
| self.assertEqual(config_boundary.auth_algorithm, "SHA256") | ||
|
|
||
| def test_hash_utf8_with_bytes_input(self): | ||
| """Test hash_utf8 with bytes input.""" | ||
| test_bytes = b"test_bytes" | ||
| result_md5 = hash_utf8(test_bytes, "MD5") | ||
| result_sha256 = hash_utf8(test_bytes, "SHA256") | ||
|
|
||
| expected_md5 = hashlib.md5(test_bytes).hexdigest() | ||
| expected_sha256 = hashlib.sha256(test_bytes).hexdigest() | ||
|
|
||
| self.assertEqual(result_md5, expected_md5) | ||
| self.assertEqual(result_sha256, expected_sha256) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.