def _fill_event(self, event_type, trigger, trigger_id):
        """
        Here I'm testing only encrypted_tip because trigger a bigger
        amount of %KeyWords%
        """
        self.assertEqual(event_type, u'encrypted_tip')
        self.assertEqual(trigger, 'Tip')

        if event_type == u'encrypted_tip' and trigger == 'Tip':

            receiver_dict = yield admin.get_receiver(self.createdReceiver['id'])
            context_dict = yield admin.get_context(self.createdContext['id'])
            notif_dict = yield admin.get_notification()

            yield admin.import_memory_variables()
            node_dict = yield admin.admin_serialize_node()

            tip_dict = yield self.get_a_fucking_random_submission()

            self.event = Event(
                type = u'encrypted_tip',
                trigger = 'Tip',
                notification_settings = notif_dict,
                node_info = node_dict,
                receiver_info = receiver_dict,
                context_info = context_dict,
                plugin = None,
                trigger_info = tip_dict,
                trigger_parent = None
            )
Example #2
0
    def _fill_event(self, event_type, trigger, trigger_id):
        """
        Here I'm testing only encrypted_tip because trigger a bigger
        amount of %KeyWords%
        """
        self.assertEqual(event_type, u'encrypted_tip')
        self.assertEqual(trigger, 'Tip')

        if event_type == u'encrypted_tip' and trigger == 'Tip':

            receiver_dict = yield admin.get_receiver(
                self.createdReceiver['id'])
            context_dict = yield admin.get_context(self.createdContext['id'])
            notif_dict = yield admin.get_notification()

            yield admin.import_memory_variables()
            node_dict = yield admin.admin_serialize_node()

            tip_dict = yield self.get_a_fucking_random_submission()

            self.event = Event(type=u'encrypted_tip',
                               trigger='Tip',
                               notification_settings=notif_dict,
                               node_info=node_dict,
                               receiver_info=receiver_dict,
                               context_info=context_dict,
                               plugin=None,
                               trigger_info=tip_dict,
                               trigger_parent=None)
Example #3
0
    def _fill_event_dict(self, event_type, event_trigger):
        """
        A notification is based on the Node, Context and Receiver values,
        that has to be taken from the database.
        """
        receiver_dict = yield admin.get_receiver(self.createdReceiver['id'])
        context_dict = yield admin.get_context(self.createdContext['id'])
        steps_dict = yield admin.get_context_steps(self.createdContext['id'])
        notif_dict = yield admin.notification.get_notification()

        yield admin.import_memory_variables()
        node_dict = yield admin.admin_serialize_node()

        # is a mock 'trigger_info' and 'trigger_parent' at the moment
        self.tip['name'] = ' foo '
        self.tip['size'] = ' 123 '
        self.tip['content_type'] = ' application/javascript '
        self.tip['creation_date'] = context_dict['creation_date']
        self.tip['type'] = ' sorry maker '
        # this is requested in the file cases

        self.event = Event(type = event_type,
                           trigger = event_trigger,
                           notification_settings = notif_dict,
                           node_info = node_dict,
                           receiver_info = receiver_dict,
                           context_info = context_dict,
                steps_info = steps_dict,
                           plugin = None,
                           trigger_info = self.tip,
                           trigger_parent = self.tip )
Example #4
0
    def _fill_event(self, type, trigger, trigger_id):

        if type == u'tip' and trigger == 'Tip':

            receiver_dict = yield admin.get_receiver(self.createdReceiver['receiver_gus'])
            context_dict = yield admin.get_context(self.createdContext['context_gus'])
            notif_dict = yield admin.get_notification()

            yield admin.import_memory_variables()
            node_dict = yield admin.get_node()

            self.event = Event(
                type = u'tip',
                trigger = 'Tip',
                notification_settings = notif_dict,
                node_info = node_dict,
                receiver_info = receiver_dict,
                context_info = context_dict,
                plugin = None,
                trigger_info = {
                   'id': trigger_id,
                   'creation_date': pretty_date_time(datetime_now())
                }
            )

        elif type == u'comment' and trigger == 'Comment':
            raise AssertionError("Not yet managed Mock comments")
        elif type == u'file' and trigger == 'File':
            raise AssertionError("Not yet managed Mock files")
        else:
            raise AssertionError("type and trigger maybe refactored, but you're using it bad")
