code format
This commit is contained in:
parent
4aed3abb5e
commit
b9220490bf
|
@ -27,12 +27,12 @@
|
||||||
-define(CONTENT_TYPE, "application/x-www-form-urlencoded").
|
-define(CONTENT_TYPE, "application/x-www-form-urlencoded").
|
||||||
|
|
||||||
-define(MQTT_SSL_MUTWAY, [{cacertfile, "certs/cacert.pem"},
|
-define(MQTT_SSL_MUTWAY, [{cacertfile, "certs/cacert.pem"},
|
||||||
{verify, verify_peer},
|
{verify, verify_peer},
|
||||||
{fail_if_no_peer_cert, true}]).
|
{fail_if_no_peer_cert, true}]).
|
||||||
|
|
||||||
-define(MQTT_SSL_CLIENT, [{keyfile, "certs/client-key.pem"},
|
-define(MQTT_SSL_CLIENT, [{keyfile, "certs/client-key.pem"},
|
||||||
{cacertfile, "certs/cacert.pem"},
|
{cacertfile, "certs/cacert.pem"},
|
||||||
{certfile, "certs/client-cert.pem"}]).
|
{certfile, "certs/client-cert.pem"}]).
|
||||||
|
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
|
@ -52,8 +52,8 @@ all() ->
|
||||||
groups() ->
|
groups() ->
|
||||||
[{protocol, [sequence],
|
[{protocol, [sequence],
|
||||||
[mqtt_connect,
|
[mqtt_connect,
|
||||||
mqtt_ssl_oneway,
|
mqtt_ssl_oneway,
|
||||||
mqtt_ssl_mutway]},
|
mqtt_ssl_twoway]},
|
||||||
{pubsub, [sequence],
|
{pubsub, [sequence],
|
||||||
[subscribe_unsubscribe,
|
[subscribe_unsubscribe,
|
||||||
publish, pubsub,
|
publish, pubsub,
|
||||||
|
@ -139,41 +139,39 @@ connect_broker_(Packet, RecvSize) ->
|
||||||
Data.
|
Data.
|
||||||
|
|
||||||
mqtt_ssl_oneway(_) ->
|
mqtt_ssl_oneway(_) ->
|
||||||
{ok, SslOneWay} = emqttc:start_link([{host, "localhost"},
|
{ok, SslOneWay} = emqttc:start_link([{host, "localhost"},
|
||||||
{port, 8883},
|
{port, 8883},
|
||||||
{client_id, <<"ssloneway">>}, ssl]),
|
{client_id, <<"ssloneway">>}, ssl]),
|
||||||
timer:sleep(100),
|
timer:sleep(100),
|
||||||
emqttc:subscribe(SslOneWay, <<"topic">>, qos1),
|
emqttc:subscribe(SslOneWay, <<"topic">>, qos1),
|
||||||
|
{ok, Pub} = emqttc:start_link([{host, "localhost"},
|
||||||
{ok, Pub} = emqttc:start_link([{host, "localhost"},
|
{client_id, <<"pub">>}]),
|
||||||
{client_id, <<"pub">>}]),
|
receive {publish, _Topic, RM} ->
|
||||||
receive {publish, _Topic, RM} ->
|
|
||||||
?assertEqual(<<"SSL oneWay test">>, RM)
|
?assertEqual(<<"SSL oneWay test">>, RM)
|
||||||
after 1000 -> false
|
after 1000 -> false
|
||||||
end,
|
end,
|
||||||
emqttc:disconnect(SslOneWay),
|
emqttc:disconnect(SslOneWay),
|
||||||
emqttc:disconnect(Pub).
|
emqttc:disconnect(Pub).
|
||||||
|
|
||||||
mqtt_ssl_mutway(Config) ->
|
mqtt_ssl_twoway(Config) ->
|
||||||
emqttd_cluster:prepare(),
|
emqttd_cluster:prepare(),
|
||||||
DataDir = proplists:get_value(data_dir, Config),
|
DataDir = proplists:get_value(data_dir, Config),
|
||||||
EmqConfig = proplists:get_value(config, Config),
|
EmqConfig = proplists:get_value(config, Config),
|
||||||
Vals = change_opts(ssl_mut, DataDir, proplists:get_value(emqttd, EmqConfig)),
|
Vals = change_opts(ssl_mut, DataDir, proplists:get_value(emqttd, EmqConfig)),
|
||||||
[application:set_env(emqttd, Par, Value) || {Par, Value} <- Vals],
|
[application:set_env(emqttd, Par, Value) || {Par, Value} <- Vals],
|
||||||
emqttd_cluster:reboot(),
|
emqttd_cluster:reboot(),
|
||||||
|
ClientSSl = [{Key, filename:join([DataDir, File])} ||
|
||||||
ClientSSl = [{Key, filename:join([DataDir, File])} ||
|
{Key, File} <- ?MQTT_SSL_CLIENT ],
|
||||||
{Key, File} <- ?MQTT_SSL_CLIENT ],
|
{ok, SslMutWay} = emqttc:start_link([{host, "localhost"},
|
||||||
{ok, SslMutWay} = emqttc:start_link([{host, "localhost"},
|
{port, 8883},
|
||||||
{port, 8883},
|
{client_id, <<"sslmut">>},
|
||||||
{client_id, <<"sslmut">>},
|
{ssl, ClientSSl}]),
|
||||||
{ssl, ClientSSl}]),
|
{ok, Sub} = emqttc:start_link([{host, "localhost"},
|
||||||
{ok, Sub} = emqttc:start_link([{host, "localhost"},
|
{client_id, <<"sub">>}]),
|
||||||
{client_id, <<"sub">>}]),
|
|
||||||
emqttc:subscribe(Sub, <<"topic">>, qos1),
|
emqttc:subscribe(Sub, <<"topic">>, qos1),
|
||||||
emqttc:publish(SslMutWay, <<"topic">>, <<"ssl client pub message">>, [{qos, 1}]),
|
emqttc:publish(SslMutWay, <<"topic">>, <<"ssl client pub message">>, [{qos, 1}]),
|
||||||
timer:sleep(10),
|
timer:sleep(10),
|
||||||
receive {publish, _Topic, RM} ->
|
receive {publish, _Topic, RM} ->
|
||||||
?assertEqual(<<"ssl client pub message">>, RM)
|
?assertEqual(<<"ssl client pub message">>, RM)
|
||||||
after 1000 -> false
|
after 1000 -> false
|
||||||
end,
|
end,
|
||||||
|
@ -643,34 +641,36 @@ slave(emqttd, Node) ->
|
||||||
slave(node, Node) ->
|
slave(node, Node) ->
|
||||||
{ok, N} = slave:start(host(), Node, "-pa ../../ebin -pa ../../deps/*/ebin"),
|
{ok, N} = slave:start(host(), Node, "-pa ../../ebin -pa ../../deps/*/ebin"),
|
||||||
N.
|
N.
|
||||||
|
|
||||||
emqttd_config(DataDir) ->
|
emqttd_config(DataDir) ->
|
||||||
Schema = cuttlefish_schema:files([filename:join([DataDir, "emqttd.schema"])]),
|
Schema = cuttlefish_schema:files([filename:join([DataDir, "emqttd.schema"])]),
|
||||||
Conf = conf_parse:file(filename:join([DataDir, "emqttd.conf"])),
|
Conf = conf_parse:file(filename:join([DataDir, "emqttd.conf"])),
|
||||||
cuttlefish_generator:map(Schema, Conf).
|
cuttlefish_generator:map(Schema, Conf).
|
||||||
|
|
||||||
change_opts(SslType, DataDir, Vals) ->
|
change_opts(SslType, DataDir, Vals) ->
|
||||||
Listeners = proplists:get_value(listeners, Vals),
|
Listeners = proplists:get_value(listeners, Vals),
|
||||||
NewListeners = lists:foldl(fun({Protocol, Port, Opts} = Listener, Acc) ->
|
NewListeners =
|
||||||
case Protocol of
|
lists:foldl(fun({Protocol, Port, Opts} = Listener, Acc) ->
|
||||||
ssl ->
|
case Protocol of
|
||||||
SslOpts = proplists:get_value(ssl, Opts),
|
ssl ->
|
||||||
Keyfile = filename:join([DataDir, proplists:get_value(keyfile, SslOpts)]),
|
SslOpts = proplists:get_value(ssl, Opts),
|
||||||
Certfile = filename:join([DataDir, proplists:get_value(certfile, SslOpts)]),
|
Keyfile = filename:join([DataDir, proplists:get_value(keyfile, SslOpts)]),
|
||||||
TupleList1 = lists:keyreplace(keyfile, 1, SslOpts, {keyfile, Keyfile}),
|
Certfile = filename:join([DataDir, proplists:get_value(certfile, SslOpts)]),
|
||||||
TupleList2 = lists:keyreplace(certfile, 1, TupleList1, {certfile, Certfile}),
|
TupleList1 = lists:keyreplace(keyfile, 1, SslOpts, {keyfile, Keyfile}),
|
||||||
TupleList3 =
|
TupleList2 = lists:keyreplace(certfile, 1, TupleList1, {certfile, Certfile}),
|
||||||
case SslType of
|
TupleList3 =
|
||||||
ssl_mut ->
|
case SslType of
|
||||||
CAfile = filename:join([DataDir, proplists:get_value(cacertfile, ?MQTT_SSL_MUTWAY)]),
|
ssl_mut ->
|
||||||
MutSslList = lists:keyreplace(cacertfile, 1, ?MQTT_SSL_MUTWAY, {cacertfile, CAfile}),
|
CAfile = filename:join([DataDir, proplists:get_value(cacertfile, ?MQTT_SSL_MUTWAY)]),
|
||||||
lists:merge(TupleList2, MutSslList);
|
MutSslList = lists:keyreplace(cacertfile, 1, ?MQTT_SSL_MUTWAY, {cacertfile, CAfile}),
|
||||||
_ ->
|
lists:merge(TupleList2, MutSslList);
|
||||||
TupleList2
|
_ ->
|
||||||
end,
|
TupleList2
|
||||||
[{Protocol, Port, [{ssl, TupleList3}]} | Acc];
|
end,
|
||||||
_ ->
|
[{Protocol, Port, [{ssl, TupleList3}]} | Acc];
|
||||||
[Listener | Acc]
|
_ ->
|
||||||
end
|
[Listener | Acc]
|
||||||
end, [], Listeners),
|
end
|
||||||
lists:keyreplace(listeners, 1, Vals, {listeners, NewListeners}).
|
end, [], Listeners),
|
||||||
|
lists:keyreplace(listeners, 1, Vals, {listeners, NewListeners}).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue