Skip to content

Commit 2dc8ef9

Browse files
committed
C#: Address some review comments.
1 parent 8583ecc commit 2dc8ef9

2 files changed

Lines changed: 20 additions & 15 deletions

File tree

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependabotProxy.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,20 @@ private DependabotProxy(IDependabotProxyConfiguration config, ILogger logger, Te
8888
return null;
8989
}
9090

91-
return MakeAux(new DependabotProxyConfiguration(), logger, diagnosticsWriter, tempWorkingDirectory);
91+
return Make(new DependabotProxyConfiguration(), logger, diagnosticsWriter, tempWorkingDirectory);
9292
}
9393

94-
internal static IDependabotProxy? MakeAux(
94+
/// <summary>
95+
/// Creates an instance of the Dependabot proxy using the specified configuration.
96+
/// Returns null if the proxy cannot be created.
97+
/// This overload is exposed primarily to enable platform-independent unit testing.
98+
/// </summary>
99+
internal static IDependabotProxy? Make(
95100
IDependabotProxyConfiguration proxyConfig, ILogger logger, IDiagnosticsWriter diagnosticsWriter, TemporaryDirectory tempWorkingDirectory)
96101
{
97102
if (string.IsNullOrWhiteSpace(proxyConfig.Host) || string.IsNullOrWhiteSpace(proxyConfig.Port))
98103
{
99-
logger.LogInfo("No Dependabot proxy credentials are configured.");
104+
logger.LogDebug("No Dependabot proxy credentials are configured.");
100105
return null;
101106
}
102107

csharp/extractor/Semmle.Extraction.Tests/DependabotProxy.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ public void TestDependabotProxyCreation1()
3434
// Setup
3535
var config = new DependabotConfigurationStub
3636
{
37-
Host = "my.private.server",
37+
Host = "localhost",
3838
Port = "",
3939
};
4040

4141
// Execute
4242
using var tempWorkingDirectory = MakeTemporaryDirectory();
43-
using var proxy = DependabotProxy.MakeAux(config, new LoggerStub(), new DiagnosticsWriterStub(), tempWorkingDirectory);
43+
using var proxy = DependabotProxy.Make(config, new LoggerStub(), new DiagnosticsWriterStub(), tempWorkingDirectory);
4444

4545
// Verify
4646
Assert.Null(proxy);
@@ -57,7 +57,7 @@ public void TestDependabotProxyCreation2()
5757

5858
// Execute
5959
using var tempWorkingDirectory = MakeTemporaryDirectory();
60-
using var proxy = DependabotProxy.MakeAux(config, new LoggerStub(), new DiagnosticsWriterStub(), tempWorkingDirectory);
60+
using var proxy = DependabotProxy.Make(config, new LoggerStub(), new DiagnosticsWriterStub(), tempWorkingDirectory);
6161

6262
// Verify
6363
Assert.Null(proxy);
@@ -103,17 +103,17 @@ public void TestDependabotProxyCertificate()
103103
var config = new DependabotConfigurationStub
104104
{
105105
Port = "8080",
106-
Host = "my.private.server",
106+
Host = "localhost",
107107
Certificate = ExampleCertificate
108108
};
109109

110110
// Execute
111111
using var tempWorkingDirectory = MakeTemporaryDirectory();
112-
using var proxy = DependabotProxy.MakeAux(config, new LoggerStub(), new DiagnosticsWriterStub(), tempWorkingDirectory);
112+
using var proxy = DependabotProxy.Make(config, new LoggerStub(), new DiagnosticsWriterStub(), tempWorkingDirectory);
113113

114114
// Verify
115115
Assert.NotNull(proxy);
116-
Assert.Equal("http://my.private.server:8080", proxy.Address);
116+
Assert.Equal("http://localhost:8080", proxy.Address);
117117
Assert.NotNull(proxy.Certificate);
118118
Assert.NotNull(proxy.CertificatePath);
119119
}
@@ -125,13 +125,13 @@ public void TestDependabotRegistryUrls1()
125125
var config = new DependabotConfigurationStub
126126
{
127127
Port = "8080",
128-
Host = "my.private.server",
128+
Host = "localhost",
129129
RegistryURLs = "Doesn't parse as a JSON list"
130130
};
131131

132132
// Execute
133133
using var tempWorkingDirectory = MakeTemporaryDirectory();
134-
using var proxy = DependabotProxy.MakeAux(config, new LoggerStub(), new DiagnosticsWriterStub(), tempWorkingDirectory);
134+
using var proxy = DependabotProxy.Make(config, new LoggerStub(), new DiagnosticsWriterStub(), tempWorkingDirectory);
135135

136136
// Verify
137137
Assert.NotNull(proxy);
@@ -145,13 +145,13 @@ public void TestDependabotRegistryUrls2()
145145
var config = new DependabotConfigurationStub
146146
{
147147
Port = "8080",
148-
Host = "my.private.server",
148+
Host = "localhost",
149149
RegistryURLs = "[ { \"type\": \"nuget_feed\", \"url\": \"https://nuget.pkg.github.com/org/index.json\" } ]"
150150
};
151151

152152
// Execute
153153
using var tempWorkingDirectory = MakeTemporaryDirectory();
154-
using var proxy = DependabotProxy.MakeAux(config, new LoggerStub(), new DiagnosticsWriterStub(), tempWorkingDirectory);
154+
using var proxy = DependabotProxy.Make(config, new LoggerStub(), new DiagnosticsWriterStub(), tempWorkingDirectory);
155155

156156
// Verify
157157
Assert.NotNull(proxy);
@@ -167,13 +167,13 @@ public void TestDependabotRegistryUrls3()
167167
var config = new DependabotConfigurationStub
168168
{
169169
Port = "8080",
170-
Host = "my.private.server",
170+
Host = "localhost",
171171
RegistryURLs = "[ { \"type\": \"nuget_feed\", \"url\": \"https://example.com/org/index.json\" }, { \"type\": \"wrong_type\", \"url\": \"https://nuget.pkg.github.com/org/index.json\" } ]"
172172
};
173173

174174
// Execute
175175
using var tempWorkingDirectory = MakeTemporaryDirectory();
176-
using var proxy = DependabotProxy.MakeAux(config, new LoggerStub(), new DiagnosticsWriterStub(), tempWorkingDirectory);
176+
using var proxy = DependabotProxy.Make(config, new LoggerStub(), new DiagnosticsWriterStub(), tempWorkingDirectory);
177177

178178
// Verify
179179
Assert.NotNull(proxy);

0 commit comments

Comments
 (0)