Inheritance: IDisposable
Beispiel #1
0
        public void ParseFileRoundTrip()
        {
            using (var tmp = new TemporaryFile())
                using (var cache = new Krb5TicketCache(tmp.File))
                {
                    Assert.IsNotNull(cache);

                    cache.Add(CreateCacheEntry());

                    using (var secondCache = new Krb5TicketCache(tmp.File))
                    {
                        var entry = secondCache.GetCacheItem <KerberosClientCacheEntry>("krbtgt/bar.com");

                        Assert.IsNotNull(entry.KdcResponse);
                        Assert.AreEqual("bar.com", entry.KdcResponse.CRealm);
                        Assert.AreEqual("*****@*****.**", entry.KdcResponse.CName.FullyQualifiedName);
                    }
                }
        }
Beispiel #2
0
        public void CanConcurrentReadAndWriteCacheFile()
        {
            using (var tmp = new TemporaryFile())
            {
                Parallel.For(0, 1000, i =>
                {
                    using (var cache = new Krb5TicketCache(tmp.File))
                    {
                        var key = $"krbtgt/IPA-{i}.IDENTITYINTERVENTION.COM";

                        cache.Add(CreateCacheEntry(key));

                        var item = cache.GetCacheItem(key);

                        Assert.IsNotNull(item);
                    }
                });
            }
        }
        public async Task KinitExecutes()
        {
            var port = NextPort();

            using (var tmpCacheFile = new TemporaryFile())
                using (var tmpConfigFile = new TemporaryFile())
                {
                    var config = Krb5Config.Default();

                    File.WriteAllText(tmpConfigFile.File, config.Serialize());

                    using (var listener = StartTcpListener(port))
                    {
                        _ = listener.Start();

                        var reader = new CommandLineAutoReader();

                        var io = new InputControl
                        {
                            Clear      = () => { },
                            HookCtrlC  = hook => { },
                            ResetColor = () => { },
                            SetColor   = c => { },
                            Reader     = reader,
                            Writer     = new StringWriter(),
                            ReadKey    = () => ReadKey(reader)
                        };

                        var command = CreateCommand($"127.0.0.1:{port}", AdminAtCorpUserName, tmpCacheFile.File, tmpConfigFile.File, io);

                        reader.QueueNext(FakeAdminAtCorpPassword + "\n");

                        await command.Execute();

                        var output = io.Writer.ToString();

                        Assert.IsTrue(output.Contains("Ticket Count: 1"));
                        Assert.IsTrue(output.Contains("client : administrator", StringComparison.OrdinalIgnoreCase), output);
                    }
                }
        }
Beispiel #4
0
        public void Version3DefaultsCorrectly()
        {
            using (var tmp = new TemporaryFile())
            {
                var config = Krb5Config.Default();

                config.Defaults.CCacheType        = 3;
                config.Defaults.DefaultCCacheName = tmp.File;

                using (var client = new KerberosClient(config)
                {
                    CacheInMemory = false
                })
                {
                    var cache = client.Cache as Krb5TicketCache;

                    Assert.IsNotNull(cache);
                    Assert.AreEqual(3, cache.Version);
                }
            }
        }
        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);
            }
        }
Beispiel #6
0
        public void Version3Roundtrips()
        {
            var key = $"krbtgt/IPA.IDENTITYINTERVENTION.COM";

            using (var tmp = new TemporaryFile())
            {
                using (var cache = new Krb5TicketCache(tmp.File)
                {
                    Version = 3
                })
                {
                    cache.Add(CreateCacheEntry(key));
                }

                using (var cache = new Krb5TicketCache(tmp.File))
                {
                    Assert.AreEqual(3, cache.Version);

                    var item = cache.GetCacheItem(key);

                    Assert.IsNotNull(item);
                }
            }
        }