Exemplo n.º 1
0
 def testGetValueUponWrongStatus(self):
     "Test result value upon wrong status"
     source = DocumentSourceMock((405, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
     document = Document(source)
     self.assertEquals(document.get_value(parser_func=parser_stub_func), None)
Exemplo n.º 2
0
 def testIncorrectCertificateWithValidSignature(self):
     "Test incorrect certificate with valid signature"
     source = DocumentSourceMock((200, INCORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
     document = Document(source)
     self.assertTrue(document.verify())
Exemplo n.º 3
0
 def testGetValueUponStatus200(self):
     "Test result value upon status 200"
     source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
     document = Document(source)
     self.assertEquals(document.get_value(parser_func=parser_stub_func), 3)
Exemplo n.º 4
0
 def testCorrectCertificateWithInvalidSignature(self):
     "Test correct certificate with invalid signature"
     source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_INVALID_SIGNATURE))
     document = Document(source)
     self.assertFalse(document.verify())
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 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')
Exemplo n.º 8
0
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