aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/extauth.erl20
-rw-r--r--test/ejabberd_SUITE.erl14
-rw-r--r--test/ejabberd_SUITE_data/ejabberd.cfg4
-rwxr-xr-xtest/ejabberd_SUITE_data/extauth.py36
4 files changed, 61 insertions, 13 deletions
diff --git a/src/extauth.erl b/src/extauth.erl
index 0403b56b4..23a409ce5 100644
--- a/src/extauth.erl
+++ b/src/extauth.erl
@@ -70,28 +70,28 @@ get_process_name(Host, Integer) ->
eauth).
check_password(User, Server, Password) ->
- call_port(Server, ["auth", User, Server, Password]).
+ call_port(Server, [<<"auth">>, User, Server, Password]).
is_user_exists(User, Server) ->
- call_port(Server, ["isuser", User, Server]).
+ call_port(Server, [<<"isuser">>, User, Server]).
set_password(User, Server, Password) ->
- call_port(Server, ["setpass", User, Server, Password]).
+ call_port(Server, [<<"setpass">>, User, Server, Password]).
try_register(User, Server, Password) ->
case call_port(Server,
- ["tryregister", User, Server, Password])
+ [<<"tryregister">>, User, Server, Password])
of
true -> {atomic, ok};
false -> {error, not_allowed}
end.
remove_user(User, Server) ->
- call_port(Server, ["removeuser", User, Server]).
+ call_port(Server, [<<"removeuser">>, User, Server]).
remove_user(User, Server, Password) ->
call_port(Server,
- ["removeuser3", User, Server, Password]).
+ [<<"removeuser3">>, User, Server, Password]).
call_port(Server, Msg) ->
LServer = jlib:nameprep(Server),
@@ -154,13 +154,7 @@ flush_buffer_and_forward_messages(Pid) ->
after 0 -> true
end.
-join(List, Sep) ->
- lists:foldl(fun (A, "") -> A;
- (A, Acc) -> Acc ++ Sep ++ A
- end,
- "", List).
-
-encode(L) -> join(L, ":").
+encode(L) -> str:join(L, <<":">>).
decode([0, 0]) -> false;
decode([0, 1]) -> true.
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