25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-24 17:29:28 +01:00
xmpp.chapril.org-ejabberd/test/ejabberd_SUITE_data/extauth.py

59 lines
1.4 KiB
Python
Raw Normal View History

"""extauth dummy script for ejabberd testing."""
2013-06-26 04:29:50 +02:00
import sys
import struct
def read_from_stdin(read_bytes):
"""Read buffer from standard input."""
if hasattr(sys.stdin, 'buffer'):
return sys.stdin.buffer.read(read_bytes)
return sys.stdin.read(read_bytes)
2013-06-26 04:29:50 +02:00
def read():
"""Read input and process the command."""
(pkt_size,) = struct.unpack('>H', read_from_stdin(2))
pkt = sys.stdin.read(pkt_size)
cmd = pkt.split(':')[0]
if cmd == 'auth':
user, _, _ = pkt.split(':', 3)[1:]
if user == "wrong":
2016-09-23 11:30:33 +02:00
write(False)
else:
write(True)
elif cmd == 'isuser':
user, _ = pkt.split(':', 2)[1:]
if user == "wrong":
2018-02-16 18:34:09 +01:00
write(False)
else:
write(True)
elif cmd == 'setpass':
user, _, _ = pkt.split(':', 3)[1:]
2013-06-26 04:29:50 +02:00
write(True)
elif cmd == 'tryregister':
user, _, _ = pkt.split(':', 3)[1:]
2013-06-26 04:29:50 +02:00
write(True)
elif cmd == 'removeuser':
user, _ = pkt.split(':', 2)[1:]
2013-06-26 04:29:50 +02:00
write(True)
elif cmd == 'removeuser3':
user, _, _ = pkt.split(':', 3)[1:]
2013-06-26 04:29:50 +02:00
write(True)
else:
write(False)
read()
def write(result):
"""write result to standard output."""
2013-06-26 04:29:50 +02:00
if result:
sys.stdout.write('\x00\x02\x00\x01')
else:
sys.stdout.write('\x00\x02\x00\x00')
sys.stdout.flush()
2013-06-26 04:29:50 +02:00
if __name__ == "__main__":
try:
read()
except struct.error:
pass