Skip to content

Commit 90a13a6

Browse files
authored
Fix SFTP file UTC time handling (#356)
* Improved SFTP file UTC time handling
1 parent c10277f commit 90a13a6

17 files changed

+144
-49
lines changed

src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_PartialSuccessLimitReachedFollowedBySuccessInAlternateBranch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,4 @@ public void AuthenticateOnPublicKeyAuthenticationMethodShouldHaveBeenInvokedTwic
181181
PublicKeyAuthenticationMethodMock.Verify(p => p.Authenticate(SessionMock.Object), Times.Exactly(2));
182182
}
183183
}
184-
}
184+
}

src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,10 +1506,12 @@ public void DefaultCtorWorks()
15061506
Assert.AreEqual("0", a.ToString(), "#4");
15071507

15081508
a = new BigInteger();
1509+
#pragma warning disable CS1718 // Comparison made to same variable
15091510
Assert.AreEqual(true, a == a, "#5");
15101511

15111512
a = new BigInteger();
15121513
Assert.AreEqual(false, a < a, "#6");
1514+
#pragma warning restore CS1718 // Comparison made to same variable
15131515

15141516
a = new BigInteger();
15151517
Assert.AreEqual(true, a < 10L, "#7");

src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelExtendedDataMessageTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void ChannelExtendedDataMessageConstructorTest()
3030
[Ignore] // placeholder
3131
public void ChannelExtendedDataMessageConstructorTest1()
3232
{
33-
uint localChannelNumber = 0; // TODO: Initialize to an appropriate value
33+
//uint localChannelNumber = 0; // TODO: Initialize to an appropriate value
3434
//ChannelExtendedDataMessage target = new ChannelExtendedDataMessage(localChannelNumber, null, null);
3535
Assert.Inconclusive("TODO: Implement code to verify target");
3636
}

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTestBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public void SetUp()
3838

3939
protected static SftpFileAttributes CreateSftpFileAttributes(long size)
4040
{
41-
return new SftpFileAttributes(default(DateTime), default(DateTime), size, default(int), default(int), default(uint), null);
41+
var utcDefault = DateTime.SpecifyKind(default(DateTime), DateTimeKind.Utc);
42+
return new SftpFileAttributes(utcDefault, utcDefault, size, default(int), default(int), default(uint), null);
4243
}
4344

4445
protected static byte[] CreateByteArray(Random random, int length)

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeAppend_FileAccessWrite.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ protected override void SetupData()
3434
_readBufferSize = (uint) _random.Next(5, 1000);
3535
_writeBufferSize = (uint) _random.Next(5, 1000);
3636
_handle = GenerateRandom(_random.Next(1, 10), _random);
37-
_fileAttributes = new SftpFileAttributesBuilder().WithLastAccessTime(DateTime.Now.AddSeconds(_random.Next()))
38-
.WithLastWriteTime(DateTime.Now.AddSeconds(_random.Next()))
37+
_fileAttributes = new SftpFileAttributesBuilder().WithLastAccessTime(DateTime.UtcNow.AddSeconds(_random.Next()))
38+
.WithLastWriteTime(DateTime.UtcNow.AddSeconds(_random.Next()))
3939
.WithSize(_random.Next())
4040
.WithUserId(_random.Next())
4141
.WithGroupId(_random.Next())

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInReadBuffer_NewLengthGreatherThanPosition.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ protected override void SetupData()
5353
_fileAttributes = new SftpFileAttributesBuilder().WithExtension("X", "ABC")
5454
.WithExtension("V", "VValue")
5555
.WithGroupId(random.Next())
56-
.WithLastAccessTime(DateTime.Now.AddSeconds(random.Next()))
57-
.WithLastWriteTime(DateTime.Now.AddSeconds(random.Next()))
56+
.WithLastAccessTime(DateTime.UtcNow.AddSeconds(random.Next()))
57+
.WithLastWriteTime(DateTime.UtcNow.AddSeconds(random.Next()))
5858
.WithPermissions((uint) random.Next())
5959
.WithSize(_length + 100)
6060
.WithUserId(random.Next())
@@ -201,4 +201,4 @@ public void WriteShouldStartFromSamePositionAsBeforeSetLength()
201201
SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(4));
202202
}
203203
}
204-
}
204+
}

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInReadBuffer_NewLengthLessThanPosition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ protected override void SetupData()
5050
_fileAttributes = new SftpFileAttributesBuilder().WithExtension("X", "ABC")
5151
.WithExtension("V", "VValue")
5252
.WithGroupId(random.Next())
53-
.WithLastAccessTime(DateTime.Now.AddSeconds(random.Next()))
54-
.WithLastWriteTime(DateTime.Now.AddSeconds(random.Next()))
53+
.WithLastAccessTime(DateTime.UtcNow.AddSeconds(random.Next()))
54+
.WithLastWriteTime(DateTime.UtcNow.AddSeconds(random.Next()))
5555
.WithPermissions((uint)random.Next())
5656
.WithSize(_length + 100)
5757
.WithUserId(random.Next())

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInWriteBuffer_NewLengthGreatherThanPosition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ protected override void SetupData()
5454
_fileAttributes = new SftpFileAttributesBuilder().WithExtension("X", "ABC")
5555
.WithExtension("V", "VValue")
5656
.WithGroupId(random.Next())
57-
.WithLastAccessTime(DateTime.Now.AddSeconds(random.Next()))
58-
.WithLastWriteTime(DateTime.Now.AddSeconds(random.Next()))
57+
.WithLastAccessTime(DateTime.UtcNow.AddSeconds(random.Next()))
58+
.WithLastWriteTime(DateTime.UtcNow.AddSeconds(random.Next()))
5959
.WithPermissions((uint)random.Next())
6060
.WithSize(_length + 100)
6161
.WithUserId(random.Next())

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInWriteBuffer_NewLengthLessThanPosition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ protected override void SetupData()
5454
_fileAttributes = new SftpFileAttributesBuilder().WithExtension("X", "ABC")
5555
.WithExtension("V", "VValue")
5656
.WithGroupId(random.Next())
57-
.WithLastAccessTime(DateTime.Now.AddSeconds(random.Next()))
58-
.WithLastWriteTime(DateTime.Now.AddSeconds(random.Next()))
57+
.WithLastAccessTime(DateTime.UtcNow.AddSeconds(random.Next()))
58+
.WithLastWriteTime(DateTime.UtcNow.AddSeconds(random.Next()))
5959
.WithPermissions((uint) random.Next())
6060
.WithSize(_length + 100)
6161
.WithUserId(random.Next())

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ protected void Arrange()
4848
_writeBufferSize = (uint) random.Next(0, 1000);
4949
_length = random.Next();
5050

51-
_fileAttributesLastAccessTime = DateTime.Now.AddSeconds(random.Next());
52-
_fileAttributesLastWriteTime = DateTime.Now.AddSeconds(random.Next());
51+
_fileAttributesLastAccessTime = DateTime.UtcNow.AddSeconds(random.Next());
52+
_fileAttributesLastWriteTime = DateTime.UtcNow.AddSeconds(random.Next());
5353
_fileAttributesSize = random.Next();
5454
_fileAttributesUserId = random.Next();
5555
_fileAttributesGroupId = random.Next();

0 commit comments

Comments
 (0)