Exemplo n.º 1
0
    def test_tor2web_absence(self):
        """
        This test checks:
        https://github.com/globaleaks/GlobaLeaks/issues/268
        """

        ### INITIALIZE BLOCK
        self.mockContext = helpers.MockDict().dummyContext
        self.mockReceiver = helpers.MockDict().dummyReceiver
        self.mockNode = helpers.MockDict().dummyNode

        self.createdContext = yield admin.create_context(self.mockContext)
        self.assertTrue(self.createdContext.has_key('id'))

        self.mockReceiver['contexts'] = [self.createdContext['id']]

        self.createdReceiver = yield admin.create_receiver(self.mockReceiver)
        self.assertTrue(self.createdReceiver.has_key('id'))

        self.createdNode = yield admin.update_node(self.mockNode)
        self.assertTrue(self.createdNode.has_key('version'))
        ### END OF THE INITIALIZE BLOCK

        # be sure of Tor2Web capability
        for attrname in Node.localized_strings:
            self.mockNode[attrname] = self.mockNode[attrname]['en']
        self.createdNode = yield admin.update_node(self.mockNode)
        yield admin.import_memory_variables()

        self._load_defaults()

        self.mockSubmission = helpers.MockDict().dummySubmission
        self.mockSubmission['finalize'] = True
        self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0]
        self.mockSubmission['receivers'] = [self.createdReceiver['id']]
        self.mockSubmission['wb_fields'] = helpers.fill_random_fields(
            self.createdContext)
        self.createdSubmission = yield submission.create_submission(
            self.mockSubmission, finalize=True)

        created_rtip = yield delivery_sched.tip_creation()
        self.assertEqual(len(created_rtip), 1)

        yield self._fill_event(u'encrypted_tip', 'Tip', created_rtip[0])

        # adding funny configured variables
        self.templates['default_ETNT.txt'][
            'en'] += " %OttimoDireiOOOttimoDirei%"

        # with the event, we can finally call the format checks
        gentext = Templating().format_template(
            self.templates['default_ETNT.txt'], self.event)

        self.assertSubstring(self.createdContext['name'], gentext)
        self.assertSubstring(created_rtip[0], gentext)
        self.assertNotSubstring("%TipT2WURL%", gentext)

        # test against funny configured variables
        self.assertSubstring("%OttimoDireiOOOttimoDirei%", gentext)
Exemplo n.º 2
0
    def test_tor2web_absence(self):
        """
        This test checks:
        https://github.com/globaleaks/GlobaLeaks/issues/268
        """

        ### INITIALIZE BLOCK
        self.mockContext = helpers.MockDict().dummyContext
        self.mockReceiver = helpers.MockDict().dummyReceiver
        self.mockNode = helpers.MockDict().dummyNode

        self.createdContext = yield admin.create_context(self.mockContext)
        self.assertTrue(self.createdContext.has_key('id'))

        self.mockReceiver['contexts'] = [ self.createdContext['id'] ]

        self.createdReceiver = yield admin.create_receiver(self.mockReceiver)
        self.assertTrue(self.createdReceiver.has_key('id'))

        self.createdNode = yield admin.update_node(self.mockNode)
        self.assertTrue(self.createdNode.has_key('version'))
        ### END OF THE INITIALIZE BLOCK

        # be sure of Tor2Web capability
        for attrname in Node.localized_strings:
            self.mockNode[attrname] = self.mockNode[attrname]['en']
        self.createdNode = yield admin.update_node(self.mockNode)
        yield admin.import_memory_variables()

        self._load_defaults()

        self.mockSubmission = helpers.MockDict().dummySubmission
        self.mockSubmission['finalize'] = True
        self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0]
        self.mockSubmission['receivers'] = [ self.createdReceiver['id'] ]
        self.mockSubmission['wb_fields'] = helpers.fill_random_fields(self.createdContext)
        self.createdSubmission = yield submission.create_submission(self.mockSubmission, finalize=True)

        created_rtip = yield delivery_sched.tip_creation()
        self.assertEqual(len(created_rtip), 1)

        yield self._fill_event(u'encrypted_tip', 'Tip', created_rtip[0])

        # adding funny configured variables 
        self.templates['default_ETNT.txt']['en'] += " %OttimoDireiOOOttimoDirei%"

        # with the event, we can finally call the format checks
        gentext = Templating().format_template(self.templates['default_ETNT.txt'], self.event)

        self.assertSubstring(self.createdContext['name'], gentext)
        self.assertSubstring(created_rtip[0], gentext)
        self.assertNotSubstring("%TipT2WURL%", gentext)

        # test against funny configured variables
        self.assertSubstring("%OttimoDireiOOOttimoDirei%", gentext)
Exemplo n.º 3
0
    def do_finalize_submission(self):
        self.submission_desc['finalize'] = True
        self.submission_desc['wb_fields'] = helpers.fill_random_fields(self.context_desc)
        self.submission_desc = yield submission.update_submission(
            self.submission_desc['id'],
            self.submission_desc,
            finalize=True)

        self.assertEqual(self.submission_desc['mark'], models.InternalTip._marker[1])
        
        submission.create_whistleblower_tip(self.submission_desc)
Exemplo n.º 4
0
    def setUp(self):
        yield helpers.TestGLWithPopulatedDB.setUp(self)

        self.recipe = yield submission.create_submission({
            'wb_fields': helpers.fill_random_fields(self.dummyContext),
            'context_id': self.dummyContext['id'],
            'receivers': [self.dummyReceiver_1['id']],
            'files': [],
            'finalize': True,
            }, finalize=True)

        yield delivery_sched.tip_creation()
Exemplo n.º 5
0
    def setUp(self):
        yield helpers.TestGLWithPopulatedDB.setUp(self)

        self.recipe = yield submission.create_submission(
            {
                'wb_fields': helpers.fill_random_fields(self.dummyContext),
                'context_id': self.dummyContext['id'],
                'receivers': [self.dummyReceiver_1['id']],
                'files': [],
                'finalize': True,
            },
            finalize=True)

        yield delivery_sched.tip_creation()
Exemplo n.º 6
0
    def test_002_fail_submission_missing_required_file(self):
        mycopy = dict(self.dummyContext)
        mycopy['file_required'] = True
        del mycopy['id']

        for attrname in models.Context.localized_strings:
            mycopy[attrname] = u'⅛¡⅜⅛’ŊÑŦŊŊ’‘ª‘ª’‘ÐŊ'

        context_status = yield create_context(mycopy)
        submission_desc = dict(self.dummySubmission)

        submission_desc['context_id'] = context_status['id']
        submission_desc['finalize'] = True
        submission_desc['wb_fields'] = helpers.fill_random_fields(mycopy)
        yield self.assertFailure(submission.create_submission(submission_desc, finalize=True), errors.FileRequiredMissing)
Exemplo n.º 7
0
    def test_002_fail_submission_missing_required_file(self):
        mycopy = dict(self.dummyContext)
        mycopy['file_required'] = True
        del mycopy['id']

        for attrname in models.Context.localized_strings:
            mycopy[attrname] = u'⅛¡⅜⅛’ŊÑŦŊŊ’‘ª‘ª’‘ÐŊ'

        context_status = yield create_context(mycopy)
        submission_desc = dict(self.dummySubmission)

        submission_desc['context_id'] = context_status['id']
        submission_desc['finalize'] = True
        submission_desc['wb_fields'] = helpers.fill_random_fields(mycopy)
        yield self.assertFailure(
            submission.create_submission(submission_desc, finalize=True),
            errors.FileRequiredMissing)
Exemplo n.º 8
0
    def test_fail_submission_missing_file(self):

        mycopy = dict(self.dummyContext)
        mycopy["file_required"] = True

        context_status = yield create_context(mycopy)
        submission_desc = dict(self.dummySubmission)

        submission_desc["context_gus"] = context_status["context_gus"]
        submission_desc["finalize"] = True
        submission_desc["wb_fields"] = helpers.fill_random_fields(self.dummyContext)

        try:
            yield submission.create_submission(submission_desc, finalize=True)
        except errors.FileRequiredMissing:
            self.assertTrue(True)
            return
        self.assertTrue(False)
Exemplo n.º 9
0
    def test_update_submission(self):
        submission_desc = dict(self.dummySubmission)
        submission_desc["finalize"] = False
        submission_desc["context_gus"] = self.dummyContext["context_gus"]
        submission_desc["submission_gus"] = submission_desc["id"] = submission_desc["mark"] = None

        status = yield submission.create_submission(submission_desc, finalize=False)

        status["wb_fields"] = helpers.fill_random_fields(self.dummyContext)
        status["finalize"] = True

        status = yield submission.update_submission(status["submission_gus"], status, finalize=True)

        receipt = yield submission.create_whistleblower_tip(status)
        wb_access_id = yield authentication.login_wb(receipt)

        wb_tip = yield tip.get_internaltip_wb(wb_access_id)

        self.assertTrue(wb_tip.has_key("fields"))
Exemplo n.º 10
0
    def test_default_template_keywords(self):

        self._load_defaults()

        ### INITIALIZE BLOCK
        self.mockContext = helpers.MockDict().dummyContext
        self.mockReceiver = helpers.MockDict().dummyReceiver
        self.mockNode = helpers.MockDict().dummyNode

        self.createdContext = yield admin.create_context(self.mockContext)
        self.assertTrue(self.createdContext.has_key('id'))

        self.mockReceiver['contexts'] = [self.createdContext['id']]

        self.createdReceiver = yield admin.create_receiver(self.mockReceiver)
        self.assertTrue(self.createdReceiver.has_key('id'))

        self.createdNode = yield admin.update_node(self.mockNode)
        self.assertTrue(self.createdNode.has_key('version'))
        ### END OF THE INITIALIZE BLOCK

        # THE REAL CONVERSION TEST START HERE:
        self.mockSubmission = helpers.MockDict().dummySubmission
        self.mockSubmission['finalize'] = True
        self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0]
        self.mockSubmission['receivers'] = [self.createdReceiver['id']]
        self.mockSubmission['wb_fields'] = helpers.fill_random_fields(
            self.createdContext)
        self.createdSubmission = yield submission.create_submission(
            self.mockSubmission, finalize=True)

        created_rtip = yield delivery_sched.tip_creation()
        self.assertEqual(len(created_rtip), 1)

        yield self._fill_event(u'encrypted_tip', 'Tip', created_rtip[0])

        # with the event, we can finally call the template filler
        gentext = Templating().format_template(
            self.templates['default_ETNT.txt'], self.event)

        self.assertSubstring(self.createdContext['name'], gentext)
        self.assertSubstring(created_rtip[0], gentext)
        self.assertSubstring(self.createdNode['public_site'], gentext)
Exemplo n.º 11
0
    def test_008_update_submission(self):
        submission_desc = dict(self.dummySubmission)
        submission_desc['finalize'] = False
        submission_desc['context_id'] = self.dummyContext['id']
        submission_desc['id'] = submission_desc['mark'] = None

        status = yield submission.create_submission(submission_desc, finalize=False)

        status['wb_fields'] = helpers.fill_random_fields(self.dummyContext)
        status['finalize'] = True

        status = yield submission.update_submission(status['id'], status, finalize=True)

        receipt = yield submission.create_whistleblower_tip(status)
        wb_access_id = yield authentication.login_wb(receipt)

        wb_tip = yield wbtip.get_internaltip_wb(wb_access_id)

        self.assertTrue(wb_tip.has_key('fields'))
Exemplo n.º 12
0
    def setUp(self):
        yield helpers.TestGL.setUp(self)

        self.recipe = yield submission.create_submission({
            'wb_fields': helpers.fill_random_fields(self.dummyContext),
            'context_gus': self.dummyContext['context_gus'],
            'receivers': [self.dummyReceiver['receiver_gus']],
            'files': [],
            'finalize': True,
            }, finalize=True)
        yield delivery_sched.tip_creation()

        # This mocks out the MailNotification plugin so it does not actually
        # require to perform a connection to send an email.
        # XXX we probably want to create a proper mock of the ESMTPSenderFactory
        def mail_flush_mock(self, from_address, to_address, message_file, event):
            return defer.succeed(None)

        notification.MailNotification.mail_flush = mail_flush_mock
Exemplo n.º 13
0
    def test_encrypt_message(self):

        dummy_template = "In %EventTime% you've got a crush for Taryn Southern, yay!! \
                         more info on: https://www.youtube.com/watch?v=C7JZ4F3zJdY \
                         and know that you're not alone!"

        mock_event = Event(
            type=u'encrypted_tip',
            trigger='Tip',
            tip_info={
                'creation_date': '2013-05-13T17:49:26.105485',  #epoch!
                'id': 'useless',
                'wb_steps': fill_random_fields(self.dummyContext['id']),
            },
            node_info=MockDict().dummyNode,
            receiver_info=MockDict().dummyReceiver,
            context_info=MockDict().dummyContext,
            steps_info={},
            subevent_info={},
            do_mail=False)

        mail_content = Templating().format_template(dummy_template, mock_event)

        # setup the GPG key before
        GLSetting.gpgroot = GPGROOT

        fake_receiver_desc = {
            'gpg_key_armor': unicode(VALID_PGP_KEY1),
            'gpg_key_fingerprint': u"CF4A22020873A76D1DCB68D32B25551568E49345",
            'gpg_key_status': u'enabled',
            'username': u'*****@*****.**',
        }

        gpgobj = GLBGPG()
        gpgobj.load_key(VALID_PGP_KEY1)

        encrypted_body = gpgobj.encrypt_message(
            fake_receiver_desc['gpg_key_fingerprint'], mail_content)
        self.assertSubstring('-----BEGIN PGP MESSAGE-----', encrypted_body)

        gpgobj.destroy_environment()
Exemplo n.º 14
0
    def test_Class_encryption_message(self):

        dummy_template = {
            "en":
            "In %EventTime% you've got a crush for Taryn Southern, yay!!"
            "more info on: https://www.youtube.com/watch?v=C7JZ4F3zJdY "
            "and know that you're not alone!"
        }

        mock_event = Event(
            type=u'encrypted_tip',
            trigger='Tip',
            notification_settings=dummy_template,
            trigger_info={
                'creation_date': '2013-05-13T17:49:26.105485',  #epoch!
                'id': 'useless',
                'wb_fields': fill_random_fields(self.dummyContext),
            },
            node_info=MockDict().dummyNode,
            receiver_info=MockDict().dummyReceiver,
            context_info=MockDict().dummyContext,
            plugin=MailNotification(),
            trigger_parent={})

        mail_content = Templating().format_template(dummy_template, mock_event)

        # setup the GPG key before
        GLSetting.gpgroot = GPGROOT

        fake_receiver_desc = {
            'gpg_key_armor': unicode(VALID_PGP_KEY),
            'gpg_key_fingerprint': u"CF4A22020873A76D1DCB68D32B25551568E49345",
            'gpg_key_status': Receiver._gpg_types[1],
            'username': u'*****@*****.**',
        }

        gpob = GLBGPG(fake_receiver_desc)
        self.assertTrue(gpob.validate_key(VALID_PGP_KEY))

        encrypted_body = gpob.encrypt_message(mail_content)
        self.assertSubstring('-----BEGIN PGP MESSAGE-----', encrypted_body)
Exemplo n.º 15
0
    def test_default_template_keywords(self):

        self._load_defaults()

        ### INITIALIZE BLOCK
        self.mockContext = helpers.MockDict().dummyContext
        self.mockReceiver = helpers.MockDict().dummyReceiver
        self.mockNode = helpers.MockDict().dummyNode

        self.createdContext = yield admin.create_context(self.mockContext)
        self.assertTrue(self.createdContext.has_key('id'))

        self.mockReceiver['contexts'] = [ self.createdContext['id'] ]

        self.createdReceiver = yield admin.create_receiver(self.mockReceiver)
        self.assertTrue(self.createdReceiver.has_key('id'))

        self.createdNode = yield admin.update_node(self.mockNode)
        self.assertTrue(self.createdNode.has_key('version'))
        ### END OF THE INITIALIZE BLOCK

        # THE REAL CONVERSION TEST START HERE:
        self.mockSubmission = helpers.MockDict().dummySubmission
        self.mockSubmission['finalize'] = True
        self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0]
        self.mockSubmission['receivers'] = [ self.createdReceiver['id'] ]
        self.mockSubmission['wb_fields'] = helpers.fill_random_fields(self.createdContext)
        self.createdSubmission = yield submission.create_submission(self.mockSubmission, finalize=True)

        created_rtip = yield delivery_sched.tip_creation()
        self.assertEqual(len(created_rtip), 1)

        yield self._fill_event(u'encrypted_tip', 'Tip', created_rtip[0])

        # with the event, we can finally call the template filler
        gentext = Templating().format_template(self.templates['default_ETNT.txt'], self.event)

        self.assertSubstring(self.createdContext['name'], gentext)
        self.assertSubstring(created_rtip[0], gentext)
        self.assertSubstring(self.createdNode['public_site'], gentext)
Exemplo n.º 16
0
    def test_008_update_submission(self):
        submission_desc = dict(self.dummySubmission)
        submission_desc['finalize'] = False
        submission_desc['context_id'] = self.dummyContext['id']
        submission_desc['id'] = submission_desc['mark'] = None

        status = yield submission.create_submission(submission_desc,
                                                    finalize=False)

        status['wb_fields'] = helpers.fill_random_fields(self.dummyContext)
        status['finalize'] = True

        status = yield submission.update_submission(status['id'],
                                                    status,
                                                    finalize=True)

        receipt = yield submission.create_whistleblower_tip(status)
        wb_access_id = yield authentication.login_wb(receipt)

        wb_tip = yield wbtip.get_internaltip_wb(wb_access_id)

        self.assertTrue(wb_tip.has_key('fields'))
Exemplo n.º 17
0
    def test_Class_encryption_message(self):

        dummy_template = "In %EventTime% you've got a crush for Taryn Southern, yay!! \
                         more info on: https://www.youtube.com/watch?v=C7JZ4F3zJdY \
                         and know that you're not alone!"

        mock_event = Event(type=u'encrypted_tip', trigger='Tip',
                    notification_settings = dummy_template,
                    trigger_info = {
                        'creation_date': '2013-05-13T17:49:26.105485', #epoch!
                        'id': 'useless',
                        'wb_steps' : fill_random_fields(self.dummyContext['id']),
                    },
                    node_info = MockDict().dummyNode,
                    receiver_info = MockDict().dummyReceiver,
                    context_info = MockDict().dummyContext,
                    steps_info = {},
                    plugin = MailNotification(),
                    trigger_parent = {} )

        mail_content = Templating().format_template(dummy_template, mock_event)

        # setup the GPG key before
        GLSetting.gpgroot = GPGROOT

        fake_receiver_desc = {
            'gpg_key_armor': unicode(VALID_PGP_KEY),
            'gpg_key_fingerprint': u"CF4A22020873A76D1DCB68D32B25551568E49345",
            'gpg_key_status': Receiver._gpg_types[1],
            'username': u'*****@*****.**',
        }

        gpob = GLBGPG(fake_receiver_desc)
        self.assertTrue(gpob.validate_key(VALID_PGP_KEY))

        encrypted_body = gpob.encrypt_message(mail_content)
        self.assertSubstring('-----BEGIN PGP MESSAGE-----', encrypted_body)
Exemplo n.º 18
0
    def test_submission_file_delivery_gpg(self):

        new_context = dict(MockDict().dummyContext)
        new_context['name'] = "this uniqueness is no more checked due to the lang"
        new_context_output = yield create_context(new_context)
        self.context_assertion(new_context, new_context_output)

        doubletest = yield get_context_list('en')
        self.assertEqual(len(doubletest), 2)

        yanr = dict(MockDict().dummyReceiver)
        yanr['name'] = yanr['mail_address'] = u"*****@*****.**"
        yanr['gpg_key_armor'] = unicode(VALID_PGP_KEY)
        yanr['contexts'] = [ new_context_output['id']]
        yanr_output = yield create_receiver(yanr)
        self.receiver_assertion(yanr, yanr_output)

        asdr = dict(MockDict().dummyReceiver)
        asdr['name'] = asdr['mail_address'] = u"*****@*****.**"
        asdr['gpg_key_armor'] = unicode(VALID_PGP_KEY)
        asdr['contexts'] = [ new_context_output['id']]
        asdr_output = yield create_receiver(asdr)
        self.receiver_assertion(asdr, asdr_output)

        new_subm = dict(MockDict().dummySubmission)

        new_subm['finalize'] = False

        new_subm['context_id'] = new_context_output['id']
        new_subm['receivers'] = [ asdr_output['id'],
                                  yanr_output['id'] ]
        new_subm['wb_fields'] = fill_random_fields(new_context_output)
        new_subm_output = yield create_submission(new_subm, False)
        # self.submission_assertion(new_subm, new_subm_output)

        self.emulate_file_upload(new_subm_output['id'])

        new_file = self.get_dummy_file()

        new_subm['id'] = new_subm_output['id']
        new_subm['finalize'] = True
        new_subm_output = yield update_submission(new_subm['id'], new_subm, True)

        yield DeliverySchedule().operation()

        # now get a lots of receivertips/receiverfiles and check!
        ifilist = yield get_files_by_itip(new_subm_output['id'])

        self.assertTrue(isinstance(ifilist, list))
        self.assertEqual(len(ifilist), 2)
        self.assertEqual(ifilist[0]['mark'], u'delivered')

        rfilist = yield get_receiverfile_by_itip(new_subm_output['id'])

        self.assertTrue(isinstance(ifilist, list))
        self.assertEqual(len(rfilist), 2)

        for i in range(0, 2):
            self.assertLess(ifilist[0]['size'], rfilist[i]['size'])

        self.assertEqual(rfilist[0]['status'], u"encrypted" )
Exemplo n.º 19
0
    def test_submission_file_delivery_gpg(self):

        new_fields = MockDict().dummyFields
        new_context = MockDict().dummyContext

        new_context['steps'][0]['children'] = []

        new_context[
            'name'] = "this uniqueness is no more checked due to the lang"
        new_context_output = yield create_context(new_context, 'en')
        self.context_assertion(new_context, new_context_output)

        doubletest = yield get_context_list('en')
        self.assertEqual(len(doubletest), 2)

        yanr = dict(MockDict().dummyReceiver)
        yanr['name'] = yanr['mail_address'] = u"*****@*****.**"
        yanr['gpg_key_armor'] = unicode(VALID_PGP_KEY1)
        yanr['contexts'] = [new_context_output['id']]
        yanr_output = yield create_receiver(yanr, 'en')
        self.receiver_assertion(yanr, yanr_output)

        asdr = dict(MockDict().dummyReceiver)
        asdr['name'] = asdr['mail_address'] = u"*****@*****.**"
        asdr['gpg_key_armor'] = unicode(VALID_PGP_KEY1)
        asdr['contexts'] = [new_context_output['id']]
        asdr_output = yield create_receiver(asdr, 'en')
        self.receiver_assertion(asdr, asdr_output)

        new_subm = dict(MockDict().dummySubmission)

        new_subm['finalize'] = False

        new_subm['context_id'] = new_context_output['id']
        new_subm['receivers'] = [asdr_output['id'], yanr_output['id']]
        new_subm['wb_steps'] = yield fill_random_fields(
            new_context_output['id'])
        new_subm_output = yield create_submission(new_subm, False, 'en')
        # self.submission_assertion(new_subm, new_subm_output)

        self.emulate_file_upload(new_subm_output['id'])

        new_file = self.get_dummy_file()

        new_subm['id'] = new_subm_output['id']
        new_subm['finalize'] = True
        new_subm_output = yield update_submission(new_subm['id'], new_subm,
                                                  True, 'en')

        yield DeliverySchedule().operation()

        # now get a lots of receivertips/receiverfiles and check!
        ifilist = yield get_files_by_itip(new_subm_output['id'])

        self.assertTrue(isinstance(ifilist, list))
        self.assertEqual(len(ifilist), 2)
        self.assertEqual(ifilist[0]['mark'], u'delivered')

        rfilist = yield get_receiverfile_by_itip(new_subm_output['id'])

        self.assertTrue(isinstance(ifilist, list))
        self.assertEqual(len(rfilist), 2)

        for i in range(0, 2):
            self.assertLess(ifilist[0]['size'], rfilist[i]['size'])

        self.assertEqual(rfilist[0]['status'], u"encrypted")
Exemplo n.º 20
0
    def test_keywords_conversion(self):

        ### INITIALIZE BLOCK
        self.mockContext =helpers.MockDict().dummyContext
        self.mockReceiver = helpers.MockDict().dummyReceiver
        self.mockNode = helpers.MockDict().dummyNode

        self.createdContext = yield admin.create_context(self.mockContext)
        self.assertTrue(self.createdContext.has_key('id'))

        self.mockReceiver['contexts'] = [ self.createdContext['id'] ]
        
        self.createdReceiver = yield admin.create_receiver(self.mockReceiver)
        self.assertTrue(self.createdReceiver.has_key('id'))

        self.createdNode = yield admin.update_node(self.mockNode)
        self.assertTrue(self.createdNode.has_key('version'))
        ### END OF THE INITIALIZE BLOCK

        self.templates = {}
        for t in self.templates_list:
            self.templates[t] = { 'en': u"" }

            for k in notifTemplateTest.generic_keyword_list:
                self.templates[t]['en'] += " " + k

        for k in notifTemplateTest.tip_keyword_list:
            self.templates['default_ETNT.txt']['en'] += " " + k
            self.templates['default_PTNT.txt']['en'] += " " + k

        for k in notifTemplateTest.protected_keyword_list:
            self.templates['default_ETNT.txt']['en'] += " " + k

        for k in notifTemplateTest.comment_keyword_list:
            self.templates['default_ECNT.txt']['en'] += " " + k
            self.templates['default_PCNT.txt']['en'] += " " + k

        for k in notifTemplateTest.file_keyword_list:
            self.templates['default_EFNT.txt']['en'] += " " + k
            self.templates['default_PFNT.txt']['en'] += " " + k

        # THE REAL CONVERSION TEST START HERE:
        self.mockSubmission = helpers.MockDict().dummySubmission
        self.mockSubmission['finalize'] = True
        self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0]
        self.mockSubmission['receivers'] = [ self.createdReceiver['id'] ]
        self.mockSubmission['wb_fields'] = helpers.fill_random_fields(self.createdContext)
        self.createdSubmission = yield submission.create_submission(self.mockSubmission, finalize=True)

        created_rtip = yield delivery_sched.tip_creation()
        self.assertEqual(len(created_rtip), 1)

        yield self._fill_event(u'encrypted_tip', 'Tip', created_rtip[0])

        # with the event, we can finally call the template filler
        gentext = Templating().format_template(self.templates['default_ETNT.txt'], self.event)

        self.assertSubstring(self.createdContext['name'], gentext)
        self.assertSubstring(created_rtip[0], gentext)
        self.assertSubstring(self.createdNode['public_site'], gentext)
        self.assertSubstring(self.createdNode['hidden_service'], gentext)

        ## HERE ARE ADDED SOME CHECK
        self.assertSubstring("=================", gentext)

        # http://witchwind.wordpress.com/2013/12/15/piv-is-always-rape-ok/
        # wtf has the internet in those days ? bwahahaah
        tip_num_test = Templating().format_template({'en': u'%TipNum%'}, self.event)
        new_id = self.event.trigger_info['id'].replace('1', '2')
        new_id.replace('3', '4')
        self.event.trigger_info['id'] = new_id.replace('5', '6')
        different_num = Templating().format_template({'en': u'%TipNum%'}, self.event)
        self.assertNotEqual(tip_num_test, different_num)
Exemplo n.º 21
0
    def test_keywords_conversion(self):
        self.templates = {}
        for t, keywords_list in templates_desc.iteritems():

            self.templates[t] = ""

            for kwl in keywords_list:
                for keyword in kwl:
                    self.templates[t] += " " + keyword + " / "

        ### INITIALIZE DATABASE
        self.mockContext = helpers.MockDict().dummyContext
        self.mockReceiver = helpers.MockDict().dummyReceiverGPG
        self.mockNode = helpers.MockDict().dummyNode

        self.createdContext = yield admin.create_context(
            self.mockContext, 'en')
        self.assertTrue('id' in self.createdContext)

        self.mockReceiver['contexts'] = [self.createdContext['id']]

        self.createdReceiver = yield admin.create_receiver(
            self.mockReceiver, 'en')
        self.assertTrue('id' in self.createdReceiver)

        self.createdNode = yield admin.update_node(self.mockNode, True, 'en')
        self.assertTrue('version' in self.createdNode)
        ### END OF THE INITIALIZE BLOCK

        # THE REAL CONVERSION TEST START HERE:
        self.mockSubmission = helpers.MockDict().dummySubmission
        self.mockSubmission['finalize'] = True
        self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0]
        self.mockSubmission['receivers'] = [self.createdReceiver['id']]
        self.mockSubmission['wb_fields'] = helpers.fill_random_fields(
            self.createdContext)
        self.createdSubmission = yield submission.create_submission(
            self.mockSubmission, True, 'en')

        created_rtip = yield delivery_sched.tip_creation()
        self.assertEqual(len(created_rtip), 1)

        # some doubt in the next two lines: is just to have a mock tip
        self.tip = dict(self.mockSubmission)
        self.tip['id'] = created_rtip[0]

        for template_name, template in self.templates.iteritems():
            # look for appropriate event_type, event_trigger
            event_type = u''
            event_trigger = ''
            for e_t, e_tri in supported_event_types.iteritems():
                if template_name.startswith(e_t):
                    event_type = e_t
                    event_trigger = e_tri
                    break

            if not event_type:
                # we've nothing to do not!
                continue

            yield self._fill_event_dict(event_type, event_trigger)

            # with the event, we can finally call the template filler
            gentext = Templating().format_template(template, self.event)

            if template_name != 'ping_mail_template' and template_name != 'ping_mail_title':
                self.assertSubstring(self.createdContext['name'], gentext)
                self.assertSubstring(self.createdNode['public_site'], gentext)
                self.assertSubstring(self.createdNode['hidden_service'],
                                     gentext)
Exemplo n.º 22
0
    def test_keywords_conversion(self):
        self.templates = {}
        for t, keywords_list in templates_desc.iteritems():

            self.templates[t] = ""

            for kwl in keywords_list:
                for keyword in kwl:
                    self.templates[t] += " " + keyword + " / "

        ### INITIALIZE DATABASE
        self.mockContext =helpers.MockDict().dummyContext
        self.mockReceiver = helpers.MockDict().dummyReceiver
        self.mockNode = helpers.MockDict().dummyNode

        self.createdContext = yield admin.create_context(self.mockContext)
        self.assertTrue(self.createdContext.has_key('id'))

        self.mockReceiver['contexts'] = [ self.createdContext['id'] ]

        self.createdReceiver = yield admin.create_receiver(self.mockReceiver)
        self.assertTrue(self.createdReceiver.has_key('id'))

        self.createdNode = yield admin.update_node(self.mockNode)
        self.assertTrue(self.createdNode.has_key('version'))
        ### END OF THE INITIALIZE BLOCK

        # THE REAL CONVERSION TEST START HERE:
        self.mockSubmission = helpers.MockDict().dummySubmission
        self.mockSubmission['finalize'] = True
        self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0]
        self.mockSubmission['receivers'] = [ self.createdReceiver['id'] ]
        self.mockSubmission['wb_fields'] = helpers.fill_random_fields(self.createdContext)
        self.createdSubmission = yield submission.create_submission(self.mockSubmission, finalize=True)

        created_rtip = yield delivery_sched.tip_creation()
        self.assertEqual(len(created_rtip), 1)

        # some doubt in the next two lines: is just to have a mock tip
        self.tip = dict(self.mockSubmission)
        self.tip['id'] = created_rtip[0]

        for fname, template in self.templates.iteritems():

            # look for appropriate event_type, event_trigger
            event_type = u''
            event_trigger = ''
            for e_t, e_tri in supported_event_types.iteritems():
                if fname.startswith(e_t):
                    event_type = e_t
                    event_trigger = e_tri
                    break

            if not event_type:
                # we've nothing to do not!
                break

            yield self._fill_event_dict(event_type, event_trigger)

            # with the event, we can finally call the template filler
            gentext = Templating().format_template(template, self.event)

            self.assertSubstring(self.createdContext['name'], gentext)
            self.assertSubstring(self.createdNode['public_site'], gentext)
            self.assertSubstring(self.createdNode['hidden_service'], gentext)
Exemplo n.º 23
0
    def test_keywords_conversion(self):

        ### INITIALIZE BLOCK
        self.mockContext = helpers.MockDict().dummyContext
        self.mockReceiver = helpers.MockDict().dummyReceiver
        self.mockNode = helpers.MockDict().dummyNode

        self.createdContext = yield admin.create_context(self.mockContext)
        self.assertTrue(self.createdContext.has_key('id'))

        self.mockReceiver['contexts'] = [self.createdContext['id']]

        self.createdReceiver = yield admin.create_receiver(self.mockReceiver)
        self.assertTrue(self.createdReceiver.has_key('id'))

        self.createdNode = yield admin.update_node(self.mockNode)
        self.assertTrue(self.createdNode.has_key('version'))
        ### END OF THE INITIALIZE BLOCK

        self.templates = {}
        for t in self.templates_list:
            self.templates[t] = {'en': u""}

            for k in notifTemplateTest.generic_keyword_list:
                self.templates[t]['en'] += " " + k

        for k in notifTemplateTest.tip_keyword_list:
            self.templates['default_ETNT.txt']['en'] += " " + k
            self.templates['default_PTNT.txt']['en'] += " " + k

        for k in notifTemplateTest.protected_keyword_list:
            self.templates['default_ETNT.txt']['en'] += " " + k

        for k in notifTemplateTest.comment_keyword_list:
            self.templates['default_ECNT.txt']['en'] += " " + k
            self.templates['default_PCNT.txt']['en'] += " " + k

        for k in notifTemplateTest.file_keyword_list:
            self.templates['default_EFNT.txt']['en'] += " " + k
            self.templates['default_PFNT.txt']['en'] += " " + k

        # THE REAL CONVERSION TEST START HERE:
        self.mockSubmission = helpers.MockDict().dummySubmission
        self.mockSubmission['finalize'] = True
        self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0]
        self.mockSubmission['receivers'] = [self.createdReceiver['id']]
        self.mockSubmission['wb_fields'] = helpers.fill_random_fields(
            self.createdContext)
        self.createdSubmission = yield submission.create_submission(
            self.mockSubmission, finalize=True)

        created_rtip = yield delivery_sched.tip_creation()
        self.assertEqual(len(created_rtip), 1)

        yield self._fill_event(u'encrypted_tip', 'Tip', created_rtip[0])

        # with the event, we can finally call the template filler
        gentext = Templating().format_template(
            self.templates['default_ETNT.txt'], self.event)

        self.assertSubstring(self.createdContext['name'], gentext)
        self.assertSubstring(created_rtip[0], gentext)
        self.assertSubstring(self.createdNode['public_site'], gentext)
        self.assertSubstring(self.createdNode['hidden_service'], gentext)

        ## HERE ARE ADDED SOME CHECK
        self.assertSubstring("=================", gentext)

        # http://witchwind.wordpress.com/2013/12/15/piv-is-always-rape-ok/
        # wtf has the internet in those days ? bwahahaah
        tip_num_test = Templating().format_template({'en': u'%TipNum%'},
                                                    self.event)
        new_id = self.event.trigger_info['id'].replace('1', '2')
        new_id.replace('3', '4')
        self.event.trigger_info['id'] = new_id.replace('5', '6')
        different_num = Templating().format_template({'en': u'%TipNum%'},
                                                     self.event)
        self.assertNotEqual(tip_num_test, different_num)