Пример #1
0
    def test_submission_file_delivery_pgp(self):
        new_fields = MockDict().dummyFields
        new_context = MockDict().dummyContext

        new_context['name'] = "Context Name"
        new_context_output = yield create_context(new_context, 'en')
        self.context_assertions(new_context, new_context_output)

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

        yanr = self.get_dummy_receiver("antani1")
        yanr['pgp_key_public'] = unicode(VALID_PGP_KEY1)
        yanr['contexts'] = [new_context_output['id']]
        yanr_output = yield receiver.create_receiver(yanr, 'en')
        self.receiver_assertions(yanr, yanr_output)

        asdr = self.get_dummy_receiver("antani2")
        asdr['pgp_key_public'] = unicode(VALID_PGP_KEY1)
        asdr['contexts'] = [new_context_output['id']]
        asdr_output = yield receiver.create_receiver(asdr, 'en')
        self.receiver_assertions(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['identity_provided'] = False
        new_subm['answers'] = yield self.fill_random_answers(
            new_context_output['id'])

        token = Token('submission')
        token.proof_of_work = False
        yield self.emulate_file_upload(token, 3)

        new_subm_output = yield submission.create_submission(
            token.id, new_subm, False, 'en')

        yield DeliverySchedule().operation()

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

        self.assertTrue(isinstance(ifilist, list))
        self.assertEqual(len(ifilist), 3)

        rfilist = yield self.get_receiverfiles_by_wbtip(new_subm_output['id'])

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

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

        self.assertEqual(rfilist[0]['status'], u"encrypted")
Пример #2
0
    def test_submission_file_delivery_pgp(self):
        new_fields = MockDict().dummyFields
        new_context = MockDict().dummyContext

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

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

        yanr = dict(MockDict().dummyReceiver)
        yanr['name'] = u"Receiver1"
        yanr['pgp_key_public'] = unicode(VALID_PGP_KEY1)
        yanr['contexts'] = [ new_context_output['id']]
        yanr_output = yield create_receiver(yanr, 'en')
        self.receiver_assertions(yanr, yanr_output)

        asdr = dict(MockDict().dummyReceiver)
        asdr['name'] = u"Receiver2"
        asdr['pgp_key_public'] = unicode(VALID_PGP_KEY1)
        asdr['contexts'] = [ new_context_output['id']]
        asdr_output = yield create_receiver(asdr, 'en')
        self.receiver_assertions(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 self.fill_random_answers(new_context_output['id'])

        token = Token('submission')
        yield self.emulate_file_upload(token, 3)

        new_subm_output = yield submission.create_submission(token.id, new_subm, False, '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), 3)

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

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

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

        self.assertEqual(rfilist[0]['status'], u"encrypted" )
Пример #3
0
    def test_handler_update_key(self):
        self.receiver_only_update = dict(MockDict().dummyReceiver)

        self.receiver_only_update['password'] = self.dummyReceiver_1[
            'password']
        self.receiver_only_update['old_password'] = self.dummyReceiver_1[
            'password']
        self.receiver_only_update['gpg_key_armor'] = unicode(VALID_PGP_KEY1)
        self.receiver_only_update[
            'gpg_key_status'] = None  # Test, this field is ignored and set
        self.receiver_only_update['gpg_key_remove'] = False
        handler = self.request(self.receiver_only_update,
                               role='receiver',
                               user_id=self.dummyReceiver_1['id'])
        yield handler.put()
        self.assertEqual(self.responses[0]['gpg_key_fingerprint'],
                         u'CF4A22020873A76D1DCB68D32B25551568E49345')
        self.assertEqual(self.responses[0]['gpg_key_status'], u'enabled')

        self.receiver_only_update['gpg_key_armor'] = unicode(VALID_PGP_KEY2)
        self.receiver_only_update['gpg_key_remove'] = False
        handler = self.request(self.receiver_only_update,
                               role='receiver',
                               user_id=self.dummyReceiver_1['id'])
        yield handler.put()
        self.assertEqual(self.responses[1]['gpg_key_fingerprint'],
                         u'7106D296DA80BCF21A3D93056097CE44FED083C9')
Пример #4
0
    def test_handler_update_key(self):

        self.receiver_only_update = dict(MockDict().dummyReceiver)

        self.receiver_only_update['password'] = self.dummyReceiver_1[
            'password']
        self.receiver_only_update['old_password'] = self.dummyReceiver_1[
            'password']
        self.receiver_only_update['gpg_key_armor'] = unicode(VALID_PGP_KEY)
        self.receiver_only_update[
            'gpg_key_status'] = None  # Test, this field is ignored and set
        self.receiver_only_update['gpg_key_remove'] = False
        handler = self.request(self.receiver_only_update,
                               role='receiver',
                               user_id=self.dummyReceiver_1['id'])
        yield handler.put()
        self.assertEqual(self.responses[0]['gpg_key_fingerprint'],
                         u'CF4A22020873A76D1DCB68D32B25551568E49345')
        self.assertEqual(self.responses[0]['gpg_key_status'],
                         Receiver._gpg_types[1])

        self.receiver_only_update['gpg_key_armor'] = unicode(
            HermesGlobaleaksKey.__doc__)
        self.receiver_only_update['gpg_key_remove'] = False
        handler = self.request(self.receiver_only_update,
                               role='receiver',
                               user_id=self.dummyReceiver_1['id'])
        yield handler.put()
        self.assertEqual(self.responses[1]['gpg_key_fingerprint'],
                         u'12CB52E0D793A11CAF0360F8839B5DED0050B3C1')
Пример #5
0
    def test_load_malformed_key(self):
        self.receiver_only_update = dict(MockDict().dummyReceiver)

        self.receiver_only_update['password'] = self.dummyReceiver_1['password']
        self.receiver_only_update['old_password'] = self.dummyReceiver_1['password']
        self.receiver_only_update['pgp_key_public'] = unicode(VALID_PGP_KEY1).replace('A', 'B')
        self.receiver_only_update['pgp_key_status'] = None # Test, this field is ignored and set
        self.receiver_only_update['pgp_key_remove'] = False
        handler = self.request(self.receiver_only_update, role='receiver', user_id=self.dummyReceiver_1['id'])
        yield self.assertFailure(handler.put(), errors.PGPKeyInvalid)
Пример #6
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()
Пример #7
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)
Пример #8
0
    def test_default_encryption_enable(self):
        self.receiver_only_update = dict(MockDict().dummyReceiver)

        self.receiver_only_update['password'] = self.dummyReceiver_1['password']
        self.receiver_only_update['old_password'] = self.dummyReceiver_1['password']
        self.receiver_only_update['pgp_key_public'] = unicode(VALID_PGP_KEY1)
        self.receiver_only_update['pgp_key_status'] = None # Test, this field is ignored and set
        self.receiver_only_update['pgp_key_remove'] = False
        handler = self.request(self.receiver_only_update, role='receiver', user_id=self.dummyReceiver_1['id'])
        yield handler.put()
        self.assertEqual(self.responses[0]['pgp_key_fingerprint'],
                         u'CF4A22020873A76D1DCB68D32B25551568E49345')
        self.assertEqual(self.responses[0]['pgp_key_status'], u'enabled')

        self.receiver_only_update['pgp_key_public'] = unicode(VALID_PGP_KEY2)
Пример #9
0
    def test_default_encryption_enable(self):

        self.receiver_only_update = dict(MockDict().dummyReceiver)

        self.receiver_only_update['password'] = self.dummyReceiver_1[
            'password']
        self.receiver_only_update['old_password'] = self.dummyReceiver_1[
            'password']
        self.receiver_only_update['gpg_key_armor'] = unicode(VALID_PGP_KEY)
        self.receiver_only_update[
            'gpg_key_status'] = None  # Test, this field is ignored and set
        self.receiver_only_update['gpg_key_remove'] = False
        handler = self.request(self.receiver_only_update,
                               role='receiver',
                               user_id=self.dummyReceiver_1['id'])
        yield handler.put()
        self.assertEqual(self.responses[0]['gpg_key_fingerprint'],
                         u'CF4A22020873A76D1DCB68D32B25551568E49345')
        self.assertEqual(self.responses[0]['gpg_key_status'],
                         Receiver._gpg_types[1])

        self.receiver_only_update['gpg_key_armor'] = unicode(
            HermesGlobaleaksKey.__doc__)
        self.assertEqual(self.responses[0]['gpg_enable_notification'], True)
Пример #10
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")