Skip to content

Commit

Permalink
Fixes #38051 - Fix built request to accept ipv6 hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
ShimShtein committed Dec 1, 2024
1 parent afc6ac3 commit 9ebe07b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/controllers/unattended_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,16 @@ def update_ip
logger.debug "Built notice from #{ip}, current host ip is #{@host.ip}, updating" if @host.ip != ip

# @host has been changed even if the save fails, so we have to change it back
old_ip = @host.ip
@host.ip = old_ip unless @host.update({'ip' => ip})
address = IPAddr.new(ip)
if address.ipv4?
old_ip = @host.ip
@host.ip = old_ip unless @host.update({'ip' => ip})
end

if address.ipv6?
old_ip = @host.ip6
@host.ip6 = old_ip unless @host.update({'ip6' => ip})
end
end

def ipxe_request?
Expand Down
10 changes: 10 additions & 0 deletions test/controllers/unattended_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,16 @@ class UnattendedControllerTest < ActionController::TestCase
refute nic.build
end

test "should accept built notifications over ipv6 and store the address" do
nic6 = FactoryBot.build(:nic_managed, :with_ipv6)
Setting[:update_ip_from_built_request] = true
@request.env["REMOTE_ADDR"] = nic6.ip6
post :built, params: { mac: @ub_host.primary_interface.mac }
assert_response :created
@ub_host.reload
assert_equal nic6.ip6, @ub_host.primary_interface.ip6
end

test "should accept failed notifications" do
@request.env["REMOTE_ADDR"] = @ub_host.ip
post :failed
Expand Down

0 comments on commit 9ebe07b

Please sign in to comment.