def testIncorrectCertificateWithValidSignature(self): "Test incorrect certificate with valid signature" source = DocumentSourceMock((200, INCORRECT_CERTIFICATE_WITH_VALID_SIGNATURE)) document = Document(source) self.assertTrue(document.verify())
def testCorrectCertificateWithInvalidSignature(self): "Test correct certificate with invalid signature" source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_INVALID_SIGNATURE)) document = Document(source) self.assertFalse(document.verify())
def testGetRawData(self): "Test result value of document raw data" source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE)) document = Document(source) self.assertTrue(document.verify()) self.assertEquals(document.get_raw_data(), CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE)
def testGetBody(self): "Test result value of document body" source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE)) document = Document(source) self.assertTrue(document.verify()) self.assertEquals(document.get_body(), VALID_BODY)
def testGetCertificateID(self): "Test result value of document ID" source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE)) document = Document(source) self.assertTrue(document.verify()) self.assertEquals(document.get_id(), '64D0 F8CA 822B BDF0 FF59 42F6 A363 ED80 D8A5 CEFF')
def index(): D = request.args.get('D', None) B = request.args.get('B', '') F = request.args.get('F', None) E = request.args.get('E', None) K = request.args.get('K', None) L = request.args.get('L', '') status_code = 200 payment_required = False if F is not None: try: F = int(F) except ValueError: F = 0 else: F = 0 page = [render_header()] if D is None: return _render_error_page(_('Missing parameter'), _('Parameter D is missing')) invoice = Invoice(D, B=B, F=F) document_source = DocumentSource(settings.ISSUER, docid=invoice.D) document = Document(document_source) value = None verified = document.verify() # document.verify() returns False if verification failed # and None upon another error if verified != False: value = document.get_value() if value is not None: invoice.value = value if value > 0: invoice.certificate_link = '<a href="%s/info?ID=%s">%s</a>' % (settings.ISSUER, invoice.D, _('GET CERTIFICATE')) if (value >= F) and (F is not None) and (F > 0): invoice.message = _('The corresponding invoice has been paid') page.append(render_invoce(invoice)) # Email address email = '' if E is not None: set_cookie_value('pfemail', E) email = E else: email = request.cookies.get('pfemail') # PGP encryption key ID pgpkey = '' if K is not None: set_cookie_value('pfpgpkey', K) pgpkey = K else: pgpkey = request_cookies_get('pfpgpkey') # If mailreceipt application is configured render the email form if settings.MAILRECEIPT_URL: page.append(render_email_form(email, pgpkey, document.get_sn(), settings.MAILRECEIPT_URL, L)) else: if F > 0: payment_required = True status_code = 402 invoice.G = '%s/?D=%s&F=%s' % (settings.REDIRECTION_TARGET, invoice.D, str(invoice.F)) page.append(render_invoce_form(invoice)) else: return self._render_error_page(_('Internal error'), _('Sorry for the inconvenience')) page.append(render_footer()) response = make_response(page, status_code) if payment_required: response.headers['Content-Price'] = "%s EPT" % str(F - value) return response