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
|
# 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
|
# 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
|
# from Mdm, the default workspace does not validate. We always validate boundaries
|
||||||
# validate boundaries of workspaces that don't use them.
|
# and a workspace may have a blank default boundary.
|
||||||
#
|
#
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def boundary_must_be_ip_range
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -20,8 +20,8 @@ RSpec.describe Mdm::Workspace, type: :model do
|
||||||
workspace.valid?
|
workspace.valid?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should validate using #valid_ip_or_range?' do
|
it 'should validate using #boundary_must_be_ip_range' do
|
||||||
expect(workspace).to receive(:valid_ip_or_range?).with(boundary).and_return(false)
|
expect(workspace).to receive(:boundary_must_be_ip_range).and_return(false)
|
||||||
|
|
||||||
workspace.valid?
|
workspace.valid?
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue