Exemplo n.º 1
0
    def test_001_setup_submission_environment(self):
        helpers.TestGL.setUp(self)

        basehandler = MockHandler()

        stuff = u"AAA :P ³²¼½¬¼³²"

        for attrname in Context.localized_strings:
            SubmissionTest.aContext1[attrname] = stuff

        basehandler.validate_jmessage(SubmissionTest.aContext1,
                                      adminContextDesc)
        SubmissionTest.context_used = yield admin.create_context(
            SubmissionTest.aContext1)

        # Correctly, TTip.tipContext has not selectable receiver, and we want test it in the 2nd test
        SubmissionTest.context_used['selectable_receiver'] = True

        for attrname in Context.localized_strings:
            SubmissionTest.context_used[attrname] = stuff

        SubmissionTest.context_used = yield admin.update_context(
            SubmissionTest.context_used['id'], SubmissionTest.context_used)

        basehandler.validate_jmessage(SubmissionTest.aContext2,
                                      adminContextDesc)
        SubmissionTest.context_unused = yield admin.create_context(
            SubmissionTest.aContext2)

        self.assertTrue(len(SubmissionTest.context_used['id']) > 1)
        self.assertTrue(len(SubmissionTest.context_unused['id']) > 1)

        SubmissionTest.aReceiver1['contexts'] = [
            SubmissionTest.context_used['id']
        ]

        for attrname in Receiver.localized_strings:
            SubmissionTest.aReceiver1[attrname] = stuff * 2
            SubmissionTest.aReceiver2[attrname] = stuff * 4

        basehandler.validate_jmessage(SubmissionTest.aReceiver1,
                                      adminReceiverDesc)
        SubmissionTest.receiver_used = yield admin.create_receiver(
            SubmissionTest.aReceiver1)

        SubmissionTest.aReceiver2['contexts'] = [
            SubmissionTest.context_unused['id']
        ]
        basehandler.validate_jmessage(SubmissionTest.aReceiver2,
                                      adminReceiverDesc)
        SubmissionTest.receiver_unused = yield admin.create_receiver(
            SubmissionTest.aReceiver2)

        self.assertTrue(SubmissionTest.receiver_used['name'] ==
                        SubmissionTest.aReceiver1['name'])
        self.assertTrue(SubmissionTest.receiver_unused['name'] ==
                        SubmissionTest.aReceiver2['name'])

        self.assertTrue(len(SubmissionTest.receiver_used['contexts']), 1)
        self.assertTrue(len(SubmissionTest.receiver_unused['contexts']), 1)
Exemplo n.º 2
0
    def test_007_submission_with_receiver_selection_allow_unencrypted_false_no_keys_loaded(
            self):

        GLSetting.memory_copy.allow_unencrypted = False

        # 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

        yield self.assertFailure(
            submission.create_submission(submission_request, finalize=True),
            errors.SubmissionFailFields)
Exemplo n.º 3
0
    def test_007_submission_with_receiver_selection_allow_unencrypted_false_no_keys_loaded(self):

        GLSetting.memory_copy.allow_unencrypted = False

        # 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

        yield self.assertFailure(submission.create_submission(submission_request, finalize=True), errors.SubmissionFailFields)
Exemplo n.º 4
0
    def test_001_setup_submission_environment(self):
        helpers.TestGL.setUp(self)
        
        basehandler = MockHandler()

        stuff = u"AAA :P ³²¼½¬¼³²"

        for attrname in Context.localized_strings:
            SubmissionTest.aContext1[attrname] = stuff

        basehandler.validate_jmessage(SubmissionTest.aContext1, adminContextDesc)

        # the test context need fields to be present
        from globaleaks.handlers.admin.field import create_field
        for idx, field in enumerate(self.dummyFields):
            f = yield create_field(field, 'en')
            self.dummyFields[idx]['id'] = f['id']

        SubmissionTest.aContext1['steps'][0]['children'] = [
            self.dummyFields[0], # Field 1
            self.dummyFields[1], # Field 2
            self.dummyFields[4]  # Generalities
        ]

        SubmissionTest.context_used = yield admin.create_context(SubmissionTest.aContext1)

        # Correctly, TTip.tipContext has not selectable receiver, and we want test it in the 2nd test
        SubmissionTest.context_used['selectable_receiver'] = True

        for attrname in Context.localized_strings:
            SubmissionTest.context_used[attrname] = stuff

        SubmissionTest.context_used = yield admin.update_context(SubmissionTest.context_used['id'],
            SubmissionTest.context_used)

        basehandler.validate_jmessage( SubmissionTest.aContext2, adminContextDesc)
        SubmissionTest.context_unused = yield admin.create_context(SubmissionTest.aContext2)

        self.assertTrue(len(SubmissionTest.context_used['id']) > 1)
        self.assertTrue(len(SubmissionTest.context_unused['id']) > 1)

        SubmissionTest.aReceiver1['contexts'] = [ SubmissionTest.context_used['id'] ]

        for attrname in Receiver.localized_strings:
            SubmissionTest.aReceiver1[attrname] = stuff * 2
            SubmissionTest.aReceiver2[attrname] = stuff * 4

        basehandler.validate_jmessage( SubmissionTest.aReceiver1, adminReceiverDesc )
        SubmissionTest.receiver_used = yield admin.create_receiver(SubmissionTest.aReceiver1)

        SubmissionTest.aReceiver2['contexts'] = [ SubmissionTest.context_unused['id'] ]
        basehandler.validate_jmessage( SubmissionTest.aReceiver2, adminReceiverDesc )
        SubmissionTest.receiver_unused = yield admin.create_receiver(SubmissionTest.aReceiver2)

        self.assertTrue(SubmissionTest.receiver_used['name'] == SubmissionTest.aReceiver1['name'])
        self.assertTrue(SubmissionTest.receiver_unused['name'] == SubmissionTest.aReceiver2['name'])

        self.assertTrue(len(SubmissionTest.receiver_used['contexts']), 1)
        self.assertTrue(len(SubmissionTest.receiver_unused['contexts']), 1)
Exemplo n.º 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"]))
Exemplo n.º 6
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']))
    def test_001_setup_submission_environment(self):
        helpers.TestGL.setUp(self)
        
        basehandler = MockHandler()

        stuff = u"AAA :P ³²¼½¬¼³²"

        for attrname in Context.localized_strings:
            SubmissionTest.aContext1[attrname] = stuff

        basehandler.validate_jmessage( SubmissionTest.aContext1, adminContextDesc)
        SubmissionTest.context_used = yield admin.create_context(SubmissionTest.aContext1)

        # Correctly, TTip.tipContext has not selectable receiver, and we want test it in the 2nd test
        SubmissionTest.context_used['selectable_receiver'] = True

        for attrname in Context.localized_strings:
            SubmissionTest.context_used[attrname] = stuff

        SubmissionTest.context_used = yield admin.update_context(SubmissionTest.context_used['id'],
            SubmissionTest.context_used)

        basehandler.validate_jmessage( SubmissionTest.aContext2, adminContextDesc)
        SubmissionTest.context_unused = yield admin.create_context(SubmissionTest.aContext2)

        self.assertTrue(len(SubmissionTest.context_used['id']) > 1)
        self.assertTrue(len(SubmissionTest.context_unused['id']) > 1)

        SubmissionTest.aReceiver1['contexts'] = [ SubmissionTest.context_used['id'] ]

        for attrname in Receiver.localized_strings:
            SubmissionTest.aReceiver1[attrname] = stuff * 2
            SubmissionTest.aReceiver2[attrname] = stuff * 4

        basehandler.validate_jmessage( SubmissionTest.aReceiver1, adminReceiverDesc )
        SubmissionTest.receiver_used = yield admin.create_receiver(SubmissionTest.aReceiver1)

        SubmissionTest.aReceiver2['contexts'] = [ SubmissionTest.context_unused['id'] ]
        basehandler.validate_jmessage( SubmissionTest.aReceiver2, adminReceiverDesc )
        SubmissionTest.receiver_unused = yield admin.create_receiver(SubmissionTest.aReceiver2)

        self.assertTrue(SubmissionTest.receiver_used['name'] == SubmissionTest.aReceiver1['name'])
        self.assertTrue(SubmissionTest.receiver_unused['name'] == SubmissionTest.aReceiver2['name'])

        self.assertTrue(len(SubmissionTest.receiver_used['contexts']), 1)
        self.assertTrue(len(SubmissionTest.receiver_unused['contexts']), 1)
