aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2013-06-26 12:29:50 +1000
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>2013-06-26 12:30:32 +1000
commitaab70fc0666f62cd23828232806a344af352be03 (patch)
tree30310352bf076e9e2dfad4bee9c8d542aaeac2e2 /test
parentDo not fetch disco#info multiple times (diff)
Fix external authentication
Diffstat (limited to 'test')
-rw-r--r--test/ejabberd_SUITE.erl14
-rw-r--r--test/ejabberd_SUITE_data/ejabberd.cfg4
-rwxr-xr-xtest/ejabberd_SUITE_data/extauth.py36
3 files changed, 54 insertions, 0 deletions
diff --git a/test/ejabberd_SUITE.erl b/test/ejabberd_SUITE.erl
index 845d9d428..ba9580fb6 100644
--- a/test/ejabberd_SUITE.erl
+++ b/test/ejabberd_SUITE.erl
@@ -70,6 +70,7 @@
-define(MYSQL_VHOST, <<"mysql.localhost">>).
-define(PGSQL_VHOST, <<"pgsql.localhost">>).
-define(LDAP_VHOST, <<"ldap.localhost">>).
+-define(EXTAUTH_VHOST, <<"extauth.localhost">>).
suite() ->
[{timetrap, {seconds,10}}].
@@ -85,8 +86,10 @@ init_per_suite(Config) ->
MnesiaDir = filename:join([PrivDir, "mnesia"]),
CertFile = filename:join([DataDir, "cert.pem"]),
LDIFFile = filename:join([DataDir, "ejabberd.ldif"]),
+ ExtAuthScript = filename:join([DataDir, "extauth.py"]),
{ok, CWD} = file:get_cwd(),
{ok, _} = file:copy(CertFile, filename:join([CWD, "cert.pem"])),
+ {ok, _} = file:copy(ExtAuthScript, filename:join([CWD, "extauth.py"])),
application:set_env(ejabberd, config, ConfigPath),
application:set_env(ejabberd, log_path, LogPath),
application:set_env(sasl, sasl_error_logger, {file, SASLPath}),
@@ -136,6 +139,8 @@ init_per_group(pgsql, Config) ->
end;
init_per_group(ldap, Config) ->
set_opt(server, ?LDAP_VHOST, Config);
+init_per_group(extauth, Config) ->
+ set_opt(server, ?EXTAUTH_VHOST, Config);
init_per_group(_GroupName, Config) ->
Pid = start_event_relay(),
set_opt(event_relay, Pid, Config).
@@ -150,6 +155,8 @@ end_per_group(no_db, _Config) ->
ok;
end_per_group(ldap, _Config) ->
ok;
+end_per_group(extauth, _Config) ->
+ ok;
end_per_group(_GroupName, Config) ->
stop_event_relay(Config),
ok.
@@ -252,8 +259,14 @@ ldap_tests() ->
[test_auth,
vcard_get]}].
+extauth_tests() ->
+ [{extauth_tests, [sequence],
+ [test_auth,
+ test_unregister]}].
+
groups() ->
[{ldap, [sequence], ldap_tests()},
+ {extauth, [sequence], extauth_tests()},
{no_db, [sequence], no_db_tests()},
{mnesia, [sequence], db_tests()},
{mysql, [sequence], db_tests()},
@@ -268,6 +281,7 @@ all() ->
{group, mnesia},
{group, mysql},
{group, pgsql},
+ {group, extauth},
stop_ejabberd].
stop_ejabberd(Config) ->
diff --git a/test/ejabberd_SUITE_data/ejabberd.cfg b/test/ejabberd_SUITE_data/ejabberd.cfg
index b50913353..458de2c7d 100644
--- a/test/ejabberd_SUITE_data/ejabberd.cfg
+++ b/test/ejabberd_SUITE_data/ejabberd.cfg
@@ -3,6 +3,7 @@
"mnesia.localhost",
"mysql.localhost",
"pgsql.localhost",
+ "extauth.localhost",
"ldap.localhost"]}.
{define_macro, 'CERTFILE', "cert.pem"}.
{listen,
@@ -59,6 +60,9 @@
{mod_version, []}
]}.
{host_config, "localhost", [{auth_method, internal}]}.
+{host_config, "extauth.localhost",
+ [{auth_method, external},
+ {extauth_program, "python extauth.py"}]}.
{host_config, "mnesia.localhost",
[{auth_method, internal},
{{add, modules}, [{mod_announce, [{db_type, internal}]},
diff --git a/test/ejabberd_SUITE_data/extauth.py b/test/ejabberd_SUITE_data/extauth.py
new file mode 100755
index 000000000..7f32eb8be
--- /dev/null
+++ b/test/ejabberd_SUITE_data/extauth.py
@@ -0,0 +1,36 @@
+import sys
+import struct
+
+def read():
+ (pkt_size,) = struct.unpack('>H', sys.stdin.read(2))
+ pkt = sys.stdin.read(pkt_size).split(':')
+ cmd = pkt[0]
+ args_num = len(pkt) - 1
+ if cmd == 'auth' and args_num == 3:
+ write(True)
+ elif cmd == 'isuser' and args_num == 2:
+ write(True)
+ elif cmd == 'setpass' and args_num == 3:
+ write(True)
+ elif cmd == 'tryregister' and args_num == 3:
+ write(True)
+ elif cmd == 'removeuser' and args_num == 2:
+ write(True)
+ elif cmd == 'removeuser3' and args_num == 3:
+ write(True)
+ else:
+ write(False)
+ read()
+
+def write(result):
+ if result:
+ sys.stdout.write('\x00\x02\x00\x01')
+ else:
+ sys.stdout.write('\x00\x02\x00\x00')
+ sys.stdout.flush()
+
+if __name__ == "__main__":
+ try:
+ read()
+ except struct.error:
+ pass