From ed45bebddd82047eee3bd65a4f392c6f36fb1f75 Mon Sep 17 00:00:00 2001 From: Anipik Date: Thu, 9 Apr 2020 19:40:53 -0700 Subject: [PATCH] use localSystem to start the service --- .../tests/ServiceBaseTests.cs | 4 ++-- .../tests/TestServiceProvider.cs | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/libraries/System.ServiceProcess.ServiceController/tests/ServiceBaseTests.cs b/src/libraries/System.ServiceProcess.ServiceController/tests/ServiceBaseTests.cs index 06943d23fe89b5..b472dd970977eb 100644 --- a/src/libraries/System.ServiceProcess.ServiceController/tests/ServiceBaseTests.cs +++ b/src/libraries/System.ServiceProcess.ServiceController/tests/ServiceBaseTests.cs @@ -81,6 +81,7 @@ public void TestOnStartThenStop() controller.WaitForStatus(ServiceControllerStatus.Stopped); } + [ActiveIssue("https://github.com/dotnet/runtime/issues/34801")] [ConditionalFact(nameof(IsProcessElevated))] public void TestOnStartWithArgsThenStop() { @@ -175,9 +176,8 @@ public void TestOnContinueBeforePause() public void LogWritten() { string serviceName = Guid.NewGuid().ToString(); - // The default username for installing the service is NT AUTHORITY\\LocalService which does not have access to EventLog. // If the username is null, then the service is created under LocalSystem Account which have access to EventLog. - var testService = new TestServiceProvider(serviceName, userName: null); + var testService = new TestServiceProvider(serviceName); Assert.True(EventLog.SourceExists(serviceName)); testService.DeleteTestServices(); } diff --git a/src/libraries/System.ServiceProcess.ServiceController/tests/TestServiceProvider.cs b/src/libraries/System.ServiceProcess.ServiceController/tests/TestServiceProvider.cs index 02bdceaba6b590..70ba7213ab748b 100644 --- a/src/libraries/System.ServiceProcess.ServiceController/tests/TestServiceProvider.cs +++ b/src/libraries/System.ServiceProcess.ServiceController/tests/TestServiceProvider.cs @@ -12,7 +12,6 @@ namespace System.ServiceProcess.Tests internal sealed class TestServiceProvider { private const int readTimeout = 60000; - public const string LocalServiceName = "NT AUTHORITY\\LocalService"; private static readonly Lazy s_runningWithElevatedPrivileges = new Lazy( () => new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)); @@ -48,7 +47,6 @@ public NamedPipeClientStream Client public readonly string TestMachineName; public readonly TimeSpan ControlTimeout; public readonly string TestServiceName; - public readonly string Username; public readonly string TestServiceDisplayName; private readonly TestServiceProvider _dependentServices; @@ -65,14 +63,13 @@ public TestServiceProvider() CreateTestServices(); } - public TestServiceProvider(string serviceName, string userName = LocalServiceName) + public TestServiceProvider(string serviceName) { TestMachineName = "."; ControlTimeout = TimeSpan.FromSeconds(120); TestServiceName = serviceName; TestServiceDisplayName = "Test Service " + TestServiceName; - Username = userName; - + // Create the service CreateTestServices(); } @@ -95,7 +92,7 @@ private void CreateTestServices() testServiceInstaller.ServiceName = TestServiceName; testServiceInstaller.DisplayName = TestServiceDisplayName; testServiceInstaller.Description = "__Dummy Test Service__"; - testServiceInstaller.Username = Username; + testServiceInstaller.Username = null; if (_dependentServices != null) {