Skip to content

Commit a6bdd95

Browse files
Cover the new authorization token methods
1 parent 5aaff20 commit a6bdd95

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

tests/ImageSharp.Web.Tests/TestUtilities/AuthenticatedServerTestBase.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,20 @@ public async Task CanRejectUnauthorizedRequestAsync()
4343
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
4444
}
4545

46-
protected override string AugmentCommand(string command)
46+
protected override async Task<string> AugmentCommandAsync(string command)
4747
{
4848
string uri = this.relativeImageSouce + command;
49-
string token = this.authorizationUtilities.ComputeHMAC(uri, CommandHandling.Sanitize);
49+
string token = await this.GetTokenAsync(uri);
5050
return command + "&" + ImageSharpRequestAuthorizationUtilities.TokenCommand + "=" + token;
5151
}
52+
53+
private async Task<string> GetTokenAsync(string uri)
54+
{
55+
string tokenSync = this.authorizationUtilities.ComputeHMAC(uri, CommandHandling.Sanitize);
56+
string tokenAsync = await this.authorizationUtilities.ComputeHMACAsync(uri, CommandHandling.Sanitize);
57+
58+
Assert.Equal(tokenSync, tokenAsync);
59+
return tokenSync;
60+
}
5261
}
5362
}

tests/ImageSharp.Web.Tests/TestUtilities/ServerTestBase.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public async Task CanProcessAndResolveImageAsync()
5151
IImageFormat format = Configuration.Default.ImageFormatsManager.FindFormatByFileExtension(ext);
5252

5353
// First response
54-
HttpResponseMessage response = await this.HttpClient.GetAsync(url + this.AugmentCommand(this.Fixture.Commands[0]));
54+
HttpResponseMessage response = await this.HttpClient.GetAsync(url + await this.AugmentCommandAsync(this.Fixture.Commands[0]));
5555

5656
Assert.NotNull(response);
5757
Assert.True(response.IsSuccessStatusCode);
@@ -67,7 +67,7 @@ public async Task CanProcessAndResolveImageAsync()
6767
response.Dispose();
6868

6969
// Cached Response
70-
response = await this.HttpClient.GetAsync(url + this.AugmentCommand(this.Fixture.Commands[0]));
70+
response = await this.HttpClient.GetAsync(url + await this.AugmentCommandAsync(this.Fixture.Commands[0]));
7171

7272
Assert.NotNull(response);
7373
Assert.True(response.IsSuccessStatusCode);
@@ -85,7 +85,7 @@ public async Task CanProcessAndResolveImageAsync()
8585
// 304 response
8686
var request = new HttpRequestMessage
8787
{
88-
RequestUri = new Uri(url + this.AugmentCommand(this.Fixture.Commands[0])),
88+
RequestUri = new Uri(url + await this.AugmentCommandAsync(this.Fixture.Commands[0])),
8989
Method = HttpMethod.Get,
9090
};
9191

@@ -108,7 +108,7 @@ public async Task CanProcessAndResolveImageAsync()
108108
// 412 response
109109
request = new HttpRequestMessage
110110
{
111-
RequestUri = new Uri(url + this.AugmentCommand(this.Fixture.Commands[0])),
111+
RequestUri = new Uri(url + await this.AugmentCommandAsync(this.Fixture.Commands[0])),
112112
Method = HttpMethod.Get,
113113
};
114114

@@ -127,8 +127,8 @@ public async Task CanProcessAndResolveImageAsync()
127127
public async Task CanProcessMultipleIdenticalQueriesAsync()
128128
{
129129
string url = this.ImageSource;
130-
string command1 = this.AugmentCommand(this.Fixture.Commands[0]);
131-
string command2 = this.AugmentCommand(this.Fixture.Commands[1]);
130+
string command1 = await this.AugmentCommandAsync(this.Fixture.Commands[0]);
131+
string command2 = await this.AugmentCommandAsync(this.Fixture.Commands[1]);
132132

133133
Task[] tasks = Enumerable.Range(0, 100).Select(i => Task.Run(async () =>
134134
{
@@ -144,6 +144,6 @@ public async Task CanProcessMultipleIdenticalQueriesAsync()
144144
Assert.True(all.IsCompletedSuccessfully);
145145
}
146146

147-
protected virtual string AugmentCommand(string command) => command;
147+
protected virtual Task<string> AugmentCommandAsync(string command) => Task.FromResult(command);
148148
}
149149
}

0 commit comments

Comments
 (0)