Exemplo n.º 8
0
    def fill_data(self):
        yield do_appdata_init()

        receivers_ids = []

        # fill_data/create_receiver
        self.dummyReceiver_1 = yield create_receiver(self.dummyReceiver_1,
                                                     'en')
        receivers_ids.append(self.dummyReceiver_1['id'])
        self.dummyReceiver_2 = yield create_receiver(self.dummyReceiver_2,
                                                     'en')
        receivers_ids.append(self.dummyReceiver_2['id'])

        # fill_data/create_context
        self.dummyContext['receivers'] = receivers_ids
        self.dummyContext = yield create_context(
            copy.deepcopy(self.dummyContext), 'en')

        # fill_data: create field templates
        for idx, field in enumerate(self.dummyFieldTemplates):
            f = yield create_field(copy.deepcopy(field), 'en')
            self.dummyFieldTemplates[idx]['id'] = f['id']

        # fill_data: create fields and associate them to the context steps
        for idx, field in enumerate(self.dummyFields):
            field['is_template'] = False
            if idx <= 2:
                # "Field 1", "Field 2" and "Generalities" are associated to the first step
                field['step_id'] = self.dummyContext['steps'][0]['id']
            else:
                # Name, Surname, Gender" are associated to field "Generalities"
                # "Field 1" and "Field 2" are associated to the first step
                field['fieldgroup_id'] = self.dummyFields[2]['id']

            f = yield create_field(copy.deepcopy(field), 'en')
            self.dummyFields[idx]['id'] = f['id']

        self.dummyContext['steps'][0]['children'] = [
            self.dummyFields[0],  # Field 1
            self.dummyFields[1],  # Field 2
            self.dummyFields[2]  # Generalities
        ]

        yield update_context(self.dummyContext['id'],
                             copy.deepcopy(self.dummyContext), 'en')
Exemplo n.º 9
0
    def fill_data(self):
        yield do_appdata_init()

        receivers_ids = []

        # fill_data/create_receiver
        self.dummyReceiver_1 = yield create_receiver(self.dummyReceiver_1, 'en')
        receivers_ids.append(self.dummyReceiver_1['id'])
        self.dummyReceiver_2 = yield create_receiver(self.dummyReceiver_2, 'en')
        receivers_ids.append(self.dummyReceiver_2['id'])

        # fill_data/create_context
        self.dummyContext['receivers'] = receivers_ids
        self.dummyContext = yield create_context(copy.deepcopy(self.dummyContext), 'en')

        # fill_data: create field templates
        for idx, field in enumerate(self.dummyFieldTemplates):
            f = yield create_field(copy.deepcopy(field), 'en')
            self.dummyFieldTemplates[idx]['id'] = f['id']

        # fill_data: create fields and associate them to the context steps
        for idx, field in enumerate(self.dummyFields):
            field['is_template'] = False
            if idx <= 2:
                # "Field 1", "Field 2" and "Generalities" are associated to the first step
                field['step_id'] = self.dummyContext['steps'][0]['id']
            else:
                # Name, Surname, Gender" are associated to field "Generalities"
                # "Field 1" and "Field 2" are associated to the first step
                field['fieldgroup_id'] = self.dummyFields[2]['id']

            f = yield create_field(copy.deepcopy(field), 'en')
            self.dummyFields[idx]['id'] = f['id']

        self.dummyContext['steps'][0]['children'] = [
            self.dummyFields[0],  # Field 1
            self.dummyFields[1],  # Field 2
            self.dummyFields[2]   # Generalities
        ]

        yield update_context(self.dummyContext['id'], copy.deepcopy(self.dummyContext), 'en')
Exemplo n.º 10
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']))
Exemplo n.º 11
0
    def test_1_setup_submission_environment(self):
        helpers.TestGL.setUp(self)

        basehandler = MockHandler()

        # context creation
        try:
            basehandler.validate_jmessage(SubmissionTest.aContext1, adminContextDesc)
            SubmissionTest.context_used = yield admin.create_context(SubmissionTest.aContext1)
            # Correctly, TTip.tipContext has not selectable receiver, and we want test it in the 2nd test
            SubmissionTest.context_used["selectable_receiver"] = True
            SubmissionTest.context_used = yield admin.update_context(
                SubmissionTest.context_used["context_gus"], SubmissionTest.context_used
            )
            basehandler.validate_jmessage(SubmissionTest.aContext2, adminContextDesc)
            SubmissionTest.context_unused = yield admin.create_context(SubmissionTest.aContext2)
        except Exception as excep:
            log.err("Unable to create context used/unused in UT: %s" % excep.message)
            raise excep

        self.assertTrue(len(SubmissionTest.context_used["context_gus"]) > 1)
        self.assertTrue(len(SubmissionTest.context_unused["context_gus"]) > 1)

        SubmissionTest.aReceiver1["contexts"] = [SubmissionTest.context_used["context_gus"]]
        basehandler.validate_jmessage(SubmissionTest.aReceiver1, adminReceiverDesc)
        SubmissionTest.receiver_used = yield admin.create_receiver(SubmissionTest.aReceiver1)

        SubmissionTest.aReceiver2["contexts"] = [SubmissionTest.context_unused["context_gus"]]
        basehandler.validate_jmessage(SubmissionTest.aReceiver2, adminReceiverDesc)
        SubmissionTest.receiver_unused = yield admin.create_receiver(SubmissionTest.aReceiver2)

        self.assertTrue(SubmissionTest.receiver_used["name"] == SubmissionTest.aReceiver1["name"])
        self.assertTrue(SubmissionTest.receiver_unused["name"] == SubmissionTest.aReceiver2["name"])

        self.assertTrue(len(SubmissionTest.receiver_used["contexts"]), 1)
        self.assertTrue(len(SubmissionTest.receiver_unused["contexts"]), 1)
