From afa0dd56e1cce64fe08bff3c64b12aecce54fd2d Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 31 May 2016 16:21:06 +0200 Subject: python: Port more tests. * lang/python/gpgme.i: Hide length fields of notations. * lang/python/tests/Makefile.am (pytests): Add new tests. * lang/python/tests/t-decrypt-verify.py: New file. * lang/python/tests/t-sig-notation.py: Likewise. * lang/python/tests/t-verify.py: Likewise. Signed-off-by: Justus Winter --- lang/python/tests/t-sig-notation.py | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 lang/python/tests/t-sig-notation.py (limited to 'lang/python/tests/t-sig-notation.py') diff --git a/lang/python/tests/t-sig-notation.py b/lang/python/tests/t-sig-notation.py new file mode 100755 index 00000000..2d832ef2 --- /dev/null +++ b/lang/python/tests/t-sig-notation.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2016 g10 Code GmbH +# +# This file is part of GPGME. +# +# GPGME is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# GPGME is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General +# Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, see . + +import os +from pyme import core, constants, errors +import support + +expected_notations = { + "laughing@me": ("Just Squeeze Me", constants.SIG_NOTATION_HUMAN_READABLE), + "preferred-email-encoding@pgp.com": ("pgpmime", + constants.SIG_NOTATION_HUMAN_READABLE + | constants.SIG_NOTATION_CRITICAL), + None: ("http://www.gnu.org/policy/", 0), +} + +def check_result(result): + assert len(result.signatures) == 1, "Unexpected number of signatures" + sig = result.signatures[0] + assert len(sig.notations) == len(expected_notations) + + for r in sig.notations: + assert not 'name_len' in dir(r) + assert not 'value_len' in dir(r) + assert r.name in expected_notations + value, flags = expected_notations.pop(r.name) + + assert r.value == value, \ + "Expected {!r}, got {!r}".format(value, r.value) + assert r.human_readable \ + == bool(flags&constants.SIG_NOTATION_HUMAN_READABLE) + # xxx notyet + #assert r.human_readable \ + # == bool(flags&constants.SIG_NOTATION_CRITICAL) + + assert len(expected_notations) == 0 + +support.init_gpgme(constants.PROTOCOL_OpenPGP) + +source = core.Data("Hallo Leute\n") +signed = core.Data() + +c = core.Context() +for name, (value, flags) in expected_notations.items(): + c.sig_notation_add(name, value, flags) + +c.op_sign(source, signed, constants.SIG_MODE_NORMAL) + +signed.seek(0, os.SEEK_SET) +sink = core.Data() +c.op_verify(signed, None, sink) +result = c.op_verify_result() +check_result(result) -- cgit v1.2.3