Пример #1
0
    def test_display_id(self):
        id = crypto_util.display_id()
        id_words = id.split()

        self.assertEqual(len(id_words), 2)
        self.assertIn(id_words[0], crypto_util.adjectives)
        self.assertIn(id_words[1], crypto_util.nouns)
Пример #2
0
    def test_genkeypair(self):
        codename = crypto_util.genrandomid()
        filesystem_id = crypto_util.hash_codename(codename)
        journalist_filename = crypto_util.display_id()
        source = db.Source(filesystem_id, journalist_filename)
        db.db_session.add(source)
        db.db_session.commit()
        crypto_util.genkeypair(source.filesystem_id, codename)

        self.assertIsNotNone(crypto_util.getkey(filesystem_id))
Пример #3
0
def generate_code():
    original_journalist_designation = g.source.journalist_designation
    g.source.journalist_designation = crypto_util.display_id()

    for item in g.source.collection:
        item.filename = store.rename_submission(g.sid, item.filename, g.source.journalist_filename)
    db_session.commit()

    flash("The source '%s' has been renamed to '%s'" % (original_journalist_designation, g.source.journalist_designation), "notification")
    return redirect('/col/' + g.sid)
Пример #4
0
def generate_code():
    original_journalist_designation = g.source.journalist_designation
    g.source.journalist_designation = crypto_util.display_id()

    for item in g.source.collection:
        item.filename = store.rename_submission(g.sid, item.filename, g.source.journalist_filename)
    db_session.commit()

    flash("The source '%s' has been renamed to '%s'" % (original_journalist_designation, g.source.journalist_designation), "notification")
    return redirect('/col/' + g.sid)
Пример #5
0
def create():
    sid = crypto_util.hash_codename(session['codename'])

    source = Source(sid, crypto_util.display_id())
    db_session.add(source)
    try:
        db_session.commit()
    except IntegrityError as e:
        app.logger.error("Attempt to create a source with duplicate codename: %s" % (e,))
    else:
        os.mkdir(store.path(sid))

    session['logged_in'] = True
    return redirect(url_for('lookup'))
Пример #6
0
    def regenerate_code():
        original_journalist_designation = g.source.journalist_designation
        g.source.journalist_designation = crypto_util.display_id()

        for item in g.source.collection:
            item.filename = store.rename_submission(
                g.filesystem_id, item.filename, g.source.journalist_filename)
        db_session.commit()

        flash(
            gettext(
                "The source '{original_name}' has been renamed to '{new_name}'"
            ).format(original_name=original_journalist_designation,
                     new_name=g.source.journalist_designation), "notification")
        return redirect(url_for('col.col', filesystem_id=g.filesystem_id))
Пример #7
0
def create():
    sid = crypto_util.hash_codename(session['codename'])

    source = Source(sid, crypto_util.display_id())
    db_session.add(source)
    db_session.commit()

    if os.path.exists(store.path(sid)):
        # if this happens, we're not using very secure crypto
        log.warning("Got a duplicate ID '%s'" % sid)
    else:
        os.mkdir(store.path(sid))

    session['logged_in'] = True
    return redirect(url_for('lookup'))
Пример #8
0
    def regenerate_code():
        original_journalist_designation = g.source.journalist_designation
        g.source.journalist_designation = crypto_util.display_id()

        for item in g.source.collection:
            item.filename = store.rename_submission(
                g.filesystem_id,
                item.filename,
                g.source.journalist_filename)
        db_session.commit()

        flash(gettext(
            "The source '{original_name}' has been renamed to '{new_name}'")
              .format(original_name=original_journalist_designation,
                      new_name=g.source.journalist_designation),
              "notification")
        return redirect(url_for('col.col', filesystem_id=g.filesystem_id))
