From 98e95d9721e54553c886bb2edbf1a4b4dea97b35 Mon Sep 17 00:00:00 2001 From: Anirudh Agnihotry Date: Fri, 10 Apr 2020 08:41:45 -0700 Subject: [PATCH] use localSystem to start the service (#34802) --- .../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 06943d2..b472dd9 100644 --- a/src/libraries/System.ServiceProcess.ServiceController/tests/ServiceBaseTests.cs +++ b/src/libraries/System.ServiceProcess.ServiceController/tests/ServiceBaseTests.cs @@ -81,6 +81,7 @@ namespace System.ServiceProcess.Tests controller.WaitForStatus(ServiceControllerStatus.Stopped); } + [ActiveIssue("https://github.com/dotnet/runtime/issues/34801")] [ConditionalFact(nameof(IsProcessElevated))] public void TestOnStartWithArgsThenStop() { @@ -175,9 +176,8 @@ namespace System.ServiceProcess.Tests 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 02bdcea..70ba721 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 @@ namespace System.ServiceProcess.Tests 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 @@ namespace System.ServiceProcess.Tests 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 @@ namespace System.ServiceProcess.Tests testServiceInstaller.ServiceName = TestServiceName; testServiceInstaller.DisplayName = TestServiceDisplayName; testServiceInstaller.Description = "__Dummy Test Service__"; - testServiceInstaller.Username = Username; + testServiceInstaller.Username = null; if (_dependentServices != null) { -- 2.7.4