From 5d5cb2d29aa9c2365017730c428064067dd3a884 Mon Sep 17 00:00:00 2001 From: Mauricio Scheffer Date: Wed, 1 Nov 2023 07:25:07 +0000 Subject: [PATCH] fix: Prevent invalid negative timestamps getting container logs (#1038) Co-authored-by: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> --- src/Testcontainers/Clients/DockerContainerOperations.cs | 4 ++-- src/Testcontainers/Clients/TestcontainersClient.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Testcontainers/Clients/DockerContainerOperations.cs b/src/Testcontainers/Clients/DockerContainerOperations.cs index 33d7e7d9e..aee7e39b1 100644 --- a/src/Testcontainers/Clients/DockerContainerOperations.cs +++ b/src/Testcontainers/Clients/DockerContainerOperations.cs @@ -69,8 +69,8 @@ public async Task GetExitCodeAsync(string id, CancellationToken ct = defau { ShowStdout = true, ShowStderr = true, - Since = since.TotalSeconds.ToString("0", CultureInfo.InvariantCulture), - Until = until.TotalSeconds.ToString("0", CultureInfo.InvariantCulture), + Since = Math.Max(0, since.TotalSeconds).ToString("0", CultureInfo.InvariantCulture), + Until = Math.Max(0, until.TotalSeconds).ToString("0", CultureInfo.InvariantCulture), Timestamps = timestampsEnabled, }; diff --git a/src/Testcontainers/Clients/TestcontainersClient.cs b/src/Testcontainers/Clients/TestcontainersClient.cs index e122610d4..2714bb0a6 100644 --- a/src/Testcontainers/Clients/TestcontainersClient.cs +++ b/src/Testcontainers/Clients/TestcontainersClient.cs @@ -106,12 +106,12 @@ public Task GetContainerExitCodeAsync(string id, CancellationToken ct = de if (default(DateTime).Equals(since)) { - since = DateTime.MinValue; + since = unixEpoch; } if (default(DateTime).Equals(until)) { - until = DateTime.MaxValue; + until = unixEpoch; } return Container.GetLogsAsync(id, since.ToUniversalTime().Subtract(unixEpoch), until.ToUniversalTime().Subtract(unixEpoch), timestampsEnabled, ct);