Beispiel #1
0
    def test_secret_str_no_repr(self):
        """
        Outside of reprs, _SecretStr behaves normally.
        """
        s = _SecretStr("abc")

        assert "'abc'" == repr(s)
    def test_name_overwrite(self, ini):
        """Passsing a specific key name is respected."""
        @environ.config
        class Cfg(object):
            pw = ini.secret(name="password")

        cfg = environ.to_config(Cfg, {})

        assert _SecretStr("foobar") == cfg.pw
    def test_secret_str_censors(self):
        """_SecretStr censors it's __repr__ if its called from another
        __repr__."""
        s = _SecretStr("abc")

        @attr.s
        class Cfg(object):
            s = attr.ib()

        assert "Cfg(s=<SECRET>)" == repr(Cfg(s))
    def test_overwrite_sections(self, ini):
        """The source section can be overwritten."""
        ini.section = "yet_another_section"

        @environ.config
        class Cfg(object):
            password = ini.secret(section="other_secrets")
            secret = ini.secret()

        cfg = environ.to_config(Cfg, {})

        assert _SecretStr("bar%foo") == cfg.password
    def test_nested(self, ini):
        """Prefix building works."""
        @environ.config
        class Cfg(object):
            @environ.config
            class DB(object):
                password = ini.secret()

            db = environ.group(DB)

        cfg = environ.to_config(Cfg, {})

        assert _SecretStr("nested!") == cfg.db.password
    def test_prefix_callable(self):
        """vault_prefix can also be a callable that is called on each entry."""
        fake_environ = {"ABC_PW": "foo"}

        def extract(env):
            assert env == fake_environ
            return "ABC"

        vault = VaultEnvSecrets(vault_prefix=extract)

        @environ.config
        class Cfg(object):
            pw = vault.secret()

        cfg = environ.to_config(Cfg, fake_environ)

        assert _SecretStr("foo") == cfg.pw