Skip to content

Commit 68b734e

Browse files
authored
Refactor TURN server tests and logs. Bump version to 0.8.1 (#60)
1 parent 89de0c2 commit 68b734e

File tree

4 files changed

+60
-38
lines changed

4 files changed

+60
-38
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ as WebRTC multiplexes traffic on a single socket but PRs are welcomed
3030
```elixir
3131
def deps do
3232
[
33-
{:ex_ice, "~> 0.8.0"}
33+
{:ex_ice, "~> 0.8.1"}
3434
]
3535
end
3636
```

lib/ex_ice/priv/ice_agent.ex

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -879,9 +879,13 @@ defmodule ExICE.Priv.ICEAgent do
879879
{t_id, t}
880880
else
881881
{false, client, sock_ip} ->
882-
Logger.warning(
883-
"Client's IP family doesn't match the socket's IP family (Client IP: #{inspect(client.turn_ip)} vs Socket IP: #{inspect(sock_ip)}). Ignoring."
884-
)
882+
Logger.debug("""
883+
TURN's IP family doesn't match socket's IP family.
884+
TURN: #{inspect(turn_server)}.
885+
TURN IP: #{inspect(client.turn_ip)}.
886+
Socket IP: #{inspect(sock_ip)}.
887+
Ignoring.
888+
""")
885889

886890
{nil, nil}
887891

@@ -2065,7 +2069,7 @@ defmodule ExICE.Priv.ICEAgent do
20652069
|> Map.put(:url, url)
20662070

20672071
:error ->
2068-
Logger.warning("Couldn't parse URL: #{inspect(ice_server.url)}. Ignoring.")
2072+
Logger.warning("Couldn't parse URL: #{inspect(url)}. Ignoring.")
20692073
nil
20702074
end
20712075
end)

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule ExICE.MixProject do
22
use Mix.Project
33

4-
@version "0.8.0"
4+
@version "0.8.1"
55
@source_url "https://github.com/elixir-webrtc/ex_ice"
66

77
def project do

test/priv/ice_agent_test.exs

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ defmodule ExICE.Priv.ICEAgentTest do
2121
end
2222
end
2323

24+
defmodule IfDiscovery.IPV6.Mock do
25+
@behaviour ExICE.Priv.IfDiscovery
26+
27+
@impl true
28+
def getifaddrs() do
29+
ifs = [{~c"mockif", [{:flags, [:up, :running]}, {:addr, {64_512, 0, 0, 0, 0, 0, 0, 1}}]}]
30+
{:ok, ifs}
31+
end
32+
end
33+
2434
defmodule Candidate.Mock do
2535
@moduledoc false
2636
@behaviour ExICE.Priv.Candidate
@@ -68,38 +78,6 @@ defmodule ExICE.Priv.ICEAgentTest do
6878
end
6979
end
7080

71-
describe "gather_candidates/1" do
72-
setup do
73-
ice_agent =
74-
ICEAgent.new(
75-
gathering_state: :new,
76-
ice_transport_policy: :all,
77-
controlling_process: self(),
78-
role: :controlling,
79-
if_discovery_module: IfDiscovery.Mock,
80-
transport_module: Transport.Mock
81-
)
82-
83-
%{ice_agent: ice_agent}
84-
end
85-
86-
test ~c"Agent with invalid TURN server url doesn't raise an exception", %{
87-
ice_agent: ice_agent
88-
} do
89-
assert %ICEAgent{gathering_state: :complete} =
90-
ICEAgent.gather_candidates(%{
91-
ice_agent
92-
| turn_servers: [
93-
%{
94-
url: "invalid.turn.url",
95-
username: "user",
96-
credential: "pass"
97-
}
98-
]
99-
})
100-
end
101-
end
102-
10381
describe "add_remote_candidate/2" do
10482
setup do
10583
ice_agent =
@@ -1550,6 +1528,46 @@ defmodule ExICE.Priv.ICEAgentTest do
15501528
# assert gathering transaction failed
15511529
assert ice_agent.gathering_transactions == %{}
15521530
end
1531+
1532+
test "invalid TURN URL" do
1533+
ice_agent =
1534+
ICEAgent.new(
1535+
controlling_process: self(),
1536+
role: :controlling,
1537+
transport_module: Transport.Mock,
1538+
if_discovery_module: IfDiscovery.Mock,
1539+
ice_servers: [
1540+
%{
1541+
urls: "turn:invalid.turn.url:#{@turn_port}?transport=udp",
1542+
username: @turn_username,
1543+
credential: @turn_password
1544+
}
1545+
]
1546+
)
1547+
|> ICEAgent.set_remote_credentials("someufrag", "somepwd")
1548+
1549+
assert %ICEAgent{gathering_state: :complete} = ICEAgent.gather_candidates(ice_agent)
1550+
end
1551+
1552+
test "non-matching IP families" do
1553+
ice_agent =
1554+
ICEAgent.new(
1555+
controlling_process: self(),
1556+
role: :controlling,
1557+
transport_module: Transport.Mock,
1558+
if_discovery_module: IfDiscovery.IPV6.Mock,
1559+
ice_servers: [
1560+
%{
1561+
urls: "turn:#{@turn_ip_str}:#{@turn_port}?transport=udp",
1562+
username: @turn_username,
1563+
credential: @turn_password
1564+
}
1565+
]
1566+
)
1567+
|> ICEAgent.set_remote_credentials("someufrag", "somepwd")
1568+
1569+
assert %ICEAgent{gathering_state: :complete} = ICEAgent.gather_candidates(ice_agent)
1570+
end
15531571
end
15541572

15551573
test "relay ice_transport_policy" do

0 commit comments

Comments
 (0)