Skip to content

Commit dfdab46

Browse files
Merge branch 'main' into debug-logging
2 parents 3c8b060 + fea3903 commit dfdab46

File tree

55 files changed

+1748
-51
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1748
-51
lines changed

DevProxy.Abstractions/DevProxy.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<RootNamespace>DevProxy.Abstractions</RootNamespace>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8-
<Version>0.28.0</Version>
8+
<Version>0.29.0</Version>
99
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
1010
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
1111
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

DevProxy.Plugins/DevProxy.Plugins.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Nullable>enable</Nullable>
77
<EnableDynamicLoading>true</EnableDynamicLoading>
88
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
9-
<Version>0.28.0</Version>
9+
<Version>0.29.0</Version>
1010
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
1111
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
1212
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

DevProxy.Plugins/Mocking/MockResponsePlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public sealed class MockResponseConfiguration
3535
[JsonIgnore]
3636
public bool NoMocks { get; set; }
3737
[JsonPropertyName("$schema")]
38-
public string Schema { get; set; } = "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/mockresponseplugin.mocksfile.schema.json";
38+
public string Schema { get; set; } = "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/mockresponseplugin.mocksfile.schema.json";
3939
}
4040

4141
public class MockResponsePlugin(

DevProxy/Commands/CertCommand.cs

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using DevProxy.Abstractions.Utils;
56
using DevProxy.Proxy;
67
using System.CommandLine;
8+
using System.CommandLine.Invocation;
79
using System.CommandLine.Parsing;
10+
using System.Diagnostics;
11+
using Titanium.Web.Proxy.Helpers;
812

913
namespace DevProxy.Commands;
1014

1115
sealed class CertCommand : Command
1216
{
1317
private readonly ILogger _logger;
18+
private readonly Option<bool> _forceOption = new(["--force", "-f"], "Don't prompt for confirmation when removing the certificate");
1419

1520
public CertCommand(ILogger<CertCommand> logger) :
1621
base("cert", "Manage the Dev Proxy certificate")
@@ -25,9 +30,14 @@ private void ConfigureCommand()
2530
var certEnsureCommand = new Command("ensure", "Ensure certificates are setup (creates root if required). Also makes root certificate trusted.");
2631
certEnsureCommand.SetHandler(EnsureCertAsync);
2732

33+
var certRemoveCommand = new Command("remove", "Remove the certificate from Root Store");
34+
certRemoveCommand.SetHandler(RemoveCert);
35+
certRemoveCommand.AddOptions(new[] { _forceOption }.OrderByName());
36+
2837
this.AddCommands(new List<Command>
2938
{
30-
certEnsureCommand
39+
certEnsureCommand,
40+
certRemoveCommand,
3141
}.OrderByName());
3242
}
3343

@@ -48,4 +58,82 @@ private async Task EnsureCertAsync()
4858

4959
_logger.LogTrace("EnsureCertAsync() finished");
5060
}
61+
62+
public void RemoveCert(InvocationContext invocationContext)
63+
{
64+
_logger.LogTrace("RemoveCert() called");
65+
66+
try
67+
{
68+
var isForced = invocationContext.ParseResult.GetValueForOption(_forceOption);
69+
if (!isForced)
70+
{
71+
var isConfirmed = PromptConfirmation("Do you want to remove the root certificate", acceptByDefault: false);
72+
if (!isConfirmed)
73+
{
74+
return;
75+
}
76+
}
77+
78+
_logger.LogInformation("Uninstalling the root certificate...");
79+
80+
RemoveTrustedCertificateOnMac();
81+
ProxyEngine.ProxyServer.CertificateManager.RemoveTrustedRootCertificate(machineTrusted: false);
82+
83+
_logger.LogInformation("DONE");
84+
}
85+
catch (Exception ex)
86+
{
87+
_logger.LogError(ex, "Error removing certificate");
88+
}
89+
finally
90+
{
91+
_logger.LogTrace("RemoveCert() finished");
92+
}
93+
}
94+
95+
private static bool PromptConfirmation(string message, bool acceptByDefault)
96+
{
97+
while (true)
98+
{
99+
Console.Write(message + $" ({(acceptByDefault ? "Y/n" : "y/N")}): ");
100+
var answer = Console.ReadLine();
101+
102+
if (string.IsNullOrWhiteSpace(answer))
103+
{
104+
return acceptByDefault;
105+
}
106+
else if (string.Equals("y", answer, StringComparison.OrdinalIgnoreCase))
107+
{
108+
return true;
109+
}
110+
else if (string.Equals("n", answer, StringComparison.OrdinalIgnoreCase))
111+
{
112+
return false;
113+
}
114+
}
115+
}
116+
117+
private static void RemoveTrustedCertificateOnMac()
118+
{
119+
if (!RunTime.IsMac)
120+
{
121+
return;
122+
}
123+
124+
var bashScriptPath = Path.Join(ProxyUtils.AppFolder, "remove-cert.sh");
125+
var startInfo = new ProcessStartInfo()
126+
{
127+
FileName = "/bin/bash",
128+
Arguments = bashScriptPath,
129+
UseShellExecute = false,
130+
CreateNoWindow = true,
131+
};
132+
133+
using var process = new Process() { StartInfo = startInfo };
134+
_ = process.Start();
135+
process.WaitForExit();
136+
137+
HasRunFlag.Remove();
138+
}
51139
}

