From 904bd844bda64b5718a4898b0b51c614ecf00888 Mon Sep 17 00:00:00 2001 From: Matt Morrison <3maven@gmail.com> Date: Thu, 18 Feb 2021 17:36:16 -0600 Subject: [PATCH] ISystemOperations.AuthenticateAsync now returns AuthResponse. --- src/Docker.DotNet/Endpoints/ISystemOperations.cs | 2 +- src/Docker.DotNet/Endpoints/SystemOperations.cs | 9 +++++---- test/Docker.DotNet.Tests/ISystemOperations.Tests.cs | 11 +++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Docker.DotNet/Endpoints/ISystemOperations.cs b/src/Docker.DotNet/Endpoints/ISystemOperations.cs index 4de8a8bf4..7c7621f2f 100644 --- a/src/Docker.DotNet/Endpoints/ISystemOperations.cs +++ b/src/Docker.DotNet/Endpoints/ISystemOperations.cs @@ -18,7 +18,7 @@ public interface ISystemOperations /// 204 - No error. /// 500 - Server error. /// - Task AuthenticateAsync(AuthConfig authConfig, CancellationToken cancellationToken = default(CancellationToken)); + Task AuthenticateAsync(AuthConfig authConfig, CancellationToken cancellationToken = default(CancellationToken)); /// /// Get version. diff --git a/src/Docker.DotNet/Endpoints/SystemOperations.cs b/src/Docker.DotNet/Endpoints/SystemOperations.cs index 50179bf0e..f2f83119a 100644 --- a/src/Docker.DotNet/Endpoints/SystemOperations.cs +++ b/src/Docker.DotNet/Endpoints/SystemOperations.cs @@ -16,15 +16,16 @@ internal SystemOperations(DockerClient client) this._client = client; } - public Task AuthenticateAsync(AuthConfig authConfig, CancellationToken cancellationToken = default(CancellationToken)) + public async Task AuthenticateAsync(AuthConfig authConfig, CancellationToken cancellationToken = default(CancellationToken)) { if (authConfig == null) { throw new ArgumentNullException(nameof(authConfig)); } - var data = new JsonRequestContent(authConfig, this._client.JsonSerializer); - - return this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Post, "auth", null, data, cancellationToken); + var data = new JsonRequestContent(authConfig, this._client.JsonSerializer); + + var response = await this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Post, "auth", null, data, cancellationToken).ConfigureAwait(false); + return this._client.JsonSerializer.DeserializeObject(response.Body); } public async Task GetVersionAsync(CancellationToken cancellationToken = default(CancellationToken)) diff --git a/test/Docker.DotNet.Tests/ISystemOperations.Tests.cs b/test/Docker.DotNet.Tests/ISystemOperations.Tests.cs index cd17102f2..8130cb782 100644 --- a/test/Docker.DotNet.Tests/ISystemOperations.Tests.cs +++ b/test/Docker.DotNet.Tests/ISystemOperations.Tests.cs @@ -220,6 +220,17 @@ public async Task PingAsync_Succeeds() await _client.System.PingAsync(); } + [Fact] + public async Task AuthenticateAsync_Succeeds() + { + // The blank config goes to Dockerhub, which allows anonymous + // reads, so the auth will definitely be accepted. This lets + // us check whether we correctly retrieve that acceptance. + var config = new AuthConfig(); + var response = await _client.System.AuthenticateAsync(config); + Assert.Equal("Login Succeeded", response.Status); + } + private class ProgressMessage : IProgress { internal Action _onMessageCalled;