def test_encrypt(self):
        encrypter = Encrypter()
        encrypted_data = encrypter.encrypt(SUBMISSION_DATA)

        decrypter = Decrypter()
        unencrypted_data = decrypter.decrypt(encrypted_data)

        self.assertEquals(SUBMISSION_DATA["type"], unencrypted_data["type"])
        self.assertEquals(SUBMISSION_DATA["version"], unencrypted_data["version"])
        self.assertEquals(SUBMISSION_DATA["origin"], unencrypted_data["origin"])
        self.assertEquals(SUBMISSION_DATA["survey_id"], unencrypted_data["survey_id"])
        self.assertEquals(SUBMISSION_DATA["collection"], unencrypted_data["collection"])
        self.assertEquals(SUBMISSION_DATA["metadata"], unencrypted_data["metadata"])
        self.assertEquals(SUBMISSION_DATA["paradata"], unencrypted_data["paradata"])
        self.assertEquals(SUBMISSION_DATA["data"], unencrypted_data["data"])
示例#2
0
    def test_encrypt(self):
        encrypter = Encrypter()
        encrypted_data = encrypter.encrypt(SUBMISSION_DATA)

        decrypter = Decrypter()
        unencrypted_data = decrypter.decrypt(encrypted_data)

        self.assertEqual(SUBMISSION_DATA["type"], unencrypted_data["type"])
        self.assertEqual(SUBMISSION_DATA["version"],
                         unencrypted_data["version"])
        self.assertEqual(SUBMISSION_DATA["origin"], unencrypted_data["origin"])
        self.assertEqual(SUBMISSION_DATA["survey_id"],
                         unencrypted_data["survey_id"])
        self.assertEqual(SUBMISSION_DATA["collection"],
                         unencrypted_data["collection"])
        self.assertEqual(SUBMISSION_DATA["metadata"],
                         unencrypted_data["metadata"])
        self.assertEqual(SUBMISSION_DATA["paradata"],
                         unencrypted_data["paradata"])
        self.assertEqual(SUBMISSION_DATA["data"], unencrypted_data["data"])
示例#3
0
    def test_encrypt(self):
        encrypter = Encrypter(TEST_DO_NOT_USE_SR_PRIVATE_SIGNING_KEY,
                              TEST_DO_NOT_USE_SR_PRIVATE_SIGNING_KEY_PASSWORD,
                              TEST_DO_NOT_USE_EQ_SUBMISSION_SDX_PUBLIC_KEY)

        encrypted_data = encrypter.encrypt(SUBMISSION_DATA)

        decrypter = Decrypter()
        unencrypted_data = decrypter.decrypt(encrypted_data)

        self.assertEqual(SUBMISSION_DATA["type"], unencrypted_data["type"])
        self.assertEqual(SUBMISSION_DATA["version"],
                         unencrypted_data["version"])
        self.assertEqual(SUBMISSION_DATA["origin"], unencrypted_data["origin"])
        self.assertEqual(SUBMISSION_DATA["survey_id"],
                         unencrypted_data["survey_id"])
        self.assertEqual(SUBMISSION_DATA["collection"],
                         unencrypted_data["collection"])
        self.assertEqual(SUBMISSION_DATA["metadata"],
                         unencrypted_data["metadata"])
        self.assertEqual(SUBMISSION_DATA["paradata"],
                         unencrypted_data["paradata"])
        self.assertEqual(SUBMISSION_DATA["data"], unencrypted_data["data"])
示例#4
0
 def encrypt_message(self, message):
     encrypter = Encrypter()
     encrypted_message = encrypter.encrypt(message)
     return encrypted_message
示例#5
0
def create_app():  # noqa: C901  pylint: disable=too-complex
    application = Flask(__name__,
                        static_url_path='/s',
                        static_folder='../static')
    application.config.from_object(settings)

    if application.config['EQ_APPLICATION_VERSION']:
        logger.info('starting eq survey runner',
                    version=application.config['EQ_APPLICATION_VERSION'])

    if application.config['EQ_NEW_RELIC_ENABLED']:
        setup_newrelic()

    application.eq = {}
    if application.config['EQ_RABBITMQ_ENABLED']:
        application.eq['submitter'] = RabbitMQSubmitter(
            application.config['EQ_RABBITMQ_URL'],
            application.config['EQ_RABBITMQ_URL_SECONDARY'],
        )

    else:
        application.eq['submitter'] = LogSubmitter()

    application.eq['encrypter'] = Encrypter(
        application.config['EQ_SUBMISSION_SR_PRIVATE_SIGNING_KEY'],
        application.config['EQ_SUBMISSION_SR_PRIVATE_SIGNING_KEY_PASSWORD'],
        application.config['EQ_SUBMISSION_SDX_PUBLIC_KEY'],
    )

    application.eq['database'] = Database(
        application.config['EQ_SERVER_SIDE_STORAGE_DATABASE_URL'],
        application.
        config['EQ_SERVER_SIDE_STORAGE_DATABASE_SETUP_RETRY_COUNT'],
        application.
        config['EQ_SERVER_SIDE_STORAGE_DATABASE_SETUP_RETRY_DELAY_SECONDS'],
    )

    application.eq['session_storage'] = SessionStorage(
        application.eq['database'], )

    setup_secure_cookies(application)

    setup_babel(application)

    application.wsgi_app = AWSReverseProxied(application.wsgi_app)

    add_blueprints(application)

    configure_flask_logging(application)

    login_manager.init_app(application)

    add_safe_health_check(application)

    if application.config['EQ_DEV_MODE']:
        start_dev_mode(application)

    if application.config['EQ_ENABLE_CACHE']:
        cache.init_app(application, config={'CACHE_TYPE': 'simple'})
    else:
        cache.init_app(application)  # Doesnt cache

    # Add theme manager
    application.config['THEME_PATHS'] = os.path.dirname(
        os.path.abspath(__file__))
    Themes(application, app_identifier="surveyrunner")

    @application.before_request
    def before_request():  # pylint: disable=unused-variable
        request_id = str(uuid4())
        logger.new(request_id=request_id)

    @application.after_request
    def apply_caching(response):  # pylint: disable=unused-variable
        for k, v in SECURE_HEADERS.items():
            response.headers[k] = v

        return response

    @application.context_processor
    def override_url_for():  # pylint: disable=unused-variable
        return dict(url_for=versioned_url_for)

    @application.teardown_appcontext
    def shutdown_session(exception=None):  # pylint: disable=unused-variable,unused-argument
        application.eq['database'].remove()

    return application
示例#6
0
    def test_encrypter_raises_error_for_invalid_public_key(self):
        with self.assertRaisesRegex(ValueError, 'Invalid public key'):

            Encrypter(TEST_DO_NOT_USE_SR_PRIVATE_SIGNING_KEY,
                      TEST_DO_NOT_USE_SR_PRIVATE_SIGNING_KEY_PASSWORD, '')
示例#7
0
    def test_encrypter_raises_error_for_invalid_private_key_password(self):
        with self.assertRaisesRegex(ValueError,
                                    'Invalid private key password'):

            Encrypter(TEST_DO_NOT_USE_SR_PRIVATE_SIGNING_KEY, '',
                      TEST_DO_NOT_USE_EQ_SUBMISSION_SDX_PUBLIC_KEY)
示例#8
0
 def encrypt_message(message):
     return Encrypter().encrypt(message)