Loading WindowsDevicePortalWrapper/TestAppXbox/Operations/FiddlerOperation.cs 0 → 100644 +112 −0 Original line number Diff line number Diff line //---------------------------------------------------------------------------------------------- // <copyright file="FiddlerOperation.cs" company="Microsoft Corporation"> // Licensed under the MIT License. See LICENSE.TXT in the project root license information. // </copyright> //---------------------------------------------------------------------------------------------- using System; using System.IO; using System.Threading.Tasks; using Microsoft.Tools.WindowsDevicePortal; namespace XboxWdpDriver { /// <summary> /// Helper for Fiddler related operations /// </summary> public class FiddlerOperation { /// <summary> /// Usage message for this operation /// </summary> private const string FiddlerUsageMessage = "Usage:\n" + " /state:<on or off> [/reboot] [/proxyaddress:<proxy address> /proxyport:<proxy port> /certpath:<path to cert file>]\n" + " Whether to enable or disable Fiddler. Enabling and disabling Fiddler\n" + " requires a reboot. You can specify the /reboot flag to do the reboot\n" + " automatically. If Fiddler is being enabled, proxyaddress and proxyport\n" + " are both required. If Fiddler has not been configured on this console\n" + " previously, then the cert file is also required."; /// <summary> /// Main entry point for handling a Fiddler operation /// </summary> /// <param name="portal">DevicePortal reference for communicating with the device.</param> /// <param name="parameters">Parsed command line parameters.</param> public static void HandleOperation(DevicePortal portal, ParameterHelper parameters) { if (parameters.HasFlag(ParameterHelper.HelpFlag)) { Console.WriteLine(FiddlerUsageMessage); return; } string state = parameters.GetParameterValue("state"); if (string.IsNullOrEmpty(state)) { Console.WriteLine("/state parameter is required."); Console.WriteLine(); Console.WriteLine(FiddlerUsageMessage); return; } bool shouldReboot = parameters.HasFlag("reboot"); try { if (string.Equals(state, "on", StringComparison.OrdinalIgnoreCase)) { string proxyAddress = parameters.GetParameterValue("proxyaddress"); string proxyPort = parameters.GetParameterValue("proxyport"); if (string.IsNullOrEmpty(proxyAddress) || string.IsNullOrEmpty(proxyPort)) { Console.WriteLine("/proxyaddress and /proxyport are required for enabling Fiddler."); Console.WriteLine(); Console.WriteLine(FiddlerUsageMessage); return; } Task fiddlerEnableTask = portal.EnableFiddlerTracing(proxyAddress, proxyPort, parameters.GetParameterValue("certpath")); fiddlerEnableTask.Wait(); Console.WriteLine("Fiddler enabled. This will take effect on the next reboot."); } else if (string.Equals(state, "off", StringComparison.OrdinalIgnoreCase)) { Task fiddlerDisableTask = portal.DisableFiddlerTracing(); fiddlerDisableTask.Wait(); Console.WriteLine("Fiddler disabled. This will take effect on the next reboot."); } else { Console.WriteLine("Unknown state parameter: {0}. Must be 'on' or 'off'.", state); Console.WriteLine(); Console.WriteLine(FiddlerUsageMessage); return; } if (shouldReboot) { Task rebootTask = portal.Reboot(); rebootTask.Wait(); Console.WriteLine("Console rebooting..."); } } catch (AggregateException e) { if (e.InnerException is DevicePortalException) { DevicePortalException innerException = e.InnerException as DevicePortalException; Console.WriteLine(string.Format("Exception encountered: {0}, hr = 0x{1:X} : {2}", innerException.StatusCode, innerException.HResult, innerException.Reason)); } else { Console.WriteLine(string.Format("Unexpected exception encountered: {0}", e.Message)); } return; } } } } No newline at end of file WindowsDevicePortalWrapper/TestAppXbox/Program.cs +15 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,8 @@ namespace XboxWdpDriver "systemPerf\n" + "config\n" + "file\n" + "screenshot"; "screenshot\n" + "fiddler"; /// <summary> /// Usage string Loading Loading @@ -109,6 +110,11 @@ namespace XboxWdpDriver /// Takes a screenshot from the current Xbox One console. /// </summary> ScreenshotOperation, /// <summary> /// Manages enabling and disabling a Fiddler proxy for the console. /// </summary> FiddlerOperation, } /// <summary> Loading Loading @@ -369,6 +375,10 @@ namespace XboxWdpDriver { ScreenshotOperation.HandleOperation(portal, parameters); } else if (operation == OperationType.FiddlerOperation) { FiddlerOperation.HandleOperation(portal, parameters); } else { Console.WriteLine("Successfully connected to console but no operation was specified. \n" + Loading Loading @@ -439,6 +449,10 @@ namespace XboxWdpDriver { return OperationType.ScreenshotOperation; } else if (operation.Equals("fiddler", StringComparison.OrdinalIgnoreCase)) { return OperationType.FiddlerOperation; } throw new Exception("Unknown Operation Type. " + AvailableOperationsText); } Loading WindowsDevicePortalWrapper/TestAppXbox/TestAppXbox.csproj +1 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ <Compile Include="DevicePortalConnection.cs" /> <Compile Include="NetworkShare.cs" /> <Compile Include="Operations\FileOperation.cs" /> <Compile Include="Operations\FiddlerOperation.cs" /> <Compile Include="Operations\ScreenshotOperation.cs" /> <Compile Include="Operations\SettingOperation.cs" /> <Compile Include="Operations\InstallOperation.cs" /> Loading WindowsDevicePortalWrapper/UnitTestProject/Device-VersionTests/XboxOne/XboxOne_rs1_xbox_rel_1608.cs +18 −0 Original line number Diff line number Diff line Loading @@ -596,6 +596,24 @@ namespace Microsoft.Tools.WindowsDevicePortal.Tests Assert.AreEqual(TaskStatus.RanToCompletion, screenshotTask.Status); } /// <summary> /// Simple test of Xbox Fiddler API. /// </summary> public void EnableFiddlerTest() { TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.FiddlerSetupApi, HttpMethods.Post); Task fiddlerEnableTask = TestHelpers.Portal.EnableFiddlerTracing("localhost", "8888"); fiddlerEnableTask.Wait(); Assert.AreEqual(TaskStatus.RanToCompletion, fiddlerEnableTask.Status); Task fiddlerDisableTask = TestHelpers.Portal.DisableFiddlerTracing(); fiddlerDisableTask.Wait(); Assert.AreEqual(TaskStatus.RanToCompletion, fiddlerDisableTask.Status); } /// <summary> /// Validate the <see cref="RunningProcesses" /> returned from the tests. /// </summary> Loading WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/WindowsDevicePortalWrapper.Shared.projitems +1 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ <Compile Include="$(MSBuildThisFileDirectory)Xbox\SmbShare.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Xbox\UserManagement.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Xbox\XboxAppDeployment.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Xbox\FiddlerSetup.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Xbox\XboxMediaCapture.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Xbox\XboxSettings.cs" /> </ItemGroup> Loading Loading
WindowsDevicePortalWrapper/TestAppXbox/Operations/FiddlerOperation.cs 0 → 100644 +112 −0 Original line number Diff line number Diff line //---------------------------------------------------------------------------------------------- // <copyright file="FiddlerOperation.cs" company="Microsoft Corporation"> // Licensed under the MIT License. See LICENSE.TXT in the project root license information. // </copyright> //---------------------------------------------------------------------------------------------- using System; using System.IO; using System.Threading.Tasks; using Microsoft.Tools.WindowsDevicePortal; namespace XboxWdpDriver { /// <summary> /// Helper for Fiddler related operations /// </summary> public class FiddlerOperation { /// <summary> /// Usage message for this operation /// </summary> private const string FiddlerUsageMessage = "Usage:\n" + " /state:<on or off> [/reboot] [/proxyaddress:<proxy address> /proxyport:<proxy port> /certpath:<path to cert file>]\n" + " Whether to enable or disable Fiddler. Enabling and disabling Fiddler\n" + " requires a reboot. You can specify the /reboot flag to do the reboot\n" + " automatically. If Fiddler is being enabled, proxyaddress and proxyport\n" + " are both required. If Fiddler has not been configured on this console\n" + " previously, then the cert file is also required."; /// <summary> /// Main entry point for handling a Fiddler operation /// </summary> /// <param name="portal">DevicePortal reference for communicating with the device.</param> /// <param name="parameters">Parsed command line parameters.</param> public static void HandleOperation(DevicePortal portal, ParameterHelper parameters) { if (parameters.HasFlag(ParameterHelper.HelpFlag)) { Console.WriteLine(FiddlerUsageMessage); return; } string state = parameters.GetParameterValue("state"); if (string.IsNullOrEmpty(state)) { Console.WriteLine("/state parameter is required."); Console.WriteLine(); Console.WriteLine(FiddlerUsageMessage); return; } bool shouldReboot = parameters.HasFlag("reboot"); try { if (string.Equals(state, "on", StringComparison.OrdinalIgnoreCase)) { string proxyAddress = parameters.GetParameterValue("proxyaddress"); string proxyPort = parameters.GetParameterValue("proxyport"); if (string.IsNullOrEmpty(proxyAddress) || string.IsNullOrEmpty(proxyPort)) { Console.WriteLine("/proxyaddress and /proxyport are required for enabling Fiddler."); Console.WriteLine(); Console.WriteLine(FiddlerUsageMessage); return; } Task fiddlerEnableTask = portal.EnableFiddlerTracing(proxyAddress, proxyPort, parameters.GetParameterValue("certpath")); fiddlerEnableTask.Wait(); Console.WriteLine("Fiddler enabled. This will take effect on the next reboot."); } else if (string.Equals(state, "off", StringComparison.OrdinalIgnoreCase)) { Task fiddlerDisableTask = portal.DisableFiddlerTracing(); fiddlerDisableTask.Wait(); Console.WriteLine("Fiddler disabled. This will take effect on the next reboot."); } else { Console.WriteLine("Unknown state parameter: {0}. Must be 'on' or 'off'.", state); Console.WriteLine(); Console.WriteLine(FiddlerUsageMessage); return; } if (shouldReboot) { Task rebootTask = portal.Reboot(); rebootTask.Wait(); Console.WriteLine("Console rebooting..."); } } catch (AggregateException e) { if (e.InnerException is DevicePortalException) { DevicePortalException innerException = e.InnerException as DevicePortalException; Console.WriteLine(string.Format("Exception encountered: {0}, hr = 0x{1:X} : {2}", innerException.StatusCode, innerException.HResult, innerException.Reason)); } else { Console.WriteLine(string.Format("Unexpected exception encountered: {0}", e.Message)); } return; } } } } No newline at end of file
WindowsDevicePortalWrapper/TestAppXbox/Program.cs +15 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,8 @@ namespace XboxWdpDriver "systemPerf\n" + "config\n" + "file\n" + "screenshot"; "screenshot\n" + "fiddler"; /// <summary> /// Usage string Loading Loading @@ -109,6 +110,11 @@ namespace XboxWdpDriver /// Takes a screenshot from the current Xbox One console. /// </summary> ScreenshotOperation, /// <summary> /// Manages enabling and disabling a Fiddler proxy for the console. /// </summary> FiddlerOperation, } /// <summary> Loading Loading @@ -369,6 +375,10 @@ namespace XboxWdpDriver { ScreenshotOperation.HandleOperation(portal, parameters); } else if (operation == OperationType.FiddlerOperation) { FiddlerOperation.HandleOperation(portal, parameters); } else { Console.WriteLine("Successfully connected to console but no operation was specified. \n" + Loading Loading @@ -439,6 +449,10 @@ namespace XboxWdpDriver { return OperationType.ScreenshotOperation; } else if (operation.Equals("fiddler", StringComparison.OrdinalIgnoreCase)) { return OperationType.FiddlerOperation; } throw new Exception("Unknown Operation Type. " + AvailableOperationsText); } Loading
WindowsDevicePortalWrapper/TestAppXbox/TestAppXbox.csproj +1 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ <Compile Include="DevicePortalConnection.cs" /> <Compile Include="NetworkShare.cs" /> <Compile Include="Operations\FileOperation.cs" /> <Compile Include="Operations\FiddlerOperation.cs" /> <Compile Include="Operations\ScreenshotOperation.cs" /> <Compile Include="Operations\SettingOperation.cs" /> <Compile Include="Operations\InstallOperation.cs" /> Loading
WindowsDevicePortalWrapper/UnitTestProject/Device-VersionTests/XboxOne/XboxOne_rs1_xbox_rel_1608.cs +18 −0 Original line number Diff line number Diff line Loading @@ -596,6 +596,24 @@ namespace Microsoft.Tools.WindowsDevicePortal.Tests Assert.AreEqual(TaskStatus.RanToCompletion, screenshotTask.Status); } /// <summary> /// Simple test of Xbox Fiddler API. /// </summary> public void EnableFiddlerTest() { TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.FiddlerSetupApi, HttpMethods.Post); Task fiddlerEnableTask = TestHelpers.Portal.EnableFiddlerTracing("localhost", "8888"); fiddlerEnableTask.Wait(); Assert.AreEqual(TaskStatus.RanToCompletion, fiddlerEnableTask.Status); Task fiddlerDisableTask = TestHelpers.Portal.DisableFiddlerTracing(); fiddlerDisableTask.Wait(); Assert.AreEqual(TaskStatus.RanToCompletion, fiddlerDisableTask.Status); } /// <summary> /// Validate the <see cref="RunningProcesses" /> returned from the tests. /// </summary> Loading
WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/WindowsDevicePortalWrapper.Shared.projitems +1 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ <Compile Include="$(MSBuildThisFileDirectory)Xbox\SmbShare.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Xbox\UserManagement.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Xbox\XboxAppDeployment.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Xbox\FiddlerSetup.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Xbox\XboxMediaCapture.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Xbox\XboxSettings.cs" /> </ItemGroup> Loading