Skip to content

Commit

Permalink
coderabbitai review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zzaakiirr committed Nov 15, 2024
1 parent bc9f66c commit a160205
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/command/terraform/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Command
module Terraform
class Base < Base
class Base < Command::Base
private

def templates
Expand Down
4 changes: 2 additions & 2 deletions lib/command/terraform/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def call
private

def run_terraform_init
result = Shell.cmd("terraform init", capture_stderr: true)
result = Shell.cmd("terraform", "init", capture_stderr: true)

if result[:success]
Shell.info(result[:output])
Expand All @@ -42,7 +42,7 @@ def run_terraform_init
end

def run_terraform_import(address, id)
result = Shell.cmd("terraform import #{address} #{id}", capture_stderr: true)
result = Shell.cmd("terraform", "import", address, id, capture_stderr: true)
Shell.info(result[:output])
end

Expand Down
26 changes: 23 additions & 3 deletions spec/command/terraform/import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
end

def stub_terraform_init_with(success, output)
allow(Shell).to receive(:cmd).with("terraform init", capture_stderr: true).and_return(
allow(Shell).to receive(:cmd).with("terraform", "init", capture_stderr: true).and_return(
success: success, output: output
)
end
Expand Down Expand Up @@ -104,9 +104,13 @@ def stub_terraform_init_with(success, output)
end

describe "#run_terraform_import" do
subject(:terraform_import) { import_command.send(:run_terraform_import, "resource_address", "resource_id") }
subject(:terraform_import) { import_command.send(:run_terraform_import, resource_address, resource_id) }

let(:resource_address) { "resource_address" }
let(:resource_id) { "resource_id" }

before do
allow(Shell).to receive(:cmd).and_call_original
allow(Shell).to receive(:info)
allow(Shell).to receive(:abort)
end
Expand Down Expand Up @@ -135,9 +139,25 @@ def stub_terraform_init_with(success, output)
end
end

context "with special characters in resource address and resource id" do
let(:resource_address) { "cpln_gvc.test-app;rm -rf /" }
let(:resource_id) { "test-app;rm -rf /" }

it "is protected from shell injection" do
terraform_import

expect(Shell).to have_received(:cmd).with(
"terraform", "import", resource_address, "test-app;rm -rf /",
capture_stderr: true
)

expect(Shell).to have_received(:info).with(/Invalid character/)
end
end

def stub_terraform_import_with(success, output)
allow(Shell).to receive(:cmd)
.with("terraform import resource_address resource_id", capture_stderr: true)
.with("terraform", "import", resource_address, resource_id, capture_stderr: true)
.and_return(success: success, output: output)
end
end
Expand Down
File renamed without changes.

0 comments on commit a160205

Please sign in to comment.