Example #5
0
    def post(self, rtip_id, compression):
        files_dict = yield download_all_files(self.current_user.user_id,
                                              rtip_id)

        if compression is None:
            compression = 'zipdeflated'

        opts = get_compression_opts(compression)

        node_dict = yield admin.admin_serialize_node(self.request.language)
        receiver_dict = yield get_receiver_from_rtip(rtip_id,
                                                     self.request.language)
        rtip_dict = yield get_rtip_info(rtip_id, self.request.language)
        collection_tip_dict = yield get_collection_info(rtip_id)
        context_dict = yield admin.get_context(rtip_dict['context_id'], 'en')
        notif_dict = yield admin.notification.get_notification(
            self.request.language)

        mock_event = Event(
            type=u'zip_collection',
            trigger='Download',
            node_info=node_dict,
            receiver_info=receiver_dict,
            context_info=context_dict,
            tip_info=rtip_dict,
            subevent_info=collection_tip_dict,
            do_mail=False,
        )

        formatted_coll = Templating().format_template(
            notif_dict['zip_description'], mock_event).encode('utf-8')

        files_dict.append({
            'buf': formatted_coll,
            'name': "COLLECTION_INFO.txt"
        })

        self.set_status(200)

        self.set_header('X-Download-Options', 'noopen')
        self.set_header('Content-Type', 'application/octet-stream')
        self.set_header('Content-Disposition',
                        'attachment; filename=\"%s\"' % opts['filename'])

        if compression in ['zipstored', 'zipdeflated']:
            for data in ZipStream(files_dict, opts['compression_type']):
                self.write(data)

        self.finish()
Example #6
0
    def get_dummy_submission(self, context_id):
        """
        this may works until the content of the fields do not start to be validated. like
        numbers shall contain only number, and not URL.
        This validation would not be implemented in validate_jmessage but in structures.Fields

        need to be enhanced generating appropriate data based on the fields.type
        """
        dummySubmissionDict = {}
        dummySubmissionDict['context_id'] = context_id
        dummySubmissionDict['wb_steps'] = yield fill_random_fields(context_id)
        dummySubmissionDict['receivers'] = (yield get_context(context_id, 'en'))['receivers']
        dummySubmissionDict['files'] = []
        dummySubmissionDict['finalize'] = False

        defer.returnValue(dummySubmissionDict)
Example #7
0
    def get_dummy_submission(self, context_id):
        """
        this may works until the content of the fields do not start to be validated. like
        numbers shall contain only number, and not URL.
        This validation would not be implemented in validate_jmessage but in structures.Fields

        need to be enhanced generating appropriate data based on the fields.type
        """
        dummySubmissionDict = {}
        dummySubmissionDict['context_id'] = context_id
        dummySubmissionDict['receivers'] = (yield get_context(context_id, 'en'))['receivers']
        dummySubmissionDict['files'] = []
        dummySubmissionDict['human_captcha_answer'] = 0
        dummySubmissionDict['wb_steps'] = yield self.fill_random_fields(context_id)

        defer.returnValue(dummySubmissionDict)