DevProxy/DevProxy.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<Nullable>enable</Nullable>
99
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1010
<Title>Dev Proxy</Title>
11-
<Version>0.28.0</Version>
11+
<Version>0.29.0</Version>
1212
<Company>.NET Foundation</Company>
1313
<Product>Dev Proxy</Product>
1414
<AssemblyName>devproxy</AssemblyName>
@@ -64,8 +64,11 @@
6464
<None Update="devproxy-errors.json">
6565
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6666
</None>
67+
<None Update="remove-cert.sh">
68+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
69+
</None>
6770
<None Update="toggle-proxy.sh">
68-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
71+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6972
</None>
7073
<None Update="trust-cert.sh">
7174
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

DevProxy/HasRunFlag.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using DevProxy.Abstractions.Utils;
6+
7+
namespace DevProxy;
8+
9+
static class HasRunFlag
10+
{
11+
private static readonly string filename = Path.Combine(ProxyUtils.AppFolder!, ".hasrun");
12+
13+
public static bool CreateIfMissing()
14+
{
15+
if (File.Exists(filename))
16+
{
17+
return false;
18+
}
19+
20+
return Create();
21+
}
22+
23+
private static bool Create()
24+
{
25+
try
26+
{
27+
File.WriteAllText(filename, "");
28+
}
29+
catch
30+
{
31+
return false;
32+
}
33+
return true;
34+
}
35+
36+
public static void Remove()
37+
{
38+
try
39+
{
40+
if (File.Exists(filename))
41+
{
42+
File.Delete(filename);
43+
}
44+
}
45+
catch { }
46+
}
47+
}