Пример #9
0
    def test_bulk_download(self):
        sid = 'EQZGCJBRGISGOTC2NZVWG6LILJBHEV3CINNEWSCLLFTUWZJPKJFECLS2NZ4G4U3QOZCFKTTPNZMVIWDCJBBHMUDBGFHXCQ3R'
        source = Source(sid, crypto_util.display_id())
        db_session.add(source)
        db_session.commit()
        files = ['abc1_msg.gpg', 'abc2_msg.gpg']
        filenames = test_setup.setup_test_docs(sid, files)

        rv = self.client.post('/bulk', data=dict(
            action='download',
            sid=sid,
            doc_names_selected=files
        ))

        self.assertEqual(rv.status_code, 200)
        self.assertEqual(rv.content_type, 'application/zip')
        self.assertTrue(zipfile.is_zipfile(StringIO(rv.data)))
    def test_get_zip(self):
        sid = 'EQZGCJBRGISGOTC2NZVWG6LILJBHEV3CINNEWSCLLFTUWZJPKJFECLS2NZ4G4U3QOZCFKTTPNZMVIWDCJBBHMUDBGFHXCQ3R'
        source = Source(sid, crypto_util.display_id())
        db_session.add(source)
        db_session.commit()

        files = ['1-abc1-msg.gpg', '2-abc2-msg.gpg']
        filenames = common.setup_test_docs(sid, files)

        archive = zipfile.ZipFile(store.get_bulk_archive(filenames))

        archivefile_contents = archive.namelist()

        for archived_file, actual_file in zip(archivefile_contents, filenames):
            actual_file_content = open(actual_file).read()
            zipped_file_content = archive.read(archived_file)
            self.assertEquals(zipped_file_content, actual_file_content)
Пример #11
0
def init_source_without_keypair():
    """Initialize a source: create their database record and the
    filesystem directory that stores their submissions & replies.
    Return a source object and their codename string.

    :returns: A 2-tuple. The first entry, the :class:`db.Source`
    initialized. The second, their codename string.
    """
    # Create source identity and database record
    codename = crypto_util.genrandomid()
    filesystem_id = crypto_util.hash_codename(codename)
    journalist_filename = crypto_util.display_id()
    source = db.Source(filesystem_id, journalist_filename)
    db.db_session.add(source)
    db.db_session.commit()
    # Create the directory to store their submissions and replies
    os.mkdir(store.path(source.filesystem_id))

    return source, codename
Пример #12
0
def init_source_without_keypair():
    """Initialize a source: create their database record and the
    filesystem directory that stores their submissions & replies.
    Return a source object and their codename string.

    :returns: A 2-tuple. The first entry, the :class:`db.Source`
    initialized. The second, their codename string.
    """
    # Create source identity and database record
    codename = crypto_util.genrandomid()
    filesystem_id = crypto_util.hash_codename(codename)
    journalist_filename = crypto_util.display_id()
    source = db.Source(filesystem_id, journalist_filename)
    db.db_session.add(source)
    db.db_session.commit()
    # Create the directory to store their submissions and replies
    os.mkdir(store.path(source.filesystem_id))

    return source, codename
Пример #13
0
    def test_bulk_download(self):
        sid = 'EQZGCJBRGISGOTC2NZVWG6LILJBHEV3CINNEWSCLLFTUWZJPKJFECLS2NZ4G4U3QOZCFKTTPNZMVIWDCJBBHMUDBGFHXCQ3R'
        source = Source(sid, crypto_util.display_id())
        db_session.add(source)
        db_session.commit()
        files = ['1-abc1-msg.gpg', '2-abc2-msg.gpg']
        filenames = common.setup_test_docs(sid, files)

        self._login_user()
        rv = self.client.post('/bulk',
                              data=dict(action='download',
                                        sid=sid,
                                        doc_names_selected=files))

        self.assertEqual(rv.status_code, 200)
        self.assertEqual(rv.content_type, 'application/zip')
        self.assertTrue(zipfile.is_zipfile(StringIO(rv.data)))
        self.assertTrue(
            zipfile.ZipFile(StringIO(rv.data)).getinfo(
                os.path.join(source.journalist_filename, files[0])))
Пример #14
0
    def create():
        filesystem_id = crypto_util.hash_codename(session['codename'])

        source = Source(filesystem_id, crypto_util.display_id())
        db_session.add(source)
        try:
            db_session.commit()
        except IntegrityError as e:
            db_session.rollback()
            current_app.logger.error(
                "Attempt to create a source with duplicate codename: %s" %
                (e, ))

            # Issue 2386: don't log in on duplicates
            del session['codename']
            abort(500)
        else:
            os.mkdir(store.path(filesystem_id))

        session['logged_in'] = True
        return redirect(url_for('.lookup'))
Пример #15
0
def generate_code():
    g.source.journalist_designation = crypto_util.display_id()
    db_session.commit()
    return redirect('/col/' + g.sid)