summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorArnaud Cogoluègnes <acogoluegnes@gmail.com>2017-06-22 15:53:48 +0200
committerArnaud Cogoluègnes <acogoluegnes@gmail.com>2017-06-22 15:53:48 +0200
commit9b25c146c39910787a0c0862f7c73b0b7c35f607 (patch)
tree544793521700357faa396e92fafe04eb40bf4da4 /test
parentce98122454f6897be0753e2938e8f59a533dbc93 (diff)
downloadrabbitmq-server-git-9b25c146c39910787a0c0862f7c73b0b7c35f607.tar.gz
Pass in extra arguments to authentication backend
Those extra arguments are extracted from an external module, the convention being "rabbit_%protocol%_connection_info" for the module name. This allows to pass in plugin-specific authentication arguments, e.g. client ID in the case of MQTT. Part of rabbitmq/rabbitmq-mqtt#139
Diffstat (limited to 'test')
-rw-r--r--test/rabbit_dummy_protocol_connection_info.erl28
-rw-r--r--test/unit_SUITE.erl21
2 files changed, 48 insertions, 1 deletions
diff --git a/test/rabbit_dummy_protocol_connection_info.erl b/test/rabbit_dummy_protocol_connection_info.erl
new file mode 100644
index 0000000000..3da963e057
--- /dev/null
+++ b/test/rabbit_dummy_protocol_connection_info.erl
@@ -0,0 +1,28 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License at
+%% http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+%% License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is GoPivotal, Inc.
+%% Copyright (c) 2017 Pivotal Software, Inc. All rights reserved.
+%%
+
+%% Dummy module to test rabbit_direct:extract_extra_auth_props
+
+-module(rabbit_dummy_protocol_connection_info).
+
+%% API
+-export([additional_authn_params/4]).
+
+additional_authn_params(_Creds, _VHost, Pid, _Infos) ->
+ case Pid of
+ -1 -> throw(error);
+ _ -> [{client_id, <<"DummyClientId">>}]
+ end.
diff --git a/test/unit_SUITE.erl b/test/unit_SUITE.erl
index 3e92158595..b4813fe801 100644
--- a/test/unit_SUITE.erl
+++ b/test/unit_SUITE.erl
@@ -49,6 +49,7 @@ groups() ->
pmerge,
plmerge,
priority_queue,
+ rabbit_direct_extract_extra_auth_props,
{resource_monitor, [parallel], [
parse_information_unit
]},
@@ -464,7 +465,25 @@ rabbitmqctl_encode_encrypt_decrypt(Secret) ->
)
.
-
+rabbit_direct_extract_extra_auth_props(_Config) ->
+ % no protocol to extract
+ [] = rabbit_direct:extract_extra_auth_props(
+ {<<"guest">>, <<"guest">>}, <<"/">>, 1,
+ [{name,<<"127.0.0.1:52366 -> 127.0.0.1:1883">>}]),
+ % protocol to extract, but no module to call
+ [] = rabbit_direct:extract_extra_auth_props(
+ {<<"guest">>, <<"guest">>}, <<"/">>, 1,
+ [{protocol, {'PROTOCOL_WITHOUT_MODULE', "1.0"}}]),
+ % see rabbit_dummy_protocol_connection_info module
+ % protocol to extract, module that returns a client ID
+ [{client_id, <<"DummyClientId">>}] = rabbit_direct:extract_extra_auth_props(
+ {<<"guest">>, <<"guest">>}, <<"/">>, 1,
+ [{protocol, {'DUMMY_PROTOCOL', "1.0"}}]),
+ % protocol to extract, but error thrown in module
+ [] = rabbit_direct:extract_extra_auth_props(
+ {<<"guest">>, <<"guest">>}, <<"/">>, -1,
+ [{protocol, {'DUMMY_PROTOCOL', "1.0"}}]),
+ ok.
%% -------------------------------------------------------------------
%% pg_local.