diff options
author | Erik Johnston <erik@matrix.org> | 2015-05-06 11:46:02 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-05-06 11:46:02 +0100 |
commit | 673375fe2d0df303e47bcd818df580d59ffc4dfa (patch) | |
tree | 8c9b339ce336b8d1dd45a3ac899c1875612236aa /scripts-dev/check_auth.py | |
parent | Re-add scripts/register_new_matrix_user (diff) | |
download | synapse-673375fe2d0df303e47bcd818df580d59ffc4dfa.tar.xz |
Acutally add scripts-dev/
Diffstat (limited to 'scripts-dev/check_auth.py')
-rw-r--r-- | scripts-dev/check_auth.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/scripts-dev/check_auth.py b/scripts-dev/check_auth.py new file mode 100644 index 0000000000..b889ac7fa7 --- /dev/null +++ b/scripts-dev/check_auth.py @@ -0,0 +1,65 @@ +from synapse.events import FrozenEvent +from synapse.api.auth import Auth + +from mock import Mock + +import argparse +import itertools +import json +import sys + + +def check_auth(auth, auth_chain, events): + auth_chain.sort(key=lambda e: e.depth) + + auth_map = { + e.event_id: e + for e in auth_chain + } + + create_events = {} + for e in auth_chain: + if e.type == "m.room.create": + create_events[e.room_id] = e + + for e in itertools.chain(auth_chain, events): + auth_events_list = [auth_map[i] for i, _ in e.auth_events] + + auth_events = { + (e.type, e.state_key): e + for e in auth_events_list + } + + auth_events[("m.room.create", "")] = create_events[e.room_id] + + try: + auth.check(e, auth_events=auth_events) + except Exception as ex: + print "Failed:", e.event_id, e.type, e.state_key + print "Auth_events:", auth_events + print ex + print json.dumps(e.get_dict(), sort_keys=True, indent=4) + # raise + print "Success:", e.event_id, e.type, e.state_key + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + + parser.add_argument( + 'json', + nargs='?', + type=argparse.FileType('r'), + default=sys.stdin, + ) + + args = parser.parse_args() + + js = json.load(args.json) + + + auth = Auth(Mock()) + check_auth( + auth, + [FrozenEvent(d) for d in js["auth_chain"]], + [FrozenEvent(d) for d in js["pdus"]], + ) |