mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
fix(portal): Fix traffic filtering to send port-less rules (#4778)
This commit is contained in:
@@ -35,7 +35,7 @@ defmodule API.Gateway.Views.Resource do
|
||||
}
|
||||
end
|
||||
|
||||
def render_filter(%Resources.Resource.Filter{} = filter) do
|
||||
def render_filter(%Resources.Resource.Filter{ports: ports} = filter) when length(ports) > 0 do
|
||||
Enum.map(filter.ports, fn port ->
|
||||
case String.split(port, "-") do
|
||||
[port_start, port_end] ->
|
||||
@@ -60,6 +60,14 @@ defmodule API.Gateway.Views.Resource do
|
||||
end)
|
||||
end
|
||||
|
||||
def render_filter(%Resources.Resource.Filter{} = filter) do
|
||||
[
|
||||
%{
|
||||
protocol: filter.protocol
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
defp port_to_number(port) do
|
||||
port |> String.trim() |> String.to_integer()
|
||||
end
|
||||
|
||||
@@ -110,7 +110,8 @@ defmodule API.Gateway.ChannelTest do
|
||||
filters: [
|
||||
%{protocol: :tcp, port_range_end: 80, port_range_start: 80},
|
||||
%{protocol: :tcp, port_range_end: 433, port_range_start: 433},
|
||||
%{protocol: :udp, port_range_start: 100, port_range_end: 200}
|
||||
%{protocol: :udp, port_range_start: 100, port_range_end: 200},
|
||||
%{protocol: :icmp}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -224,7 +225,8 @@ defmodule API.Gateway.ChannelTest do
|
||||
filters: [
|
||||
%{protocol: :tcp, port_range_end: 80, port_range_start: 80},
|
||||
%{protocol: :tcp, port_range_end: 433, port_range_start: 433},
|
||||
%{protocol: :udp, port_range_start: 100, port_range_end: 200}
|
||||
%{protocol: :udp, port_range_start: 100, port_range_end: 200},
|
||||
%{protocol: :icmp}
|
||||
]
|
||||
}
|
||||
end
|
||||
@@ -301,7 +303,8 @@ defmodule API.Gateway.ChannelTest do
|
||||
filters: [
|
||||
%{protocol: :tcp, port_range_end: 80, port_range_start: 80},
|
||||
%{protocol: :tcp, port_range_end: 433, port_range_start: 433},
|
||||
%{protocol: :udp, port_range_start: 100, port_range_end: 200}
|
||||
%{protocol: :udp, port_range_start: 100, port_range_end: 200},
|
||||
%{protocol: :icmp}
|
||||
]
|
||||
}
|
||||
end
|
||||
@@ -435,7 +438,8 @@ defmodule API.Gateway.ChannelTest do
|
||||
filters: [
|
||||
%{protocol: :tcp, port_range_end: 80, port_range_start: 80},
|
||||
%{protocol: :tcp, port_range_end: 433, port_range_start: 433},
|
||||
%{protocol: :udp, port_range_start: 100, port_range_end: 200}
|
||||
%{protocol: :udp, port_range_start: 100, port_range_end: 200},
|
||||
%{protocol: :icmp}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -549,7 +553,8 @@ defmodule API.Gateway.ChannelTest do
|
||||
filters: [
|
||||
%{protocol: :tcp, port_range_end: 80, port_range_start: 80},
|
||||
%{protocol: :tcp, port_range_end: 433, port_range_start: 433},
|
||||
%{protocol: :udp, port_range_start: 100, port_range_end: 200}
|
||||
%{protocol: :udp, port_range_start: 100, port_range_end: 200},
|
||||
%{protocol: :icmp}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -741,7 +746,8 @@ defmodule API.Gateway.ChannelTest do
|
||||
filters: [
|
||||
%{protocol: :tcp, port_range_end: 80, port_range_start: 80},
|
||||
%{protocol: :tcp, port_range_end: 433, port_range_start: 433},
|
||||
%{protocol: :udp, port_range_start: 100, port_range_end: 200}
|
||||
%{protocol: :udp, port_range_start: 100, port_range_end: 200},
|
||||
%{protocol: :icmp}
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
@@ -1002,7 +1002,8 @@ defmodule Domain.ResourcesTest do
|
||||
|
||||
assert [
|
||||
%Domain.Resources.Resource.Filter{ports: ["80", "433"], protocol: :tcp},
|
||||
%Domain.Resources.Resource.Filter{ports: ["100 - 200"], protocol: :udp}
|
||||
%Domain.Resources.Resource.Filter{ports: ["100 - 200"], protocol: :udp},
|
||||
%Domain.Resources.Resource.Filter{protocol: :icmp}
|
||||
] = resource.filters
|
||||
end
|
||||
|
||||
@@ -1042,7 +1043,8 @@ defmodule Domain.ResourcesTest do
|
||||
|
||||
assert [
|
||||
%Domain.Resources.Resource.Filter{ports: ["80", "433"], protocol: :tcp},
|
||||
%Domain.Resources.Resource.Filter{ports: ["100 - 200"], protocol: :udp}
|
||||
%Domain.Resources.Resource.Filter{ports: ["100 - 200"], protocol: :udp},
|
||||
%Domain.Resources.Resource.Filter{protocol: :icmp}
|
||||
] = resource.filters
|
||||
|
||||
assert Repo.aggregate(Domain.Network.Address, :count) == address_count
|
||||
|
||||
@@ -12,7 +12,8 @@ defmodule Domain.Fixtures.Resources do
|
||||
type: :dns,
|
||||
filters: [
|
||||
%{protocol: :tcp, ports: [80, 433]},
|
||||
%{protocol: :udp, ports: [100..200]}
|
||||
%{protocol: :udp, ports: [100..200]},
|
||||
%{protocol: :icmp}
|
||||
]
|
||||
})
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user