Skip to content

Update Client.cs #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion csharp-ovh/Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
public static string GenerateSignature(string applicationSecret, string consumerKey,
long currentTimestamp, string method, string target, string data = null)
{
SHA1Managed sha1Hasher = new SHA1Managed();

Check warning on line 231 in csharp-ovh/Client/Client.cs

View workflow job for this annotation

GitHub Actions / build-and-test-ubuntu-latest

'SHA1Managed' is obsolete: 'Derived cryptographic types are obsolete. Use the Create method on the base type instead.'

Check warning on line 231 in csharp-ovh/Client/Client.cs

View workflow job for this annotation

GitHub Actions / build-and-test-ubuntu-latest

'SHA1Managed' is obsolete: 'Derived cryptographic types are obsolete. Use the Create method on the base type instead.'

Check warning on line 231 in csharp-ovh/Client/Client.cs

View workflow job for this annotation

GitHub Actions / build-and-test-ubuntu-latest

'SHA1Managed' is obsolete: 'Derived cryptographic types are obsolete. Use the Create method on the base type instead.'

Check warning on line 231 in csharp-ovh/Client/Client.cs

View workflow job for this annotation

GitHub Actions / build-and-test-ubuntu-latest

'SHA1Managed' is obsolete: 'Derived cryptographic types are obsolete. Use the Create method on the base type instead.'
string toSign =
string.Join("+", applicationSecret, consumerKey, method,
target, data, currentTimestamp);
Expand Down Expand Up @@ -361,7 +361,11 @@
{
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}

if (response.StatusCode == HttpStatusCode.NoContent)
{
return "Success ; Response Status: No Content:204";
}

throw await ExtractExceptionFromHttpResponse(response).ConfigureAwait(false);
}

Expand Down
23 changes: 23 additions & 0 deletions test/PutRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,28 @@ public async Task PUT_with_T_data_and_T_result()
var headers = requestMessage.Headers;
Assert.AreEqual("$1$747cdaf92e412ea434a387e6ff7b20150ee1172f", headers.GetValues(Client.OVH_SIGNATURE_HEADER).First());
}

[Test]
public async Task PUT_with_no_content_result()
{
var testHandler = A.Fake<FakeHttpMessageHandler>(a => a.CallsBaseMethods());
MockAuthTimeCallWithFakeItEasy(testHandler);
A.CallTo(() =>
testHandler.Send(A<HttpRequestMessage>.That.Matches(
r => r.RequestUri.ToString().Contains("/me/contact"))))
.Returns(Responses.PutWith204Response.response_204_message);

var c = ClientFactory.GetClient(testHandler).AsTestable(timeProvider);
var result = await c.PutAsync("/me/contact");
Assert.AreEqual(Responses.PutWith204Response.success_204_response, result);

var contactCall = Fake.GetCalls(testHandler).Where(call =>
call.Method.Name == "Send" &&
call.GetArgument<HttpRequestMessage>("request").RequestUri.ToString().Contains("/me/contact")).First();

var requestMessage = contactCall.GetArgument<HttpRequestMessage>("request");
var headers = requestMessage.Headers;
Assert.AreEqual("$1$5595b180f954de130f8da7a5a4b55adc3d27556f", headers.GetValues(Client.OVH_SIGNATURE_HEADER).First());
}
}
}
6 changes: 6 additions & 0 deletions test/Responses/PutResponses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ public static class Put
public static readonly HttpResponseMessage me_contact_message =
HttpResponseMessageFactory.Create(me_contact_content, HttpStatusCode.OK);
}
public static class PutWith204Response
{
public static readonly string success_204_response = "Success ; Response Status: No Content:204";
public static readonly HttpResponseMessage response_204_message =
HttpResponseMessageFactory.Create(success_204_response, HttpStatusCode.NoContent);
}
}