Merge pull request #1098 from emqtt/develop
Update test case for http api
This commit is contained in:
commit
e444cc2d1a
|
@ -433,7 +433,7 @@ request_status(_) ->
|
||||||
end,
|
end,
|
||||||
Status = iolist_to_binary(io_lib:format("Node ~s is ~s~nemqttd is ~s",
|
Status = iolist_to_binary(io_lib:format("Node ~s is ~s~nemqttd is ~s",
|
||||||
[node(), InternalStatus, AppStatus])),
|
[node(), InternalStatus, AppStatus])),
|
||||||
Url = "http://127.0.0.1:8083/status",
|
Url = "http://127.0.0.1:8080/status",
|
||||||
{ok, {{"HTTP/1.1", 200, "OK"}, _, Return}} =
|
{ok, {{"HTTP/1.1", 200, "OK"}, _, Return}} =
|
||||||
httpc:request(get, {Url, []}, [], []),
|
httpc:request(get, {Url, []}, [], []),
|
||||||
?assertEqual(binary_to_list(Status), Return).
|
?assertEqual(binary_to_list(Status), Return).
|
||||||
|
@ -446,7 +446,7 @@ request_publish(_) ->
|
||||||
emqttd:unsubscribe(<<"a/b/c">>).
|
emqttd:unsubscribe(<<"a/b/c">>).
|
||||||
|
|
||||||
connect_emqttd_publish_(Method, Api, Params, Auth) ->
|
connect_emqttd_publish_(Method, Api, Params, Auth) ->
|
||||||
Url = "http://127.0.0.1:8083/" ++ Api,
|
Url = "http://127.0.0.1:8080/" ++ Api,
|
||||||
case httpc:request(Method, {Url, [Auth], ?CONTENT_TYPE, Params}, [], []) of
|
case httpc:request(Method, {Url, [Auth], ?CONTENT_TYPE, Params}, [], []) of
|
||||||
{error, socket_closed_remotely} ->
|
{error, socket_closed_remotely} ->
|
||||||
false;
|
false;
|
||||||
|
@ -647,8 +647,8 @@ conflict_listeners(_) ->
|
||||||
{current_clients, esockd:get_current_clients(Pid)},
|
{current_clients, esockd:get_current_clients(Pid)},
|
||||||
{shutdown_count, esockd:get_shutdown_count(Pid)}]}
|
{shutdown_count, esockd:get_shutdown_count(Pid)}]}
|
||||||
end, esockd:listeners()),
|
end, esockd:listeners()),
|
||||||
?assertEqual(1, proplists:get_value(current_clients, proplists:get_value("mqtt:tcp:1883", Listeners))),
|
?assertEqual(1, proplists:get_value(current_clients, proplists:get_value("mqtt:tcp:0.0.0.0:1883", Listeners))),
|
||||||
?assertEqual([{conflict,1}], proplists:get_value(shutdown_count, proplists:get_value("mqtt:tcp:1883", Listeners))),
|
?assertEqual([{conflict,1}], proplists:get_value(shutdown_count, proplists:get_value("mqtt:tcp:0.0.0.0:1883", Listeners))),
|
||||||
emqttc:disconnect(C2).
|
emqttc:disconnect(C2).
|
||||||
|
|
||||||
cli_vm(_) ->
|
cli_vm(_) ->
|
||||||
|
|
|
@ -54,7 +54,7 @@ node.max_ets_tables = 256000
|
||||||
node.fullsweep_after = 1000
|
node.fullsweep_after = 1000
|
||||||
|
|
||||||
## Crash dump
|
## Crash dump
|
||||||
node.crash_dump = log/crash.dump
|
node.crash_dump = {{ platform_log_dir }}/crash.dump
|
||||||
|
|
||||||
## Distributed node ticktime
|
## Distributed node ticktime
|
||||||
node.dist_net_ticktime = 60
|
node.dist_net_ticktime = 60
|
||||||
|
@ -68,7 +68,7 @@ node.dist_listen_max = 6369
|
||||||
##--------------------------------------------------------------------
|
##--------------------------------------------------------------------
|
||||||
|
|
||||||
## Set the log dir
|
## Set the log dir
|
||||||
log.dir = log
|
log.dir = {{ platform_log_dir }}
|
||||||
|
|
||||||
## Console log. Enum: off, file, console, both
|
## Console log. Enum: off, file, console, both
|
||||||
log.console = console
|
log.console = console
|
||||||
|
@ -83,15 +83,15 @@ log.syslog = on
|
||||||
log.syslog.level = error
|
log.syslog.level = error
|
||||||
|
|
||||||
## Console log file
|
## Console log file
|
||||||
## log.console.file = log/console.log
|
## log.console.file = {{ platform_log_dir }}/console.log
|
||||||
|
|
||||||
## Error log file
|
## Error log file
|
||||||
log.error.file = log/error.log
|
log.error.file = {{ platform_log_dir }}/error.log
|
||||||
|
|
||||||
## Enable the crash log. Enum: on, off
|
## Enable the crash log. Enum: on, off
|
||||||
log.crash = on
|
log.crash = on
|
||||||
|
|
||||||
log.crash.file = log/crash.log
|
log.crash.file = {{ platform_log_dir }}/crash.log
|
||||||
|
|
||||||
##--------------------------------------------------------------------
|
##--------------------------------------------------------------------
|
||||||
## Allow Anonymous and Default ACL
|
## Allow Anonymous and Default ACL
|
||||||
|
@ -104,7 +104,7 @@ mqtt.allow_anonymous = true
|
||||||
mqtt.acl_nomatch = allow
|
mqtt.acl_nomatch = allow
|
||||||
|
|
||||||
## Default ACL File
|
## Default ACL File
|
||||||
mqtt.acl_file = etc/acl.conf
|
mqtt.acl_file = {{ platform_etc_dir }}/acl.conf
|
||||||
|
|
||||||
## Cache ACL for PUBLISH
|
## Cache ACL for PUBLISH
|
||||||
mqtt.cache_acl = true
|
mqtt.cache_acl = true
|
||||||
|
@ -119,6 +119,9 @@ mqtt.max_clientid_len = 1024
|
||||||
## Max Packet Size Allowed, 64K by default.
|
## Max Packet Size Allowed, 64K by default.
|
||||||
mqtt.max_packet_size = 64KB
|
mqtt.max_packet_size = 64KB
|
||||||
|
|
||||||
|
## Check Websocket Protocol Header. Enum: on, off
|
||||||
|
mqtt.websocket_protocol_header = on
|
||||||
|
|
||||||
##--------------------------------------------------------------------
|
##--------------------------------------------------------------------
|
||||||
## MQTT Connection
|
## MQTT Connection
|
||||||
##--------------------------------------------------------------------
|
##--------------------------------------------------------------------
|
||||||
|
@ -188,7 +191,7 @@ mqtt.mqueue.type = simple
|
||||||
|
|
||||||
## Max queue length. Enqueued messages when persistent client disconnected,
|
## Max queue length. Enqueued messages when persistent client disconnected,
|
||||||
## or inflight window is full. 0 means no limit.
|
## or inflight window is full. 0 means no limit.
|
||||||
mqtt.mqueue.max_length = 0
|
mqtt.mqueue.max_length = 1000
|
||||||
|
|
||||||
## Low-water mark of queued messages
|
## Low-water mark of queued messages
|
||||||
mqtt.mqueue.low_watermark = 20%
|
mqtt.mqueue.low_watermark = 20%
|
||||||
|
@ -229,10 +232,10 @@ mqtt.bridge.ping_down_interval = 1
|
||||||
##-------------------------------------------------------------------
|
##-------------------------------------------------------------------
|
||||||
|
|
||||||
## Dir of plugins' config
|
## Dir of plugins' config
|
||||||
mqtt.plugins.etc_dir =etc/plugins/
|
mqtt.plugins.etc_dir ={{ platform_etc_dir }}/plugins/
|
||||||
|
|
||||||
## File to store loaded plugin names.
|
## File to store loaded plugin names.
|
||||||
mqtt.plugins.loaded_file = data/loaded_plugins
|
mqtt.plugins.loaded_file = {{ platform_data_dir }}/loaded_plugins
|
||||||
|
|
||||||
##--------------------------------------------------------------------
|
##--------------------------------------------------------------------
|
||||||
## MQTT Listeners
|
## MQTT Listeners
|
||||||
|
@ -354,9 +357,9 @@ listener.ssl.external.keyfile = certs/key.pem
|
||||||
|
|
||||||
listener.ssl.external.certfile = certs/cert.pem
|
listener.ssl.external.certfile = certs/cert.pem
|
||||||
|
|
||||||
## listener.ssl.external.cacertfile = certs/cacert.pem
|
## listener.ssl.external.cacertfile = {{ platform_etc_dir }}/certs/cacert.pem
|
||||||
|
|
||||||
## listener.ssl.external.dhfile = certs/dh-params.pem
|
## listener.ssl.external.dhfile = {{ platform_etc_dir }}/certs/dh-params.pem
|
||||||
|
|
||||||
## listener.ssl.external.verify = verify_peer
|
## listener.ssl.external.verify = verify_peer
|
||||||
|
|
||||||
|
@ -437,12 +440,23 @@ listener.wss.external.keyfile = certs/key.pem
|
||||||
|
|
||||||
listener.wss.external.certfile = certs/cert.pem
|
listener.wss.external.certfile = certs/cert.pem
|
||||||
|
|
||||||
## listener.wss.external.cacertfile = certs/cacert.pem
|
## listener.wss.external.cacertfile = {{ platform_etc_dir }}/certs/cacert.pem
|
||||||
|
|
||||||
## listener.wss.external.verify = verify_peer
|
## listener.wss.external.verify = verify_peer
|
||||||
|
|
||||||
## listener.wss.external.fail_if_no_peer_cert = true
|
## listener.wss.external.fail_if_no_peer_cert = true
|
||||||
|
|
||||||
|
##--------------------------------------------------------------------
|
||||||
|
## HTTP Management API Listener
|
||||||
|
|
||||||
|
listener.api.mgmt = 127.0.0.1:8080
|
||||||
|
|
||||||
|
listener.api.mgmt.acceptors = 4
|
||||||
|
|
||||||
|
listener.api.mgmt.max_clients = 64
|
||||||
|
|
||||||
|
listener.api.mgmt.access.1 = allow all
|
||||||
|
|
||||||
##-------------------------------------------------------------------
|
##-------------------------------------------------------------------
|
||||||
## System Monitor
|
## System Monitor
|
||||||
##-------------------------------------------------------------------
|
##-------------------------------------------------------------------
|
||||||
|
|
|
@ -346,6 +346,11 @@ end}.
|
||||||
{max_packet_size, cuttlefish:conf_get("mqtt.max_packet_size", Conf)}]
|
{max_packet_size, cuttlefish:conf_get("mqtt.max_packet_size", Conf)}]
|
||||||
end}.
|
end}.
|
||||||
|
|
||||||
|
{mapping, "mqtt.websocket_protocol_header", "emqttd.websocket_protocol_header", [
|
||||||
|
{default, on},
|
||||||
|
{datatype, flag}
|
||||||
|
]}.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% MQTT Connection
|
%% MQTT Connection
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -1016,15 +1021,113 @@ end}.
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
ApiListeners = fun(Type, Name) ->
|
||||||
|
Prefix = string:join(["listener", Type, Name], "."),
|
||||||
|
case cuttlefish:conf_get(Prefix, Conf, undefined) of
|
||||||
|
undefined ->
|
||||||
|
[];
|
||||||
|
ListenOn ->
|
||||||
|
SslOpts1 = case SslOpts(Prefix) of
|
||||||
|
[] -> [];
|
||||||
|
SslOpts0 -> [{sslopts, SslOpts0}]
|
||||||
|
end,
|
||||||
|
[{Atom(Type), ListenOn, [{connopts, ConnOpts(Prefix)},
|
||||||
|
{sockopts, TcpOpts(Prefix)}| LisOpts(Prefix)] ++ SslOpts1}]
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
|
||||||
lists:flatten([TcpListeners(Type, Name) || {["listener", Type, Name], ListenOn}
|
lists:flatten([TcpListeners(Type, Name) || {["listener", Type, Name], ListenOn}
|
||||||
<- cuttlefish_variable:filter_by_prefix("listener.tcp", Conf)
|
<- cuttlefish_variable:filter_by_prefix("listener.tcp", Conf)
|
||||||
++ cuttlefish_variable:filter_by_prefix("listener.ws", Conf)]
|
++ cuttlefish_variable:filter_by_prefix("listener.ws", Conf)]
|
||||||
++
|
++
|
||||||
[SslListeners(Type, Name) || {["listener", Type, Name], ListenOn}
|
[SslListeners(Type, Name) || {["listener", Type, Name], ListenOn}
|
||||||
<- cuttlefish_variable:filter_by_prefix("listener.ssl", Conf)
|
<- cuttlefish_variable:filter_by_prefix("listener.ssl", Conf)
|
||||||
++ cuttlefish_variable:filter_by_prefix("listener.wss", Conf)])
|
++ cuttlefish_variable:filter_by_prefix("listener.wss", Conf)]
|
||||||
|
++
|
||||||
|
[ApiListeners(Type, Name) || {["listener", Type, Name], ListenOn}
|
||||||
|
<- cuttlefish_variable:filter_by_prefix("listener.api", Conf)])
|
||||||
end}.
|
end}.
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% MQTT REST API Listeners
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name", "emqttd.listeners", [
|
||||||
|
{datatype, [integer, ip]}
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.acceptors", "emqttd.listeners", [
|
||||||
|
{default, 8},
|
||||||
|
{datatype, integer}
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.max_clients", "emqttd.listeners", [
|
||||||
|
{default, 1024},
|
||||||
|
{datatype, integer}
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.rate_limit", "emqttd.listeners", [
|
||||||
|
{datatype, string}
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.access.$id", "emqttd.listeners", [
|
||||||
|
{datatype, string}
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.backlog", "emqttd.listeners", [
|
||||||
|
{default, 1024},
|
||||||
|
{datatype, integer}
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.recbuf", "emqttd.listeners", [
|
||||||
|
{datatype, bytesize},
|
||||||
|
hidden
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.sndbuf", "emqttd.listeners", [
|
||||||
|
{datatype, bytesize},
|
||||||
|
hidden
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.buffer", "emqttd.listeners", [
|
||||||
|
{datatype, bytesize},
|
||||||
|
hidden
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.tune_buffer", "emqttd.listeners", [
|
||||||
|
{datatype, flag},
|
||||||
|
hidden
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.nodelay", "emqttd.listeners", [
|
||||||
|
{datatype, {enum, [true, false]}},
|
||||||
|
hidden
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.handshake_timeout", "emqttd.listeners", [
|
||||||
|
{datatype, {duration, ms}}
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.keyfile", "emqttd.listeners", [
|
||||||
|
{datatype, string}
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.certfile", "emqttd.listeners", [
|
||||||
|
{datatype, string}
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.cacertfile", "emqttd.listeners", [
|
||||||
|
{datatype, string}
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.verify", "emqttd.listeners", [
|
||||||
|
{datatype, atom}
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.api.$name.fail_if_no_peer_cert", "emqttd.listeners", [
|
||||||
|
{datatype, {enum, [true, false]}}
|
||||||
|
]}.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% System Monitor
|
%% System Monitor
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue