Пример #1
0
    def test_tor2web_absence(self):
        """
        This test checks:
        https://github.com/globaleaks/GlobaLeaks/issues/268
        """

        yield self._initialize()

        # be sure of Tor2Web capability
        self.mockNode['tor2web_tip'] = False
        self.createdNode = yield admin.update_node(self.mockNode)
        yield admin.import_memory_variables()

        self._load_defaults()

        self.mockSubmission = MockDict().dummySubmission
        self.mockSubmission['finalize'] = True
        self.mockSubmission['context_gus'] = self.createdReceiver['contexts'][0]
        self.mockSubmission['receivers'] = [ self.createdReceiver['receiver_gus'] ]
        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'tip', 'Tip', created_rtip[0])

        # with the event, we can finally call the format checks
        gentext = MailNotification().format_template(self.Tip_notifi_template, self.event)

        self.assertSubstring(self.createdContext['name'], gentext)
        self.assertSubstring(created_rtip[0], gentext)
        self.assertNotSubstring("%TipT2WURL%", gentext)
Пример #2
0
    def test_create_receiverfiles_allow_unencrypted_true_no_keys_loaded(self):
        yield self.test_create_submission_attach_files_finalize_and_access_wbtip()

        # create receivertip its NEEDED to create receiverfile
        self.rt = yield delivery_sched.tip_creation()
        self.assertTrue(isinstance(self.rt, list))

        self.rfilesdict = yield delivery_sched.receiverfile_planning()
        # return a list of lists [ "file_id", status, "f_path", len, "receiver_desc" ]
        self.assertTrue(isinstance(self.rfilesdict, dict))

        for ifile_path, receivermap in self.rfilesdict.iteritems():
            yield delivery_sched.encrypt_where_available(receivermap)
            for elem in receivermap:
                yield delivery_sched.receiverfile_create(ifile_path,
                                                         elem['path'],
                                                         elem['status'],
                                                         elem['size'],
                                                         elem['receiver'])

        self.fil = yield delivery_sched.get_files_by_itip(self.submission_desc['id'])
        self.assertTrue(isinstance(self.fil, list))
        self.assertEqual(len(self.fil), 3)

        self.rfi = yield delivery_sched.get_receiverfile_by_itip(self.submission_desc['id'])
        self.assertTrue(isinstance(self.rfi, list))
        self.assertEqual(len(self.rfi), 6)

        for i in range(0, 6):
            self.assertTrue(self.rfi[i]['status'] in [u'reference', u'encrypted'])

        self.wbfls = yield collect_ifile_as_wb_without_wbtip(self.submission_desc['id'])
        self.assertEqual(len(self.wbfls), 3)
Пример #3
0
    def test_keywords(self):

        yield self._initialize()
        self._load_defaults()

        self.mockSubmission = MockDict().dummySubmission
        self.mockSubmission['finalize'] = True
        self.mockSubmission['context_gus'] = self.createdReceiver['contexts'][0]
        self.mockSubmission['receivers'] = [ self.createdReceiver['receiver_gus'] ]
        self.createdSubmission = yield submission.create_submission(self.mockSubmission, finalize=True)

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

        try:
            yield self._fill_event(u'tip', 'Tip', created_rtip[0])
        except Exception as excep:
            print excep; raise excep

        # with the event, we can finally call the template filler
        gentext = MailNotification().format_template(self.Tip_notifi_template, 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)
Пример #4
0
    def test_006_submission_with_receiver_selection_allow_unencrypted_true_no_keys_loaded(
            self):

        # for some reason, the first receiver is no more with the same ID
        self.receivers = yield get_receiver_list()

        rcvrs_ids = []

        for rcvr in self.receivers:
            rcvrs_ids.append(rcvr['id'])

        self.dummyContext['receivers'] = rcvrs_ids
        self.dummyContext['selectable_receiver'] = True
        self.dummyContext['escalation_threshold'] = 0

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

        context_status = yield update_context(self.dummyContext['id'],
                                              self.dummyContext)

        # Create a new request with selected three of the four receivers
        submission_request = dict(self.dummySubmission)
        # submission_request['context_id'] = context_status['context_id']
        submission_request['id'] = ''
        submission_request['finalize'] = False

        submission_request['receivers'] = rcvrs_ids

        status = yield submission.create_submission(submission_request,
                                                    finalize=False)
        just_empty_eventually_internaltip = yield delivery_sched.tip_creation()

        # Checks, the submission need to be the same now
        self.assertEqual(len(submission_request['receivers']),
                         len(status['receivers']))

        status['finalize'] = True
        submission_request['context_id'] = context_status['id']  # reused
        status['receivers'] = rcvrs_ids

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

        receiver_tips = yield delivery_sched.tip_creation()
        self.assertEqual(len(receiver_tips), len(status['receivers']))
Пример #5
0
    def test_submission_with_receiver_selection(self):

        yield create_receiver(self.get_new_receiver_desc("second"))
        yield create_receiver(self.get_new_receiver_desc("third"))
        yield create_receiver(self.get_new_receiver_desc("fourth"))

        # for some reason, the first receiver is no more with the same ID
        self.receivers = yield get_receiver_list()

        self.assertEqual(len(self.receivers), 4)

        self.dummyContext["receivers"] = [
            self.receivers[0]["receiver_gus"],
            self.receivers[1]["receiver_gus"],
            self.receivers[2]["receiver_gus"],
            self.receivers[3]["receiver_gus"],
        ]
        self.dummyContext["selectable_receiver"] = True
        self.dummyContext["escalation_threshold"] = 0

        context_status = yield update_context(self.dummyContext["context_gus"], self.dummyContext)

        # Create a new request with selected three of the four receivers
        submission_request = dict(self.dummySubmission)
        # submission_request['context_gus'] = context_status['context_gus']
        submission_request["submission_gus"] = submission_request["id"] = ""
        submission_request["finalize"] = False
        submission_request["receivers"] = [
            self.receivers[0]["receiver_gus"],
            self.receivers[1]["receiver_gus"],
            self.receivers[2]["receiver_gus"],
        ]

        status = yield submission.create_submission(submission_request, finalize=False)
        just_empty_eventually_internaltip = yield delivery_sched.tip_creation()

        # Checks, the submission need to be the same now
        self.assertEqual(len(submission_request["receivers"]), len(status["receivers"]))

        status["finalize"] = True
        submission_request["context_gus"] = context_status["context_gus"]  # reused
        status["receivers"] = [self.receivers[0]["receiver_gus"], self.receivers[3]["receiver_gus"]]

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

        receiver_tips = yield delivery_sched.tip_creation()
        self.assertEqual(len(receiver_tips), len(status["receivers"]))
Пример #6
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)
Пример #7
0
    def do_create_receivers_tip(self):
        receiver_tips = yield delivery_sched.tip_creation()

        self.rtip1_id = receiver_tips[0]
        self.rtip2_id = receiver_tips[1]

        self.assertEqual(len(receiver_tips), 2)
        self.assertTrue(re.match(uuid_regexp, receiver_tips[0]))
        self.assertTrue(re.match(uuid_regexp, receiver_tips[1]))
Пример #8
0
    def create_receivers_tip(self):

        receiver_tips = yield delivery_sched.tip_creation()

        self.rtip1_id = receiver_tips[0]
        self.rtip2_id = receiver_tips[1]

        self.assertEqual(len(receiver_tips), 2)
        self.assertTrue(re.match(requests.uuid_regexp, receiver_tips[0]))
        self.assertTrue(re.match(requests.uuid_regexp, receiver_tips[1]))
Пример #9
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)
Пример #10
0
    def create_receivers_tip(self):
        receiver_tips = yield delivery_sched.tip_creation()

        self.assertEqual(len(receiver_tips), 2)
        self.assertTrue(re.match(requests.uuid_regexp, receiver_tips[0]))
        self.assertTrue(re.match(requests.uuid_regexp, receiver_tips[1]))

        tips_receiver_1 = yield receiver.get_receiver_tip_list(self.receiver1_desc['id'], 'en')
        tips_receiver_2 = yield receiver.get_receiver_tip_list(self.receiver2_desc['id'], 'en')
        self.rtip1_id = tips_receiver_1[0]['id']
        self.rtip2_id = tips_receiver_2[0]['id']
Пример #11
0
    def create_receivers_tip(self):
        receivertips = yield delivery_sched.tip_creation()

        self.assertEqual(len(receivertips), 2)
        self.assertTrue(re.match(requests.uuid_regexp, receivertips[0]))
        self.assertTrue(re.match(requests.uuid_regexp, receivertips[1]))

        tips_receiver_1 = yield receiver.get_receivertip_list(self.receiver1_desc['id'], 'en')
        tips_receiver_2 = yield receiver.get_receivertip_list(self.receiver2_desc['id'], 'en')
        self.rtip1_id = tips_receiver_1[0]['id']
        self.rtip2_id = tips_receiver_2[0]['id']
Пример #12
0
    def test_006_submission_with_receiver_selection_allow_unencrypted_true_no_keys_loaded(self):

        # for some reason, the first receiver is no more with the same ID
        self.receivers = yield get_receiver_list()

        rcvrs_ids = []

        for rcvr in self.receivers:
            rcvrs_ids.append(rcvr['id'])

        self.dummyContext['receivers'] = rcvrs_ids
        self.dummyContext['selectable_receiver'] = True
        self.dummyContext['escalation_threshold'] = 0

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

        context_status = yield update_context(self.dummyContext['id'], self.dummyContext)

        # Create a new request with selected three of the four receivers
        submission_request= dict(self.dummySubmission)
        # submission_request['context_id'] = context_status['context_id']
        submission_request['id'] = ''
        submission_request['finalize'] = False

        submission_request['receivers'] = rcvrs_ids

        status = yield submission.create_submission(submission_request, finalize=False)
        just_empty_eventually_internaltip = yield delivery_sched.tip_creation()

        # Checks, the submission need to be the same now
        self.assertEqual(len(submission_request['receivers']), len(status['receivers']))

        status['finalize'] = True
        submission_request['context_id'] = context_status['id'] # reused
        status['receivers'] = rcvrs_ids

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

        receiver_tips = yield delivery_sched.tip_creation()
        self.assertEqual(len(receiver_tips), len(status['receivers']))
Пример #13
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()
Пример #14
0
    def test_tip_creation(self):

        receivers = yield get_public_receiver_list('en')
        contexts = yield get_public_context_list('en')

        yield create_submission(self.dummySubmission, finalize=True)
        created_tips = yield delivery_sched.tip_creation()
        self.assertEqual(len(created_tips), 2) # this createSubmission and the helpers one

        receiver_tips = yield get_receiver_tip_list(self.dummyReceiver['receiver_gus'])

        expected_keys = ['access_counter', 'creation_date', 'expressed_pertinence', 'id', 'files_number', 'last_access', 'preview']
        self.assertEqual(set(receiver_tips[0].keys()), set(expected_keys))
Пример #15
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()
Пример #16
0
    def test_005_create_receiverfiles_allow_unencrypted_false_no_keys_loaded(
            self):

        GLSetting.memory_copy.allow_unencrypted = False

        yield self.test_003_create_submission_attach_files_finalize_and_access_wbtip(
        )

        # create receivertip its NEEDED to create receiverfile
        self.rt = yield delivery_sched.tip_creation()
        self.assertTrue(isinstance(self.rt, list))

        self.rfilesdict = yield delivery_sched.receiverfile_planning()
        # return a list of lists [ "file_id", status, "f_path", len, "receiver_desc" ]
        self.assertTrue(isinstance(self.rfilesdict, dict))

        for ifile_path, receivermap in self.rfilesdict.iteritems():
            yield delivery_sched.encrypt_where_available(receivermap)
            for elem in receivermap:
                rfdesc = yield delivery_sched.receiverfile_create(
                    ifile_path, elem['path'], elem['status'], elem['size'],
                    elem['receiver'])
                self.assertEqual(rfdesc['mark'], u'not notified')
                self.assertEqual(rfdesc['receiver_id'], elem['receiver']['id'])

        self.fil = yield delivery_sched.get_files_by_itip(
            self.dummySubmission['id'])
        self.assertTrue(isinstance(self.fil, list))
        self.assertEqual(len(self.fil), 4)

        self.rfi = yield delivery_sched.get_receiverfile_by_itip(
            self.dummySubmission['id'])
        self.assertTrue(isinstance(self.rfi, list))

        self.assertEqual(len(self.rfi), 8)
        # no rfiles are created for the receivers that have no key
        for i in range(0, 8):
            self.assertTrue(
                self.rfi[i]['mark'] in [u'not notified', u'skipped'])
            self.assertTrue(self.rfi[i]['status'] in [u'reference', u'nokey'])

        # verify the checksum returned by whistleblower POV, I'm not using
        #  wfv = yield tip.get_files_wb()
        # because is not generated a WhistleblowerTip in this test
        self.wbfls = yield collect_ifile_as_wb_without_wbtip(
            self.dummySubmission['id'])
        self.assertEqual(len(self.wbfls), 4)
Пример #17
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
Пример #18
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)
Пример #19
0
    def test_005_create_receiverfiles_allow_unencrypted_false_no_keys_loaded(self):

        GLSetting.memory_copy.allow_unencrypted = False

        yield self.test_003_create_submission_attach_files_finalize_and_access_wbtip()

        # create receivertip its NEEDED to create receiverfile
        self.rt = yield delivery_sched.tip_creation()
        self.assertTrue(isinstance(self.rt, list))

        self.rfilesdict = yield delivery_sched.receiverfile_planning()
        # return a list of lists [ "file_id", status, "f_path", len, "receiver_desc" ]
        self.assertTrue(isinstance(self.rfilesdict, dict))


        for ifile_path, receivermap in self.rfilesdict.iteritems():
            yield delivery_sched.encrypt_where_available(receivermap)
            for elem in receivermap:
                rfdesc = yield delivery_sched.receiverfile_create(ifile_path,
                                    elem['path'], elem['status'], elem['size'], elem['receiver'])
                self.assertEqual(rfdesc['mark'], u'not notified')
                self.assertEqual(rfdesc['receiver_id'], elem['receiver']['id'])

        self.fil = yield delivery_sched.get_files_by_itip(self.dummySubmission['id'])
        self.assertTrue(isinstance(self.fil, list))
        self.assertEqual(len(self.fil), 4)

        self.rfi = yield delivery_sched.get_receiverfile_by_itip(self.dummySubmission['id'])
        self.assertTrue(isinstance(self.rfi, list))

        self.assertEqual(len(self.rfi), 8)
        # no rfiles are created for the receivers that have no key
        for i in range(0, 8):
            self.assertTrue(self.rfi[i]['mark'] in [u'not notified', u'skipped'])
            self.assertTrue(self.rfi[i]['status'] in [u'reference', u'nokey'])

        # verify the checksum returned by whistleblower POV, I'm not using
        #  wfv = yield tip.get_files_wb()
        # because is not generated a WhistleblowerTip in this test
        self.wbfls = yield collect_ifile_as_wb_without_wbtip(self.dummySubmission['id'])
        self.assertEqual(len(self.wbfls), 4)
Пример #20
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)
Пример #21
0
    def test_create_receiverfiles(self):

        yield self.emulate_file_upload(self.dummySubmission["submission_gus"])
        yield self._force_finalize(self.dummySubmission["submission_gus"])

        # create receivertip its NEEDED to create receiverfile
        rt = yield delivery_sched.tip_creation()
        self.assertTrue(isinstance(rt, list))

        rfileslist = yield delivery_sched.receiverfile_planning()
        # return a list of lists [ "file_id", status, "f_path", len, "receiver_desc" ]
        self.assertTrue(isinstance(rfileslist, list))

        for (fid, status, fpath, flen, receiver_desc) in rfileslist:

            rfdesc = yield delivery_sched.receiverfile_create(fid, status, fpath, flen, receiver_desc)
            self.assertEqual(rfdesc["mark"], "not notified")
            self.assertEqual(rfdesc["receiver_id"], receiver_desc["receiver_gus"])
            self.assertEqual(rfdesc["internalfile_id"], fid)

        fil = yield delivery_sched.get_files_by_itip(self.dummySubmission["submission_gus"])
        self.assertTrue(isinstance(fil, list))
        self.assertEqual(len(fil), 2)

        rfi = yield delivery_sched.get_receiverfile_by_itip(self.dummySubmission["submission_gus"])
        self.assertTrue(isinstance(rfi, list))
        self.assertEqual(len(rfi), 2)
        self.assertEqual(rfi[0]["mark"], "not notified")
        self.assertEqual(rfi[1]["mark"], "not notified")
        self.assertEqual(rfi[0]["status"], "reference")
        self.assertEqual(rfi[1]["status"], "reference")

        # verify the checksum returned by whistleblower POV, I'm not using
        #  wfv = yield tip.get_files_wb()
        # because is not generated a WhistleblowerTip in this test
        wbfls = yield collect_ifile_as_wb_without_wbtip(self.dummySubmission["submission_gus"])
        self.assertEqual(len(wbfls), 2)
        self.assertEqual(wbfls[0]["sha2sum"], fil[0]["sha2sum"])
        self.assertEqual(wbfls[1]["sha2sum"], fil[1]["sha2sum"])
Пример #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)
Пример #23
0
    def test_submission_with_receiver_selection_allow_unencrypted_true_no_keys_loaded(self):
        self.submission_desc = yield self.get_dummy_submission(self.dummyContext['id'])
        self.submission_desc = yield self.create_submission(self.submission_desc)

        receivertips = yield delivery_sched.tip_creation()
        self.assertEqual(len(receivertips), len(self.submission_desc['receivers']))
Пример #24
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)
Пример #25
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)
Пример #26
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)