forked from tpitale/coap_ex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
126 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
use Mix.Config | ||
import Mix.Config | ||
|
||
import_config "#{Mix.env()}.exs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
use Mix.Config | ||
import Mix.Config | ||
|
||
config :logger, level: :info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
defmodule CoAP.SocketServerTest do | ||
use ExUnit.Case | ||
|
||
import ExUnit.CaptureLog | ||
|
||
alias CoAP.SocketServer | ||
alias CoAP.Adapters.GenericServer | ||
|
||
# @moduletag :capture_log | ||
|
||
defmodule FakeEndpoint do | ||
end | ||
|
||
describe "CoAP.SocketServer decoding errors" do | ||
test "non repeatable options" do | ||
peer_ip = "127.0.0.1" | ||
peer_port = 5830 | ||
|
||
{:ok, server} = SocketServer.start_link([{GenericServer, FakeEndpoint}, peer_port]) | ||
|
||
data = | ||
<<100, 69, 0, 1, 252, 1, 46, 56, 68, 80, 231, 168, 249, 100, 69, 0, 1, 252, 1, 46, 56, 68, | ||
80, 231, 168, 249>> | ||
|
||
log = capture_log(fn -> | ||
send(server, {:udp, :socket, peer_ip, peer_port, data}) | ||
|
||
response = | ||
receive do | ||
{:deliver, response, _peer} -> response | ||
{:error, reason} -> {:error, reason} | ||
after | ||
10 -> {:error, {:timeout, :await_response}} | ||
end | ||
|
||
assert response == {:error, {:timeout, :await_response}} | ||
end) | ||
|
||
assert log =~ "CoAP socket failed to decode udp packets" | ||
assert log =~ "is not repeatable" | ||
assert log =~ "from ip: \"#{peer_ip}\"" | ||
assert log =~ "port: #{peer_port}" | ||
assert log =~ "data: #{inspect(data, binaries: :as_binary)}" | ||
end | ||
|
||
test "CaseClauseError" do | ||
peer_ip = "127.0.0.1" | ||
peer_port = 5830 | ||
|
||
{:ok, server} = SocketServer.start_link([{GenericServer, FakeEndpoint}, peer_port]) | ||
|
||
data = | ||
<<100, 69, 0, 1, 83, 61, 239, 152, 68, 244, 81, 253, 46, 100, 69, 0, 1, 83, 61, 239, 152, 68, 244, 81, 253, 46>> | ||
|
||
log = capture_log(fn -> | ||
send(server, {:udp, :socket, peer_ip, peer_port, data}) | ||
|
||
response = | ||
receive do | ||
{:deliver, response, _peer} -> response | ||
{:error, reason} -> {:error, reason} | ||
after | ||
10 -> {:error, {:timeout, :await_response}} | ||
end | ||
|
||
assert response == {:error, {:timeout, :await_response}} | ||
end) | ||
|
||
assert log =~ "CoAP socket failed to decode udp packets" | ||
assert log =~ "CaseClauseError" | ||
assert log =~ "from ip: \"#{peer_ip}\"" | ||
assert log =~ "port: #{peer_port}" | ||
assert log =~ "data: #{inspect(data, binaries: :as_binary)}" | ||
end | ||
end | ||
end |