Example #1
0
        protected virtual KerberosClient CreateClient(string configValue = null, bool verbose = false)
        {
            Krb5Config config;

            if (configValue != null)
            {
                config = Krb5Config.Parse(configValue);
            }
            else
            {
                config = Krb5Config.CurrentUser(this.ConfigurationPath);
            }

            ILoggerFactory logger = null;

            if (verbose)
            {
                logger = this.IO.CreateVerboseLogger(labels: true);
            }

            return(new KerberosClient(config, logger)
            {
                CacheInMemory = false
            });
        }
        public async Task ConfigRemovesValue()
        {
            var tmpCacheFile = Path.GetTempFileName();

            var config = Krb5Config.Parse(File.ReadAllText(tmpCacheFile));

            Assert.IsFalse(config.Defaults.AllowWeakCrypto);

            try
            {
                string commandLine = $"kconfig --config \"{tmpCacheFile}\" realms.\"example.com\".kdc=foo.com";

                config = await ExecuteCommand(commandLine, tmpCacheFile);

                Assert.AreEqual(1, config.Realms["example.com"].Kdc.Count);
                Assert.AreEqual("foo.com", config.Realms["example.com"].Kdc.First());

                commandLine = $"kconfig --config \"{tmpCacheFile}\" +realms.\"example.com\".kdc=";

                config = await ExecuteCommand(commandLine, tmpCacheFile);

                Assert.AreEqual(0, config.Realms["example.com"].Kdc.Count);
            }
            finally
            {
                TryCleanupTmp(tmpCacheFile);
            }
        }
Example #3
0
        protected virtual KerberosClient CreateClient(string configValue = null, bool verbose = false)
        {
            Krb5Config config;

            if (!string.IsNullOrWhiteSpace(configValue))
            {
                config = Krb5Config.Parse(configValue);
            }
            else
            {
                config = Krb5Config.CurrentUser();
            }

            ILoggerFactory logger = null;

            if (verbose)
            {
                logger = this.CreateVerboseLogger();
            }

            return(new KerberosClient(config, logger)
            {
                CacheInMemory = false
            });
        }
        public async Task ConfigSetsValue()
        {
            using (var tmpConfigFile = new TemporaryFile())
            {
                var config = Krb5Config.Parse(File.ReadAllText(tmpConfigFile.File));
                Assert.IsFalse(config.Defaults.AllowWeakCrypto);

                string commandLine = $"kconfig --config \"{tmpConfigFile.File}\" libdefaults.allow_weak_crypto=true";

                config = await ExecuteCommand(commandLine, tmpConfigFile.File);

                Assert.IsTrue(config.Defaults.AllowWeakCrypto);
            }
        }
        private static async Task <Krb5Config> ExecuteCommand(string commandLine, string tmpCacheFile)
        {
            var io = new InputControl
            {
                Clear     = () => { },
                HookCtrlC = hook => { },
                Writer    = new StringWriter()
            };

            var parameters = CommandLineParameters.Parse(commandLine);

            var command = (KerberosConfigCommand)parameters.CreateCommandExecutor(io);

            await command.Execute();

            return(Krb5Config.Parse(File.ReadAllText(tmpCacheFile)));
        }
        public async Task ConfigSetsValue()
        {
            var tmpCacheFile = Path.GetTempFileName();

            var config = Krb5Config.Parse(File.ReadAllText(tmpCacheFile));

            Assert.IsFalse(config.Defaults.AllowWeakCrypto);

            try
            {
                string commandLine = $"kconfig --config \"{tmpCacheFile}\" libdefaults.allow_weak_crypto=true";

                config = await ExecuteCommand(commandLine, tmpCacheFile);

                Assert.IsTrue(config.Defaults.AllowWeakCrypto);
            }
            finally
            {
                TryCleanupTmp(tmpCacheFile);
            }
        }
        public async Task ConfigRemovesValue()
        {
            using (var tmpConfigFile = new TemporaryFile())
            {
                var config = Krb5Config.Parse(File.ReadAllText(tmpConfigFile.File));
                Assert.IsFalse(config.Defaults.AllowWeakCrypto);

                string commandLine = $"kconfig --config \"{tmpConfigFile.File}\" realms.\"example.com\".kdc=foo.com";

                config = await ExecuteCommand(commandLine, tmpConfigFile.File);

                Assert.AreEqual(1, config.Realms["example.com"].Kdc.Count);
                Assert.AreEqual("foo.com", config.Realms["example.com"].Kdc.First());

                commandLine = $"kconfig --config \"{tmpConfigFile.File}\" +realms.\"example.com\".kdc=";

                config = await ExecuteCommand(commandLine, tmpConfigFile.File);

                Assert.AreEqual(0, config.Realms["example.com"].Kdc.Count);
            }
        }