summaryrefslogtreecommitdiff
path: root/script/testauthenticator.py
blob: faf4f56b63ce9c19862eb9b64c3015ba2d99dc63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3

import logging
import os
import sys

VALID_USER = b"mockmaildir@example.org"
VALID_PW = b"12345"


def main():
    with os.fdopen(3, "rb", buffering=0) as authfd:
        inp = authfd.readall()

    u, p, *r = inp.split(b"\0")
    if len(r) > 2:
        logging.warning("too many fields!")
        sys.exit(2)

    if r and r[0]:
        raise ValueError("cram currently not supported")
    else:
        if u == VALID_USER and p == VALID_PW:
            os.execvp(sys.argv[1], sys.argv[1:])

    sys.exit(1)


if __name__ == "__main__":
    main()