Skip to content

Commit 8701195

Browse files
committed
Remove automatic 'source' from Virtual Client Proxy API client.
1 parent 5035150 commit 8701195

14 files changed

Lines changed: 170 additions & 49 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.23
1+
2.0.24

src/VirtualClient/Module.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
<System_Diagnostics_PerformanceCounter_PackageVersion>9.0.3</System_Diagnostics_PerformanceCounter_PackageVersion>
118118

119119
<!-- System.IO.Abstractions -->
120-
<System_IO_Abstractions_PackageVersion>21.0.29</System_IO_Abstractions_PackageVersion>
120+
<System_IO_Abstractions_PackageVersion>22.0.14</System_IO_Abstractions_PackageVersion>
121121

122122
<!-- System.IO.FileSystem.AccessControl -->
123123
<System_IO_FileSystem_AccessControl_PackageVersion>5.0.0</System_IO_FileSystem_AccessControl_PackageVersion>

src/VirtualClient/VirtualClient.Contracts.UnitTests/Proxy/ProxyBlobDescriptorTests.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ public class ProxyBlobDescriptorTests
1515
public void ProxyBlobDescriptorObjectsAreJsonSerializable()
1616
{
1717
ProxyBlobDescriptor descriptor = new ProxyBlobDescriptor(
18-
"VirtualClient",
1918
"Packages",
2019
"any.package.1.2.3.zip",
2120
"anycontainer",
2221
"application/octet-stream",
2322
"utf8",
24-
"/any/path/to/blob");
23+
blobPath: "/any/path/to/blob");
24+
25+
SerializationAssert.IsJsonSerializable<ProxyBlobDescriptor>(descriptor);
26+
27+
descriptor = new ProxyBlobDescriptor(
28+
"Packages",
29+
"any.package.1.2.3.zip",
30+
"anycontainer",
31+
"application/octet-stream",
32+
"utf8",
33+
blobPath: "/any/path/to/blob",
34+
source: "VirtualClient");
2535

2636
SerializationAssert.IsJsonSerializable<ProxyBlobDescriptor>(descriptor);
2737
}

src/VirtualClient/VirtualClient.Contracts.UnitTests/Proxy/VirtualClientProxyApiClientTests.cs

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,27 @@ public void VirtualClientProxyApiClientUsesTheExpectedChunkSizeWhenDefinedInTheA
9090
Assert.AreEqual(expectedChunkSize, this.apiClient.ChunkSize);
9191
}
9292

93+
[Test]
94+
[TestCase("Content", "anyfile.log", "anycontainer", "application/octet-stream", "utf-8", null,
95+
"/api/blobs/anyfile.log?storeType=Content&containerName=anycontainer&contentType=application/octet-stream&contentEncoding=utf-8")]
96+
//
97+
[TestCase("Content", "anyfile.log", "anycontainer", "application/octet-stream", "utf-8", "/any/path/to/blob",
98+
"/api/blobs/anyfile.log?storeType=Content&containerName=anycontainer&contentType=application/octet-stream&contentEncoding=utf-8&blobPath=/any/path/to/blob")]
99+
//
100+
[TestCase("Content", "anyfile.log", "anycontainer", "application/octet-stream", "utf-8", "any/path/to/blob/",
101+
"/api/blobs/anyfile.log?storeType=Content&containerName=anycontainer&contentType=application/octet-stream&contentEncoding=utf-8&blobPath=any/path/to/blob")]
102+
//
103+
[TestCase("Content", "anyfile.log", "anycontainer", "application/octet-stream", "utf-8", "/any/path/to/blob/",
104+
"/api/blobs/anyfile.log?storeType=Content&containerName=anycontainer&contentType=application/octet-stream&contentEncoding=utf-8&blobPath=/any/path/to/blob")]
105+
public void VirtualClientProxyApiClientFormsTheCorrectUriRouteForAGivenDescriptor(string storeType, string blobName, string containerName, string contentType, string contentEncoding, string blobPath, string expectedRoute)
106+
{
107+
string encoding = Encoding.UTF8.WebName;
108+
ProxyBlobDescriptor descriptor = new ProxyBlobDescriptor(storeType, blobName, containerName, contentType, contentEncoding, blobPath);
109+
110+
string actualRoute = VirtualClientProxyApiClient.CreateBlobApiRoute(descriptor);
111+
Assert.AreEqual(expectedRoute, actualRoute);
112+
}
113+
93114
[Test]
94115
[TestCase("VirtualClient", "Content", "anyfile.log", "anycontainer", "application/octet-stream", "utf-8", null,
95116
"/api/blobs/anyfile.log?source=VirtualClient&storeType=Content&containerName=anycontainer&contentType=application/octet-stream&contentEncoding=utf-8")]
@@ -105,23 +126,40 @@ public void VirtualClientProxyApiClientUsesTheExpectedChunkSizeWhenDefinedInTheA
105126
public void VirtualClientProxyApiClientFormsTheCorrectUriRouteForAGivenDescriptor(string source, string storeType, string blobName, string containerName, string contentType, string contentEncoding, string blobPath, string expectedRoute)
106127
{
107128
string encoding = Encoding.UTF8.WebName;
108-
ProxyBlobDescriptor descriptor = new ProxyBlobDescriptor(source, storeType, blobName, containerName, contentType, contentEncoding, blobPath);
129+
ProxyBlobDescriptor descriptor = new ProxyBlobDescriptor(storeType, blobName, containerName, contentType, contentEncoding, blobPath, source);
109130

110131
string actualRoute = VirtualClientProxyApiClient.CreateBlobApiRoute(descriptor);
111132
Assert.AreEqual(expectedRoute, actualRoute);
112133
}
113134

135+
[Test]
136+
[TestCase("Content", "anyfile.log", "anycontainer", "application/octet-stream", "utf-8", null,
137+
"/api/blobs/anyfile.log?api-key=123&chunk-size=10000&storeType=Content&containerName=anycontainer&contentType=application/octet-stream&contentEncoding=utf-8")]
138+
//
139+
[TestCase("Content", "anyfile.log", "anycontainer", "application/octet-stream", "utf-8", "/any/path/to/blob",
140+
"/api/blobs/anyfile.log?api-key=123&chunk-size=10000&storeType=Content&containerName=anycontainer&contentType=application/octet-stream&contentEncoding=utf-8&blobPath=/any/path/to/blob")]
141+
public void VirtualClientProxyApiClientFormsTheCorrectUriRouteForAGivenDescriptor_WhenQueryStringParametersAreProvidedOnTheBaseUri_1(
142+
string storeType, string blobName, string containerName, string contentType, string contentEncoding, string blobPath, string expectedRoute)
143+
{
144+
string encoding = Encoding.UTF8.WebName;
145+
ProxyBlobDescriptor descriptor = new ProxyBlobDescriptor(storeType, blobName, containerName, contentType, contentEncoding, blobPath);
146+
147+
Uri baseUri = new Uri("https://any.proxy.api.endpoint:5000?api-key=123&chunk-size=10000");
148+
string actualRoute = VirtualClientProxyApiClient.CreateBlobApiRoute(descriptor, baseUri.Query);
149+
Assert.AreEqual(expectedRoute, actualRoute);
150+
}
151+
114152
[Test]
115153
[TestCase("VirtualClient", "Content", "anyfile.log", "anycontainer", "application/octet-stream", "utf-8", null,
116154
"/api/blobs/anyfile.log?api-key=123&chunk-size=10000&source=VirtualClient&storeType=Content&containerName=anycontainer&contentType=application/octet-stream&contentEncoding=utf-8")]
117155
//
118156
[TestCase("VirtualClient", "Content", "anyfile.log", "anycontainer", "application/octet-stream", "utf-8", "/any/path/to/blob",
119157
"/api/blobs/anyfile.log?api-key=123&chunk-size=10000&source=VirtualClient&storeType=Content&containerName=anycontainer&contentType=application/octet-stream&contentEncoding=utf-8&blobPath=/any/path/to/blob")]
120-
public void VirtualClientProxyApiClientFormsTheCorrectUriRouteForAGivenDescriptor_WhenQueryStringParametersAreProvidedOnTheBaseUri(
158+
public void VirtualClientProxyApiClientFormsTheCorrectUriRouteForAGivenDescriptor_WhenQueryStringParametersAreProvidedOnTheBaseUri_2(
121159
string source, string storeType, string blobName, string containerName, string contentType, string contentEncoding, string blobPath, string expectedRoute)
122160
{
123161
string encoding = Encoding.UTF8.WebName;
124-
ProxyBlobDescriptor descriptor = new ProxyBlobDescriptor(source, storeType, blobName, containerName, contentType, contentEncoding, blobPath);
162+
ProxyBlobDescriptor descriptor = new ProxyBlobDescriptor(storeType, blobName, containerName, contentType, contentEncoding, blobPath, source);
125163

126164
Uri baseUri = new Uri("https://any.proxy.api.endpoint:5000?api-key=123&chunk-size=10000");
127165
string actualRoute = VirtualClientProxyApiClient.CreateBlobApiRoute(descriptor, baseUri.Query);
@@ -748,16 +786,16 @@ private static ProxyTelemetryMessage CreateMockProxyTelemetryMessage()
748786
};
749787
}
750788

