parent
8de58e4b80
commit
f5415c8058
|
@ -38,12 +38,24 @@ module Mdm::Workspace::BoundaryRange
|
|||
|
||||
# Validates that {#boundary} is {#valid_ip_or_range? a valid IP address or
|
||||
# IP address range}. Due to this not being tested before it was moved here
|
||||
# from Mdm, the default workspace does not validate. We therefore don't
|
||||
# validate boundaries of workspaces that don't use them.
|
||||
# from Mdm, the default workspace does not validate. We always validate boundaries
|
||||
# and a workspace may have a blank default boundary.
|
||||
#
|
||||
# @return [void]
|
||||
def boundary_must_be_ip_range
|
||||
errors.add(:boundary, "must be a valid IP range") unless !limit_to_network || valid_ip_or_range?(boundary)
|
||||
unless boundary.blank?
|
||||
begin
|
||||
boundaries = Shellwords.split(boundary)
|
||||
rescue ArgumentError
|
||||
boundaries = []
|
||||
end
|
||||
|
||||
boundaries.each do |range|
|
||||
unless valid_ip_or_range?(range)
|
||||
errors.add(:boundary, "must be a valid IP range")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -20,8 +20,8 @@ RSpec.describe Mdm::Workspace, type: :model do
|
|||
workspace.valid?
|
||||
end
|
||||
|
||||
it 'should validate using #valid_ip_or_range?' do
|
||||
expect(workspace).to receive(:valid_ip_or_range?).with(boundary).and_return(false)
|
||||
it 'should validate using #boundary_must_be_ip_range' do
|
||||
expect(workspace).to receive(:boundary_must_be_ip_range).and_return(false)
|
||||
|
||||
workspace.valid?
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue