Refactor terminal and service classes#4
Merged
Conversation
- Change `getCommandFor` to an instance method `getCommand` - Add `@NonNull` annotation to the return type of `getCommand` Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
- Rename `TerminalExecutionException` to `TerminalIOException`. - Introduce a new class `TerminalResult` to encapsulate both stdout and stderr from terminal execution. - Update `TerminalUtility` (renamed to `TerminalService`) to return `TerminalResult` instead of a raw string. - Modify the `execute` method to handle and return both stdout and stderr. It has also been made package private to reduce arbitrary command execution - Update the exception handling to throw `TerminalIOException` for I/O errors. - Add a new method `executeCommand` to `TerminalService` for executing specific DMI commands originating from the `DMIType` enum. Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
…orInformationMapper Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
- introduce `configureObjectMapper` method to allow custom ObjectMapper configuration - use `configureObjectMapper` to create `jacksonMapper` instance in `map` and `mapList` methods Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
- Replace direct instantiation of `TerminalUtility` and mappers with dependency injection of `TerminalService` and specific mappers. - Introduce package-private constructors to facilitate dependency injection. - Update `get` methods to utilize the injected `TerminalService` and mappers. - Add `Objects.requireNonNull` checks for injected dependencies to ensure non-nullability. - This change improves testability and maintainability by decoupling service classes from their dependencies, for the upcoming test rewrite Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR includes security improvements regarding arbitrary command execution in the terminal, and service refactors to improve
mocking of dependencies via injection, in tests, for the upcoming test rewrites.
Type of Change
Refactor
getCommandFor()to an instance methodgetCommand(), inDMIType.TerminalUtilitytoTerminalServiceand refactored it to become an instance based class from utility class and reduced the possibility of arbitrary command execution.TerminalServiceand mappers.DMIPortConnectionInformationMappertoDMIPortConnectorInformationMapper.configureObjectMapper()to allow custom ObjectMapper configuration inCommonDMIMapperinterface.