Ejemplo n.º 1
0
        public void GetEnvironmentVariable_Returns_From_Os_If_Set()
        {
            _configManagerMock.GetKeyFromMapping("MG_SOME_VAR", "MG_SOME_VAR");
            _envMock.GetEnvironmentVariable("MG_SOME_VAR", "Hello value");

            var sut = new SecretManager(_envMock.Object, _fileManagerMock.Object, _configManagerMock.Object);

            var result = sut.GetEnvironmentVariable("MG_SOME_VAR");

            Assert.Equal("Hello value", result);
        }
Ejemplo n.º 2
0
        public void GetEnvironmentVariable_Returns_Empty_From_Os()
        {
            _configManagerMock.ConfigReturns(null);
            _configManagerMock.GetKeyFromMapping("MG_SOME_VAR", "MG_SOME_VAR");
            _envMock.GetEnvironmentVariable("MG_SOME_VAR", "");
            var sut = new SecretManager(_envMock.Object, _fileManagerMock.Object, _configManagerMock.Object);

            var result = sut.GetEnvironmentVariable("MG_SOME_VAR");

            Assert.Equal(string.Empty, result);
        }
Ejemplo n.º 3
0
        public void GetEnvironmentVariable_Returns_Empty_If_Not_Set_In_File()
        {
            _configManagerMock.ConfigReturns(new MgConfig {
                EnvFile = "someenv.file"
            });
            _configManagerMock.GetKeyFromMapping("MG_SOME_VAR", "MG_SOME_VAR");
            _envMock.GetEnvironmentVariable("MG_SOME_VAR", string.Empty);
            _fileManagerMock.ReadLines("someenv.file", new[]
            {
                "USERNAME=user",
                "BASE_ITEM=item12"
            });

            var sut = new SecretManager(_envMock.Object, _fileManagerMock.Object, _configManagerMock.Object);

            var result = sut.GetEnvironmentVariable("MG_SOME_VAR");

            Assert.Equal(string.Empty, result);
        }
Ejemplo n.º 4
0
        private string ResolveConfig(string fromConfig, string envKey, string defaultValue)
        {
            if (fromConfig != null)
            {
                if (SecretManager.HasVariable(fromConfig))
                {
                    return(SecretManager.ReplaceVariablesInContent(fromConfig));
                }

                return(fromConfig);
            }

            if (!string.IsNullOrEmpty(envKey))
            {
                return(SecretManager.GetEnvironmentVariable(envKey));
            }

            return(defaultValue);
        }