Exemplo n.º 12
0
    def fill_data(self):
        yield do_appdata_init()

        receivers_ids = []

        # fill_data/create_receiver
        self.dummyReceiver_1 = yield create_receiver(self.dummyReceiver_1)
        receivers_ids.append(self.dummyReceiver_1['id'])
        self.dummyReceiver_2 = yield create_receiver(self.dummyReceiver_2)
        receivers_ids.append(self.dummyReceiver_2['id'])

        # fill_data/create_context
        self.dummyContext['receivers'] = receivers_ids
        self.dummyContext = yield create_context(self.dummyContext)

        # fill_data: create cield templates
        for idx, field in enumerate(self.dummyFieldTemplates):
            f = yield create_field(field, 'en')
            self.dummyFieldTemplates[idx]['id'] = f['id']

        # fill_data: create fields and associate them to the context steps
        for idx, field in enumerate(self.dummyFields):
            field['is_template'] = False
            if idx <= 2:
                # "Field 1", "Field 2" and "Generalities" are associated to the first step
                field['step_id'] = self.dummyContext['steps'][0]['id']
            else:
                # Name, Surname, Gender" are associated to field "Generalities"
                # "Field 1" and "Field 2" are associated to the first step
                field['fieldgroup_id'] = self.dummyFields[2]['id']
               
            f = yield create_field(field, 'en')
            self.dummyFields[idx]['id'] = f['id']

        self.dummyContext['steps'][0]['children'] = [
            self.dummyFields[0], # Field 1
            self.dummyFields[1], # Field 2
            self.dummyFields[2]  # Generalities
        ]

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

        # fill_data/create_submission
        self.dummySubmission['context_id'] = self.dummyContext['id']
        self.dummySubmission['receivers'] = receivers_ids
        self.dummySubmission['wb_steps'] = yield fill_random_fields(self.dummyContext['id'])
        self.dummySubmissionNotFinalized = yield create_submission(self.dummySubmission, finalize=False)
        self.dummySubmission = yield create_submission(self.dummySubmission, finalize=False)

        yield self.emulate_file_upload(self.dummySubmission['id'])
        # fill_data/update_submssion
        submission = yield update_submission(self.dummySubmission['id'], self.dummySubmission, finalize=True)
        # fill_data/create_whistleblower
        self.dummyWBTip = yield create_whistleblower_tip(self.dummySubmission)

        assert self.dummyReceiver_1.has_key('id')
        assert self.dummyReceiver_2.has_key('id')
        assert self.dummyContext.has_key('id')
        assert self.dummySubmission.has_key('id')

        yield delivery_sched.DeliverySchedule().operation()
        yield notification_sched.NotificationSchedule().operation()

        commentCreation = {
            'content': 'comment!',
        }

        messageCreation = {
            'content': 'message!',
        }

        rtips_desc = yield self.get_rtips()

        for rtip_desc in rtips_desc:
            yield rtip.create_comment_receiver(rtip_desc['receiver_id'],
                                               rtip_desc['rtip_id'],
                                               commentCreation)

            yield rtip.create_message_receiver(rtip_desc['receiver_id'],
                                               rtip_desc['rtip_id'],
                                               messageCreation)


        wbtips_desc = yield self.get_wbtips()

        for wbtip_desc in wbtips_desc:
            yield wbtip.create_comment_wb(wbtip_desc['wbtip_id'],
                                          commentCreation)

            for receiver_id in wbtip_desc['wbtip_receivers']:
                yield wbtip.create_message_wb(wbtip_desc['wbtip_id'], receiver_id, messageCreation)

        yield delivery_sched.DeliverySchedule().operation()
        yield notification_sched.NotificationSchedule().operation()