fix(ws): take ws_cookie to clientinfo

see: https://github.com/emqx/emqx/issues/3747#issuecomment-702268570
This commit is contained in:
JianBo He 2020-10-12 17:05:06 +08:00 committed by tigercl
parent 87ef4e4dd9
commit 2feeb4d91f
3 changed files with 30 additions and 3 deletions

View File

@ -5,8 +5,11 @@
4 -> % arch_32 4 -> % arch_32
{1000, cuttlefish_bytesize:parse("32MB")} {1000, cuttlefish_bytesize:parse("32MB")}
end, end,
{"4.2.1", {"4.2.2",
[ [
{"4.2.1", [
{load_module, emqx_channel, brutal_purge, soft_purge, []}
]},
{"4.2.0", [ {"4.2.0", [
{load_module, emqx_channel, brutal_purge, soft_purge, []}, {load_module, emqx_channel, brutal_purge, soft_purge, []},
{apply, {application, set_env, {apply, {application, set_env,
@ -16,6 +19,9 @@
]} ]}
], ],
[ [
{"4.2.1", [
{load_module, emqx_channel, brutal_purge, soft_purge, []}
]},
{"4.2.0", [ {"4.2.0", [
{load_module, emqx_channel, brutal_purge, soft_purge, []} {load_module, emqx_channel, brutal_purge, soft_purge, []}
]} ]}

View File

@ -183,8 +183,9 @@ init(ConnInfo = #{peername := {PeerHost, _Port},
is_bridge => false, is_bridge => false,
is_superuser => false is_superuser => false
}, Options), }, Options),
#channel{conninfo = ConnInfo, {NClientInfo, NConnInfo} = take_ws_cookie(ClientInfo, ConnInfo),
clientinfo = ClientInfo, #channel{conninfo = NConnInfo,
clientinfo = NClientInfo,
topic_aliases = #{inbound => #{}, topic_aliases = #{inbound => #{},
outbound => #{} outbound => #{}
}, },
@ -213,6 +214,14 @@ setting_peercert_infos(Peercert, ClientInfo, Options) ->
end, end,
ClientInfo#{username => Username, dn => DN, cn => CN}. ClientInfo#{username => Username, dn => DN, cn => CN}.
take_ws_cookie(ClientInfo, ConnInfo) ->
case maps:take(ws_cookie, ConnInfo) of
{WsCookie, NConnInfo} ->
{ClientInfo#{ws_cookie => WsCookie}, NConnInfo};
_ ->
{ClientInfo, ConnInfo}
end.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Handle incoming packet %% Handle incoming packet
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------

View File

@ -687,6 +687,18 @@ t_terminate(_) ->
ok = emqx_channel:terminate(sock_error, channel(#{conn_state => connected})), ok = emqx_channel:terminate(sock_error, channel(#{conn_state => connected})),
ok = emqx_channel:terminate({shutdown, kicked}, channel(#{conn_state => connected})). ok = emqx_channel:terminate({shutdown, kicked}, channel(#{conn_state => connected})).
t_ws_cookie_init(_) ->
WsCookie = [{<<"session_id">>, <<"xyz">>}],
ConnInfo = #{socktype => ws,
peername => {{127,0,0,1}, 3456},
sockname => {{127,0,0,1}, 1883},
peercert => nossl,
conn_mod => emqx_ws_connection,
ws_cookie => WsCookie
},
Channel = emqx_channel:init(ConnInfo, [{zone, zone}]),
?assertMatch(#{ws_cookie := WsCookie}, emqx_channel:info(clientinfo, Channel)).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Helper functions %% Helper functions
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------