-
Notifications
You must be signed in to change notification settings - Fork 1
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
defaults #5
defaults #5
Conversation
Caution Review failedThe pull request is closed. WalkthroughThe changes in the Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🧹 Outside diff range and nitpick comments (1)
dot.lua (1)
794-797
: Refactor Suggestion: Centralize Argument ParsingThe options
--defaults-export
and--defaults-import
are parsed outside theparse_args
function. For consistency and maintainability, consider handling these options withinparse_args
.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
dot.lua
(4 hunks)
🔇 Additional comments (2)
dot.lua (2)
90-90
: Default Case in print_message
Function Handled Correctly
The assignment of default color
and symbol
ensures that messages with unspecified types are displayed properly.
704-706
: Integration of process_defaults
Function
The call to process_defaults
in process_module
is correctly integrated, and the dependencies_changed
flag is appropriately updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
spec/dot_spec.lua (1)
511-546
: Enhance test coverage for defaults functionality.While the test case covers the basic flow, consider adding:
- Negative test cases:
- Invalid app names
- Missing or inaccessible plist files
- Permission issues
- Cleanup of created files in the
after_each
block- Verification of error messages
it("should handle defaults export and import", function() -- Set up 'defaults_test' module with defaults configuration setup_module( "defaults_test", [[ return { defaults = { { plist = "./defaults/SwiftShift.plist", app = "com.pablopunk.SwiftShift", } } } ]] ) -- Create module directory pl_dir.makepath(pl_path.join(modules_dir, "defaults_test", "defaults")) -- Run dot.lua with --defaults-export and --mock-defaults options assert.is_true(run_dot "defaults_test --defaults-export --mock-defaults") -- Check if the plist file was created local plist_path = pl_path.join(modules_dir, "defaults_test", "defaults", "SwiftShift.plist") assert.is_true(pl_path.isfile(plist_path), "Expected plist file to be created") -- Verify the content of the plist file local content = pl_file.read(plist_path) assert.are.equal("mocked preferences", content) -- Run dot.lua with --defaults-import and --mock-defaults options assert.is_true(run_dot "defaults_test --defaults-import --mock-defaults") + + -- Negative test cases + -- Test with invalid app name + setup_module( + "defaults_test_invalid", + [[ +return { + defaults = { + { + plist = "./defaults/Invalid.plist", + app = "invalid.app.name", + } + } +} +]] + ) + assert.is_false(run_dot "defaults_test_invalid --defaults-export --mock-defaults") + + -- Test with missing plist file + setup_module( + "defaults_test_missing", + [[ +return { + defaults = { + { + plist = "./defaults/Missing.plist", + app = "com.example.app", + } + } +} +]] + ) + assert.is_false(run_dot "defaults_test_missing --defaults-import --mock-defaults") end)dot.lua (1)
117-129
: Consider improving mock defaults implementation.The current mock implementation only handles basic cases. Consider:
- Simulating error cases for testing
- Adding validation of input parameters
- Supporting different plist formats
if MOCK_DEFAULTS and cmd:match("^defaults") then if cmd:match("export") then -- Simulate exporting preferences to a file local plist_file = cmd:match('export ".-" "(.-)"') + -- Validate input parameters + if not plist_file then + return 1, "Invalid plist file path" + end local file = io.open(plist_file, "w") + if not file then + return 1, "Failed to create plist file" + end file:write("mocked preferences") file:close() return 0, "" elseif cmd:match("import") then -- Simulate importing preferences + local app = cmd:match('import "(.-)"') + if not app then + return 1, "Invalid app name" + end return 0, "" end end
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
dot.lua
(9 hunks)spec/dot_spec.lua
(1 hunks)
🔇 Additional comments (5)
dot.lua (5)
7-7
: LGTM: Command-line options for defaults management.
The new command-line options and their corresponding flags are well-structured and follow the existing pattern.
Also applies to: 17-19, 37-42, 56-58, 75-77
734-736
: LGTM: Integration with process_module function.
The integration of defaults processing with the main module processing flow is clean and consistent.
824-826
: LGTM: Mock defaults initialization.
The initialization of the mock defaults flag is consistent with other mock flags.
611-622
:
Security Issue: Command Injection in files_are_equal Function
The function constructs a shell command using unsanitized file paths.
Apply this fix to prevent command injection:
- local cmd = string.format('diff "%s" "%s"', file1, file2)
+ local cmd = string.format('diff %q %q', file1, file2)
623-703
:
Multiple Security Issues in process_defaults Function
Several instances of potential command injection vulnerabilities exist in this function.
Apply these fixes:
- Export command:
-local export_cmd = string.format('defaults export "%s" "%s"', app, tmp_file)
+local export_cmd = string.format('defaults export %q %q', app, tmp_file)
- Move commands:
-local move_cmd = string.format('mv "%s" "%s"', tmp_file, resolved_plist)
+local move_cmd = string.format('mv %q %q', tmp_file, resolved_plist)
- Import command:
-local import_cmd = string.format('defaults import "%s" "%s"', app, resolved_plist)
+local import_cmd = string.format('defaults import %q %q', app, resolved_plist)
Additionally:
- The use of
os.tmpname()
is insecure - Consider adding input validation for app names and plist paths
Summary by CodeRabbit
New Features
wget
in module'sinit.lua
.Improvements
Tests