Exemple #1
0
 def test_crypt_file_ok(self):
     crypt = Crypt()
     crypt.generate_key("mypassword", True)
     arguments = ["encrypt", "prueba"]
     cmd = Command(arguments=arguments, autorun=False)
     cmd.run()
     crypt.delete_key()
Exemple #2
0
 def test_crypt_file_ok(self):
     crypt = CryptFernet()
     crypt.generate_key("mypassword", True)
     message = "My crypt message"
     encrypt_message = crypt.encrypt(message)
     assert message == crypt.decrypt(str(encrypt_message, encoding="utf-8"))
     crypt.delete_key()
Exemple #3
0
class FlaskWithEncryptedFernetTests(unittest.TestCase):
    BASE_DIR = os.path.dirname(os.path.abspath(__file__))

    def setUp(self):
        os.environ[CONFIGMAP_FILE_ENVIRONMENT] = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            "config-tests-flask-encrypted-fernet.yml")
        os.environ[CRYPT_FILE_KEY_ENVIRONMENT] = os.path.join(
            self.BASE_DIR, "key.key")
        self.crypt = CryptFernet(path=self.BASE_DIR)
        self.crypt._loader.put_file(
            b"9IXx2F5d5Ob-h5xdCnFSUXhuFKLGRibvLfSbixpcfCw=", "wb")
        ms = MyMicroserviceNoSingleton(path=__file__)
        ms.reload_conf()
        self.app = ms.create_app()
        self.client = self.app.test_client()
        self.assertEqual("Python Microservice With Flask encrypted",
                         self.app.config["APP_NAME"])

    def tearDown(self):
        self.crypt.delete_key()
        del os.environ[CONFIGMAP_FILE_ENVIRONMENT]
        del os.environ[CRYPT_FILE_KEY_ENVIRONMENT]

    def test_fask_fernet(self):
        assert self.app.ms.config.database_url == "http://database-url"
        assert self.app.config["DATABASE_URL"] == "http://database-url"

    def test_fask_fernet_sqlalchemy(self):
        assert self.app.ms.config.SQLALCHEMY_DATABASE_URI == "http://database-url"
        assert self.app.config[
            "SQLALCHEMY_DATABASE_URI"] == "http://database-url"
Exemple #4
0
 def test_generate_file_ok(self, input):
     crypt = Crypt()
     arguments = [
         "create-key",
     ]
     cmd = Command(arguments=arguments, autorun=False)
     cmd.run()
     crypt.delete_key()
Exemple #5
0
 def test_output_key(self, input):
     crypt = Crypt()
     arguments = ["create-key", ]
     cmd = Command(arguments=arguments, autorun=False)
     cmd.run()
     with pytest.raises(FileNotFoundError) as excinfo:
         crypt.delete_key()
     assert "[Errno 2] No such file or directory: 'key.key'" in str(excinfo.value)
Exemple #6
0
 def test_encrypt_conf_deprecated_env(self):
     os.environ[CRYPT_FILE_KEY_ENVIRONMENT_LEGACY] = os.getenv(CRYPT_FILE_KEY_ENVIRONMENT)
     del os.environ[CRYPT_FILE_KEY_ENVIRONMENT]
     crypt = CryptFernet(path=self.BASE_DIR)
     crypt._loader.put_file(b"9IXx2F5d5Ob-h5xdCnFSUXhuFKLGRibvLfSbixpcfCw=", "wb")
     config = get_conf(service=CONFIG_BASE, uppercase=True, crypt=CryptFernet)
     crypt.delete_key()
     assert config.database_url == "http://database-url"
Exemple #7
0
 def test_encrypt_conf(self):
     crypt = CryptFernet(path=self.BASE_DIR)
     crypt._loader.put_file(b"9IXx2F5d5Ob-h5xdCnFSUXhuFKLGRibvLfSbixpcfCw=",
                            "wb")
     config = get_conf(service=CONFIG_BASE,
                       uppercase=True,
                       crypt=CryptFernet)
     crypt.delete_key()
     assert config.database_url == "http://database-url"