public async Task CertificateObserver_expiredAndexpiringCerts() { if (!this.isSFRuntimePresentOnTestMachine) { return; } var startDateTime = DateTime.Now; ObserverManager.FabricServiceContext = this.context; ObserverManager.FabricClientInstance = new FabricClient(FabricClientRole.User); ObserverManager.TelemetryEnabled = false; ObserverManager.EtwEnabled = false; var obs = new CertificateObserver { IsTestRun = true, }; var commonNamesToObserve = new System.Collections.Generic.List <string> { "MyExpiredCert", // common name of expired cert }; var thumbprintsToObserve = new System.Collections.Generic.List <string> { "1fda27a2923505e47de37db48ff685b049642c25", // thumbprint of valid cert, but warning threshold causes expiring }; obs.DaysUntilAppExpireWarningThreshold = int.MaxValue; obs.DaysUntilClusterExpireWarningThreshold = 14; obs.AppCertificateCommonNamesToObserve = commonNamesToObserve; obs.AppCertificateThumbprintsToObserve = thumbprintsToObserve; obs.SecurityConfiguration = new SecurityConfiguration { SecurityType = SecurityType.None, ClusterCertThumbprintOrCommonName = string.Empty, ClusterCertSecondaryThumbprint = string.Empty, }; await obs.ObserveAsync(this.token).ConfigureAwait(true); // observer ran to completion with no errors... Assert.IsTrue(obs.LastRunDateTime > startDateTime); // observer detected error conditions... Assert.IsTrue(obs.HasActiveFabricErrorOrWarning); // observer did not have any internal errors during run... Assert.IsFalse(obs.IsUnhealthy); obs.Dispose(); ObserverManager.FabricClientInstance.Dispose(); }
public void Successful_CertificateObserver_Run_Cancellation_Via_ObserverManager() { ObserverManager.FabricServiceContext = this.context; ObserverManager.TelemetryEnabled = false; ObserverManager.EtwEnabled = false; ObserverManager.FabricClientInstance = new FabricClient(FabricClientRole.User); var stopWatch = new Stopwatch(); var obs = new CertificateObserver { IsEnabled = true, NodeName = "_Test_0", }; var obsMgr = new ObserverManager(obs) { ApplicationName = "fabric:/TestApp0", }; var objReady = new ManualResetEventSlim(false); stopWatch.Start(); var t = Task.Factory.StartNew(() => { objReady.Set(); obsMgr.StartObservers(); }); objReady?.Wait(); while (!obsMgr.IsObserverRunning && stopWatch.Elapsed.TotalSeconds < 10) { // wait... } stopWatch.Stop(); // Observer is running. Stop it... obsMgr.StopObservers(); Thread.Sleep(5); Assert.IsFalse(obsMgr.IsObserverRunning); obs.Dispose(); objReady?.Dispose(); }
public void CertificateObserver_Constructor_test() { ObserverManager.FabricServiceContext = this.context; ObserverManager.FabricClientInstance = new FabricClient(FabricClientRole.User); ObserverManager.TelemetryEnabled = false; ObserverManager.EtwEnabled = false; var obs = new CertificateObserver(); Assert.IsTrue(obs.ObserverLogger != null); Assert.IsTrue(obs.CsvFileLogger != null); Assert.IsTrue(obs.HealthReporter != null); Assert.IsTrue(obs.ObserverName == ObserverConstants.CertificateObserverName); obs.Dispose(); ObserverManager.FabricClientInstance.Dispose(); }