751-
private static ProxyBlobDescriptor GetBlobDescriptor(bool withPath = false)
789+
private static ProxyBlobDescriptor GetBlobDescriptor(bool withPath = false, string withSource = null)
752790
{
753791
return new ProxyBlobDescriptor(
754-
"VirtualClient",
755792
"Packages",
756793
"blobname.1.0.0.zip",
757794
"packages",
758795
"application/octet-stream",
759796
Encoding.UTF8.WebName,
760-
withPath ? "/path/to/blob" : null);
797+
withPath ? "/path/to/blob" : null,
798+
!string.IsNullOrWhiteSpace(withSource) ? withSource : null);
761799
}
762800

763801
private static string GetExpectedBlobPathAndQuery(ProxyBlobDescriptor descriptor, string queryString = null)
@@ -771,13 +809,17 @@ private static string GetExpectedBlobPathAndQuery(ProxyBlobDescriptor descriptor
771809
string expectedBlobPath = descriptor.BlobPath;
772810

773811
string fullQueryString =
774-
$"source={expectedSource}" +
775-
$"&storeType={expectedStoreType}" +
812+
$"storeType={expectedStoreType}" +
776813
$"&containerName={expectedContainerName}" +
777814
$"&contentType={expectedContentType}" +
778815
$"&contentEncoding={expectedContentEncoding}" +
779816
$"{(!string.IsNullOrEmpty(expectedBlobPath) ? $"&blobPath={expectedBlobPath}" : string.Empty)}";
780817

818+
if (!string.IsNullOrWhiteSpace(expectedSource))
819+
{
820+
fullQueryString = $"source={expectedSource}&{fullQueryString}";
821+
}
822+
781823
if (!string.IsNullOrWhiteSpace(queryString))
782824
{
783825
fullQueryString = $"{queryString.Trim('?', '&', '/')}&{fullQueryString}";

src/VirtualClient/VirtualClient.Contracts/Proxy/ProxyBlobDescriptor.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,25 @@ namespace VirtualClient.Contracts.Proxy
1111
/// </summary>
1212
public class ProxyBlobDescriptor
1313
{
14-
/// <summary>
15-
/// The default source to use when interfacing with a proxy API service.
16-
/// </summary>
17-
public const string DefaultSource = "VirtualClient";
18-
1914
/// <summary>
2015
/// Initializes a new instance of the <see cref="ProxyBlobDescriptor"/> class.
2116
/// </summary>
22-
/// <param name="source">The source of the blob upload/download request (e.g. VirtualClient).</param>
2317
/// <param name="storeType">The type of blob/content store (e.g. Content, Packages).</param>
2418
/// <param name="blobName">The name of the blob including its path (e.g. anyblob.zip, /any/path/to/the/blob/anyblob.zip).</param>
2519
/// <param name="containerName">The name of the blob container.</param>
2620
/// <param name="contentType">The MIME type of content (e.g. application/json).</param>
2721
/// <param name="contentEncoding">The web encoding for the content (e.g. UTF-8 -> Encoding.UTF8.WebName).</param>
2822
/// <param name="blobPath">An optional path/virtual path to where the blob should be stored. This is equivalent to a directory path.</param>
29-
public ProxyBlobDescriptor(string source, string storeType, string blobName, string containerName, string contentType, string contentEncoding, string blobPath = null)
23+
/// <param name="source">The source of the blob upload/download request (e.g. VirtualClient).</param>
24+
public ProxyBlobDescriptor(string storeType, string blobName, string containerName, string contentType, string contentEncoding, string blobPath = null, string source = null)
3025
{
31-
source.ThrowIfNullOrWhiteSpace(nameof(source));
3226
storeType.ThrowIfNullOrWhiteSpace(nameof(storeType));
3327
blobName.ThrowIfNullOrWhiteSpace(nameof(blobName));
3428
containerName.ThrowIfNullOrWhiteSpace(nameof(containerName));
3529
contentType.ThrowIfNullOrWhiteSpace(nameof(contentType));
3630
contentEncoding.ThrowIfNullOrWhiteSpace(nameof(contentEncoding));
3731

38-
this.Source = source.Trim();
32+
this.Source = source?.Trim();
3933
this.StoreType = storeType.Trim();
4034
this.BlobName = blobName.Trim();
4135
this.BlobPath = blobPath?.Trim()?.TrimEnd('/');

src/VirtualClient/VirtualClient.Contracts/Proxy/VirtualClientProxyApiClient.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,17 @@ public static string CreateBlobApiRoute(ProxyBlobDescriptor descriptor, string q
103103
// With API key
104104
// /api/blobs/anyfile.log?api-key=1234&source=VirtualClient&storeType=Content&containerName=A57214DC-41BA-4211-956D-07095275D73D&contentType=application/octet-stream&contentEncoding=utf-8&blobPath=/any/path/to/blob
105105

106-
string fullQueryString = $"source={descriptor.Source}" +
107-
$"&storeType={descriptor.StoreType}" +
106+
string fullQueryString =
107+
$"storeType={descriptor.StoreType}" +
108108
$"&containerName={descriptor.ContainerName}" +
109109
$"&contentType={descriptor.ContentType}" +
110110
$"&contentEncoding={descriptor.ContentEncoding}";
111111

112+
if (!string.IsNullOrWhiteSpace(descriptor.Source))
113+
{
114+
fullQueryString = $"source={descriptor.Source}&{fullQueryString}";
115+
}
116+
112117
if (!string.IsNullOrWhiteSpace(descriptor.BlobPath))
113118
{
114119
fullQueryString += $"&blobPath={descriptor.BlobPath}";

src/VirtualClient/VirtualClient.Core.UnitTests/Proxy/ProxyBlobManagerTests.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Task ProxyBlobManagerDownloadsUseTheExpectedSourceWhenAnExplicitSourceIsS
9393
}
9494

9595
[Test]
96-
public Task ProxyBlobManagerDownloadsUseTheExpectedSourceWhenAnExplicitSourceIsNotSupplied()
96+
public Task ProxyBlobManagerDownloadsHandlesCasesWhenAnExplicitSourceIsNotSupplied()
9797
{
9898
using (MemoryStream stream = new MemoryStream())
9999
{
@@ -115,7 +115,7 @@ public Task ProxyBlobManagerDownloadsUseTheExpectedSourceWhenAnExplicitSourceIsN
115115
.Callback<ProxyBlobDescriptor, Stream, CancellationToken, IAsyncPolicy<HttpResponseMessage>>((blobDescriptor, stream, token, retryPolicy) =>
116116
{
117117
Assert.IsNotNull(blobDescriptor);
118-
Assert.AreEqual(ProxyBlobDescriptor.DefaultSource, blobDescriptor.Source);
118+
Assert.IsNull(blobDescriptor.Source);
119119
})
120120
.ReturnsAsync(this.mockFixture.CreateHttpResponse(System.Net.HttpStatusCode.OK));
121121

@@ -145,7 +145,7 @@ public Task ProxyBlobManagerDownloadsTheExpectedBlobThroughTheProxyApi_Scenario1
145145
.Callback<ProxyBlobDescriptor, Stream, CancellationToken, IAsyncPolicy<HttpResponseMessage>>((blobDescriptor, stream, token, retryPolicy) =>
146146
{
147147
Assert.IsNotNull(blobDescriptor);
148-
Assert.AreEqual("VirtualClient", blobDescriptor.Source);
148+
Assert.IsNull(blobDescriptor.Source);
149149
Assert.AreEqual(this.mockPackagesStore.StoreName, blobDescriptor.StoreType);
150150
Assert.AreEqual("anypackage.1.0.0.zip", blobDescriptor.BlobName);
151151
Assert.AreEqual("packages", blobDescriptor.ContainerName);
@@ -182,7 +182,7 @@ public Task ProxyBlobManagerDownloadsTheExpectedBlobThroughTheProxyApi_Scenario2
182182
.Callback<ProxyBlobDescriptor, Stream, CancellationToken, IAsyncPolicy<HttpResponseMessage>>((blobDescriptor, stream, token, retryPolicy) =>
183183
{
184184
Assert.IsNotNull(blobDescriptor);
185-
Assert.AreEqual("VirtualClient", blobDescriptor.Source);
185+
Assert.IsNull(blobDescriptor.Source);
186186
Assert.AreEqual(this.mockPackagesStore.StoreName, blobDescriptor.StoreType);
187187
Assert.AreEqual("anypackage.1.0.0.zip", blobDescriptor.BlobName);
188188
Assert.AreEqual("application/octet-stream", blobDescriptor.ContentType);
@@ -253,7 +253,7 @@ public Task ProxyBlobManagerUploadsUseTheExpectedSourceWhenAnExplicitSourceIsSup
253253
}
254254

255255
[Test]
256-
public Task ProxyBlobManagerUploadsUseTheExpectedSourceWhenAnExplicitSourceIsNotSupplied()
256+
public Task ProxyBlobManagerUploadsHandlesCasesWhenAnExplicitSourceIsNotSupplied()
257257
{
258258
using (MemoryStream stream = new MemoryStream())
259259
{
@@ -275,7 +275,7 @@ public Task ProxyBlobManagerUploadsUseTheExpectedSourceWhenAnExplicitSourceIsNot
275275
.Callback<ProxyBlobDescriptor, Stream, CancellationToken, IAsyncPolicy<HttpResponseMessage>>((blobDescriptor, stream, token, retryPolicy) =>
276276
{
277277
Assert.IsNotNull(blobDescriptor);
278-
Assert.AreEqual(ProxyBlobDescriptor.DefaultSource, blobDescriptor.Source);
278+
Assert.IsNull(blobDescriptor.Source);
279279
})
280280
.ReturnsAsync(this.mockFixture.CreateHttpResponse(System.Net.HttpStatusCode.OK));
281281

@@ -305,7 +305,7 @@ public Task ProxyBlobManagerUploadsABlobAsExpectedThroughTheProxyApi_Scenario1()
305305
.Callback<ProxyBlobDescriptor, Stream, CancellationToken, IAsyncPolicy<HttpResponseMessage>>((blobDescriptor, stream, token, retryPolicy) =>
306306
{
307307
Assert.IsNotNull(blobDescriptor);
308-
Assert.AreEqual("VirtualClient", blobDescriptor.Source);
308+
Assert.IsNull(blobDescriptor.Source);
309309
Assert.AreEqual(this.mockContentStore.StoreName, blobDescriptor.StoreType);
310310
Assert.AreEqual("anyfile.log", blobDescriptor.BlobName);
311311
Assert.AreEqual("logs", blobDescriptor.ContainerName);
@@ -340,7 +340,7 @@ public Task ProxyBlobManagerUploadsABlobAsExpectedThroughTheProxyApi_Scenario2()
340340
.Callback<ProxyBlobDescriptor, Stream, CancellationToken, IAsyncPolicy<HttpResponseMessage>>((blobDescriptor, stream, token, retryPolicy) =>
341341
{
342342
Assert.IsNotNull(blobDescriptor);
343-
Assert.AreEqual("VirtualClient", blobDescriptor.Source);
343+
Assert.IsNull(blobDescriptor.Source);
344344
Assert.AreEqual(this.mockContentStore.StoreName, blobDescriptor.StoreType);
345345
Assert.AreEqual("anyfile.log", blobDescriptor.BlobName);
346346
Assert.AreEqual("/any/path/to/blob", blobDescriptor.BlobPath);
@@ -378,7 +378,7 @@ public Task ProxyBlobManagerUploadsABlobAsExpectedThroughTheProxyApi_Scenario3()
378378
.Callback<ProxyBlobDescriptor, Stream, CancellationToken, IAsyncPolicy<HttpResponseMessage>>((blobDescriptor, stream, token, retryPolicy) =>
379379
{
380380
Assert.IsNotNull(blobDescriptor);
381-
Assert.AreEqual("VirtualClient", blobDescriptor.Source);
381+
Assert.IsNull(blobDescriptor.Source);
382382
Assert.AreEqual(this.mockContentStore.StoreName, blobDescriptor.StoreType);
383383
Assert.AreEqual("anyfile.log", blobDescriptor.BlobName);
384384
Assert.AreEqual("logs", blobDescriptor.ContainerName);
@@ -401,9 +401,11 @@ public Task ProxyBlobManagerUploadsABlobAsExpectedThroughTheProxyApi_Scenario4()
401401
["Name"] = "/any/path/to/blob/anyfile.log",
402402
["ContainerName"] = "logs",
403403
["ContentType"] = "application/octet-stream",
404-
["ContentEncoding"] = Encoding.ASCII.WebName
404+
["ContentEncoding"] = Encoding.ASCII.WebName,
405+
["Source"] = "VirtualClient"
405406
});
406407

408+
407409
ProxyBlobManager blobManager = new ProxyBlobManager(this.mockContentStore, this.mockProxyApiClient.Object);
408410

409411
this.mockProxyApiClient
@@ -415,7 +417,7 @@ public Task ProxyBlobManagerUploadsABlobAsExpectedThroughTheProxyApi_Scenario4()
415417
.Callback<ProxyBlobDescriptor, Stream, CancellationToken, IAsyncPolicy<HttpResponseMessage>>((blobDescriptor, stream, token, retryPolicy) =>
416418
{
417419
Assert.IsNotNull(blobDescriptor);
418-
Assert.AreEqual("VirtualClient", blobDescriptor.Source);
420+
Assert.IsNull(blobDescriptor.Source);
419421
Assert.AreEqual(this.mockContentStore.StoreName, blobDescriptor.StoreType);
420422
Assert.AreEqual("anyfile.log", blobDescriptor.BlobName);
421423
Assert.AreEqual("/any/path/to/blob", blobDescriptor.BlobPath);

0 commit comments

Comments
 (0)