Example #8
0
    def post(self, rtip_id, compression):
        files_dict = yield download_all_files(self.current_user.user_id, rtip_id)

        if compression is None:
            compression = 'zipdeflated'

        opts = get_compression_opts(compression)

        node_dict = yield admin.admin_serialize_node(self.request.language)
        receiver_dict = yield get_receiver_from_rtip(rtip_id, self.request.language)
        rtip_dict = yield get_rtip_info(rtip_id, self.request.language)
        collection_tip_dict = yield get_collection_info(rtip_id)
        context_dict = yield admin.get_context(rtip_dict['context_id'], 'en')
        notif_dict = yield admin.notification.get_notification(self.request.language)

        mock_event = Event(
            type=u'zip_collection',
            trigger='Download',
            node_info=node_dict,
            receiver_info=receiver_dict,
            context_info=context_dict,
            tip_info=rtip_dict,
            subevent_info=collection_tip_dict,
            do_mail=False,
        )

        formatted_coll = Templating().format_template(notif_dict['zip_description'], mock_event).encode('utf-8')

        files_dict.append(
            {
               'buf': formatted_coll,
               'name': "COLLECTION_INFO.txt"
            }
        )

        self.set_status(200)

        self.set_header('X-Download-Options', 'noopen')
        self.set_header('Content-Type', 'application/octet-stream')
        self.set_header('Content-Disposition', 'attachment; filename=\"%s\"' % opts['filename'])

        if compression in ['zipstored', 'zipdeflated']:
            for data in ZipStream(files_dict, opts['compression_type']):
                self.write(data)

        self.finish()
Example #9
0
    def test_keywords_conversion(self):
        yield self.perform_full_submission_actions()

        self.receiver_dict = yield admin.get_receiver(self.dummyReceiver_1['id'], 'en')
        self.context_dict = yield admin.get_context(self.dummyContext['id'], 'en')
        self.steps_dict = yield admin.get_context_steps(self.dummyContext['id'], 'en')
        self.notif_dict = yield admin.notification.get_notification('en')
        self.node_dict = yield admin.admin_serialize_node('en')
        self.rtip_dict = self.dummyRTips[0]['itip']

        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 + " / "

        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

            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.context_dict['name'], gentext)
                self.assertSubstring(self.node_dict['public_site'], gentext)
                self.assertSubstring(self.node_dict['hidden_service'], gentext)
Example #10
0
    def post(self, rtip_id, compression):

        files_dict = yield download_all_files(self.current_user.user_id, rtip_id)

        if not files_dict:
            raise errors.DownloadLimitExceeded

        if compression is None:
            compression = 'zipstored'

        opts = get_compression_opts(compression)

        node_dict = yield admin.admin_serialize_node()
        receiver_dict = yield get_receiver_from_rtip(rtip_id)
        rtip_dict = yield get_rtip_info(rtip_id)
        collection_tip_dict = yield get_collection_info(rtip_id)
        context_dict = yield admin.get_context(rtip_dict['context_id'])
        notif_dict = yield admin.get_notification()

        mock_event = Event(
            type = u'zip_collection',
            trigger = 'Download',
            notification_settings = notif_dict,
            node_info = node_dict,
            receiver_info = receiver_dict,
            context_info = context_dict,
            plugin = None,
            trigger_info = collection_tip_dict,
            trigger_parent = rtip_dict
        )

        formatted_coll = Templating().format_template(notif_dict['zip_description'], mock_event).encode('utf-8')
        # log.debug("Generating collection content with: %s" % formatted_coll)
        files_dict.append(
            { 'buf'  : formatted_coll,
              'name' : "COLLECTION_INFO.txt"
            })

        self.set_status(200)

        self.set_header('X-Download-Options', 'noopen')
        self.set_header('Content-Type', 'application/octet-stream')
        self.set_header('Content-Disposition','attachment; filename=\"%s\"' %opts['filename'])

        if compression in ['zipstored', 'zipdeflated']:
            for data in ZipStream(files_dict, opts['compression_type']):
                self.write(data)

        elif compression in ['tar', 'targz', 'tarbz2']:
            collectionstreamer = CollectionStreamer(self)
            tar = tarfile.open("collection." + compression, 'w|'+opts['compression_type'], collectionstreamer)
            for f in files_dict:
                if 'path' in f:
                    try:
                        tar.add(f['path'], f['name'])
                    except (OSError, IOError) as excpd:
                        log.err("OSError while adding %s to files collection: %s" % (f['path'], excpd))

                elif 'buf' in f:
                    tarinfo = tarfile.TarInfo(f['name'])
                    tarinfo.size = len(f['buf'])
                    tar.addfile(tarinfo, StringIO.StringIO(f['buf']))

            tar.close()

        self.finish()