DevProxy/Proxy/ProxyEngine.cs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private void FirstRunSetup()
179179
{
180180
if (!RunTime.IsMac ||
181181
_config.NoFirstRun ||
182-
!IsFirstRun() ||
182+
!HasRunFlag.CreateIfMissing() ||
183183
!_config.InstallCert)
184184
{
185185
return;
@@ -615,23 +615,6 @@ private static void ToggleSystemProxy(ToggleSystemProxyAction toggle, string? ip
615615
process.WaitForExit();
616616
}
617617

618-
private static bool IsFirstRun()
619-
{
620-
var firstRunFilePath = Path.Combine(ProxyUtils.AppFolder!, ".hasrun");
621-
if (File.Exists(firstRunFilePath))
622-
{
623-
return false;
624-
}
625-
626-
try
627-
{
628-
File.WriteAllText(firstRunFilePath, "");
629-
}
630-
catch { }
631-
632-
return true;
633-
}
634-
635618
private static int GetProcessId(TunnelConnectSessionEventArgs e)
636619
{
637620
if (RunTime.IsWindows)

DevProxy/config/m365-mocks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/mockresponseplugin.mocksfile.schema.json",
2+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/mockresponseplugin.mocksfile.schema.json",
33
"mocks": [
44
{
55
"request": {

DevProxy/config/m365.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/rc.schema.json",
2+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/rc.schema.json",
33
"plugins": [
44
{
55
"name": "DevToolsPlugin",
@@ -173,11 +173,11 @@
173173
"https://*.sharepoint-df.*/*_vti_bin/*"
174174
],
175175
"mocksPlugin": {
176-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/mockresponseplugin.schema.json",
176+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/mockresponseplugin.schema.json",
177177
"mocksFile": "m365-mocks.json"
178178
},
179179
"graphRandomErrorsPlugin": {
180-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/graphrandomerrorplugin.schema.json",
180+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/graphrandomerrorplugin.schema.json",
181181
"allowedErrors": [
182182
429,
183183
500,
@@ -189,28 +189,28 @@
189189
"rate": 50
190190
},
191191
"executionSummaryPlugin": {
192-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/executionsummaryplugin.schema.json",
192+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/executionsummaryplugin.schema.json",
193193
"groupBy": "url"
194194
},
195195
"graphMinimalPermissionsPlugin": {
196-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/graphminimalpermissionsplugin.schema.json",
196+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/graphminimalpermissionsplugin.schema.json",
197197
"type": "delegated"
198198
},
199199
"cachingGuidance": {
200-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/cachingguidanceplugin.schema.json",
200+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/cachingguidanceplugin.schema.json",
201201
"cacheThresholdSeconds": 5
202202
},
203203
"latencyPlugin": {
204-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/latencyplugin.schema.json",
204+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/latencyplugin.schema.json",
205205
"minMs": 200,
206206
"maxMs": 10000
207207
},
208208
"devTools": {
209-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/devtoolsplugin.schema.json",
209+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/devtoolsplugin.schema.json",
210210
"preferredBrowser": "Edge"
211211
},
212212
"rateLimiting": {
213-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/ratelimitingplugin.schema.json",
213+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/ratelimitingplugin.schema.json",
214214
"costPerRequest": 2,
215215
"rateLimit": 120,
216216
"retryAfterSeconds": 5

DevProxy/config/microsoft-graph-rate-limiting.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/rc.schema.json",
2+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/rc.schema.json",
33
"plugins": [
44
{
55
"name": "RateLimitingPlugin",

DevProxy/config/microsoft-graph.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/rc.schema.json",
2+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/rc.schema.json",
33
"plugins": [
44
{
55
"name": "GraphSelectGuidancePlugin",
@@ -67,7 +67,7 @@
6767
"https://microsoftgraph.chinacloudapi.cn/beta/*"
6868
],
6969
"graphRandomErrorsPlugin": {
70-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/graphrandomerrorplugin.schema.json",
70+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/graphrandomerrorplugin.schema.json",
7171
"allowedErrors": [
7272
429,
7373
500,
@@ -79,7 +79,7 @@
7979
"rate": 50
8080
},
8181
"executionSummaryPlugin": {
82-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/executionsummaryplugin.schema.json",
82+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/executionsummaryplugin.schema.json",
8383
"groupBy": "url"
8484
},
8585
"labelMode": "text",

DevProxy/config/spo-csom-types.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/minimalcsompermissions.types.schema.json",
2+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/minimalcsompermissions.types.schema.json",
33
"types": {
44
"268004ae-ef6b-4e9b-8425-127220d84719": "Microsoft.Online.SharePoint.TenantAdministration.Tenant",
55
"3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a": "Microsoft.SharePoint.Client.RequestContext"

DevProxy/devproxy-errors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/genericrandomerrorplugin.errorsfile.schema.json",
2+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/genericrandomerrorplugin.errorsfile.schema.json",
33
"errors": [
44
{
55
"request": {

DevProxy/devproxyrc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/rc.schema.json",
2+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/rc.schema.json",
33
"plugins": [
44
{
55
"name": "RetryAfterPlugin",
@@ -17,7 +17,7 @@
1717
"https://jsonplaceholder.typicode.com/*"
1818
],
1919
"genericRandomErrorPlugin": {
20-
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.28.0/genericrandomerrorplugin.schema.json",
20+
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/genericrandomerrorplugin.schema.json",
2121
"errorsFile": "devproxy-errors.json",
2222
"rate": 50
2323
},

0 commit comments

Comments
 (0)