Disgraceful that we didn't have automated tests for so long! These are still pretty simple, but will have to do.
This commit is contained in:
parent
0617de9407
commit
8b6ab83b18
|
|
@ -0,0 +1,13 @@
|
|||
The tests *require* a locally installed LDAP server with some
|
||||
predefined objects inside. If there's no LDAP server running on port
|
||||
389, they will be skipped.
|
||||
|
||||
On Debian / Ubuntu you can just:
|
||||
|
||||
$ ./example/setup.sh
|
||||
$ make test
|
||||
|
||||
- but be aware that this will wipe out your local OpenLDAP installation.
|
||||
|
||||
Poke around in example/ if using any other distro, you can probably
|
||||
make it work.
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
[{rabbit, [{auth_backends, [rabbit_auth_backend_ldap]},
|
||||
{default_vhost, <<"test">>}]},
|
||||
{rabbitmq_auth_backend_ldap,
|
||||
[ {servers, ["localhost"]},
|
||||
{user_dn_pattern, "cn=${username},ou=People,dc=example,dc=com"},
|
||||
{other_bind, anon},
|
||||
{use_ssl, false},
|
||||
{port, 389},
|
||||
{log, true},
|
||||
{tag_queries, [{administrator, {constant, false}}]},
|
||||
{vhost_access_query, {exists, "ou=${vhost},ou=vhosts,dc=example,dc=com"}},
|
||||
{resource_access_query,
|
||||
{for, [{resource, exchange,
|
||||
{for, [{permission, configure,
|
||||
{ in_group, "cn=wheel,ou=groups,dc=example,dc=com" }
|
||||
},
|
||||
{permission, write, {constant, true}},
|
||||
{permission, read, {constant, true}}
|
||||
]}},
|
||||
{resource, queue, {constant, true}} ]}}
|
||||
]}
|
||||
].
|
||||
|
|
@ -6,4 +6,3 @@ dn: cn=wheel,ou=groups,dc=example,dc=com
|
|||
objectclass: groupOfNames
|
||||
cn: wheel
|
||||
member: cn=Simon MacMullen,ou=people,dc=example,dc=com
|
||||
member: cn=Michael Bridgen,ou=people,dc=example,dc=com
|
||||
|
|
|
|||
|
|
@ -1,2 +1,7 @@
|
|||
RELEASABLE:=true
|
||||
DEPS:=rabbitmq-server rabbitmq-erlang-client eldap-wrapper
|
||||
|
||||
ifeq ($(shell nmap -p 389 localhost | grep '389/tcp open' > /dev/null && echo true),true)
|
||||
WITH_BROKER_TEST_COMMANDS:=eunit:test(rabbit_auth_backend_ldap_test,[verbose])
|
||||
WITH_BROKER_TEST_CONFIG:=$(PACKAGE_DIR)/etc/rabbit-test
|
||||
endif
|
||||
|
|
|
|||
|
|
@ -14,4 +14,4 @@
|
|||
{use_ssl, false},
|
||||
{port, 389},
|
||||
{log, false} ] },
|
||||
{applications, [kernel, stdlib, eldap]}]}.
|
||||
{applications, [kernel, stdlib, eldap, rabbit]}]}.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
%% 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 VMware, Inc.
|
||||
%% Copyright (c) 2007-2011 VMware, Inc. All rights reserved.
|
||||
%%
|
||||
|
||||
-module(rabbit_auth_backend_ldap_test).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include_lib("amqp_client/include/amqp_client.hrl").
|
||||
|
||||
-define(SIMON, #amqp_params_network{username = <<"Simon MacMullen">>,
|
||||
password = <<"password">>,
|
||||
virtual_host = <<"test">>}).
|
||||
|
||||
-define(MIKEB, #amqp_params_network{username = <<"Mike Bridgen">>,
|
||||
password = <<"password">>,
|
||||
virtual_host = <<"test">>}).
|
||||
|
||||
login_test_() ->
|
||||
[?_test(fail(#amqp_params_network{})),
|
||||
?_test(fail(#amqp_params_network{username = <<"Simon MacMullen">>})),
|
||||
?_test(fail(#amqp_params_network{username = <<"Simon MacMullen">>,
|
||||
password = <<"password">>})),
|
||||
?_test(succ(?SIMON))].
|
||||
|
||||
succ(Params) -> ?assertMatch({ok, _}, amqp_connection:start(Params)).
|
||||
fail(Params) -> ?assertMatch({error, _}, amqp_connection:start(Params)).
|
||||
|
||||
resource_test_() ->
|
||||
X = #'exchange.declare'{exchange = <<"test">>},
|
||||
Q = #'queue.declare'{queue = <<"test">>},
|
||||
[fun() ->
|
||||
{ok, Conn} = amqp_connection:start(Person),
|
||||
{ok, Ch} = amqp_connection:open_channel(Conn),
|
||||
?assertEqual(Result, try amqp_channel:call(Ch, Thing), ok
|
||||
catch exit:_ -> fail
|
||||
end)
|
||||
end || {Person, Thing, Result} <- [{?SIMON, X, ok},
|
||||
{?SIMON, Q, ok},
|
||||
{?MIKEB, X, fail},
|
||||
{?MIKEB, Q, ok}]].
|
||||
Loading…
Reference in New Issue