mirror of
https://github.com/Govor-team/Govor.git
synced 2026-11-18 13:24:59 +00:00
Expose chat read positions and E2EE errors
Add optional chat activity and read-position details to the unread-count endpoint. Return stable E2EE rejection codes for stale timestamps and untrusted signing devices, with tests for both behaviors.
This commit is contained in:
@@ -90,13 +90,17 @@ public class E2eeTests
|
||||
[TestCase("malformed")]
|
||||
[TestCase("routing")]
|
||||
[TestCase("stale")]
|
||||
[TestCase("future")]
|
||||
public async Task InvalidEnvelopeContextIsReturnedAsValidationFailure(string reason)
|
||||
{
|
||||
var directory = await _e2ee.GetConversationKeysAsync(_db.Alice, _db.ChatId, RecipientType.User);
|
||||
var content = reason == "malformed" ? E2eeProtocol.Prefix + "invalid" : E2eeProtocol.Encrypt(new("secret", []),
|
||||
_alice, _a, directory, Guid.NewGuid(), createdAt: DateTimeOffset.UtcNow.AddMinutes(reason == "stale" ? -6 : 0).ToUnixTimeMilliseconds());
|
||||
Assert.ThrowsAsync<ArgumentException>(() => _e2ee.ValidateAsync(content, reason == "routing" ? _db.Bob : _db.Alice,
|
||||
_alice, _a, directory, Guid.NewGuid(), createdAt: DateTimeOffset.UtcNow.AddMinutes(reason switch
|
||||
{ "stale" => -6, "future" => 6, _ => 0 }).ToUnixTimeMilliseconds());
|
||||
var failure = Assert.ThrowsAsync<ArgumentException>(() => _e2ee.ValidateAsync(content, reason == "routing" ? _db.Bob : _db.Alice,
|
||||
_db.ChatId, RecipientType.User, null, []));
|
||||
if (reason is "stale" or "future")
|
||||
Assert.That(failure!.Message, Is.EqualTo(E2eeProtocol.TimestampOutOfRangeError));
|
||||
}
|
||||
|
||||
[TestCase(false)]
|
||||
@@ -206,8 +210,9 @@ public class E2eeTests
|
||||
var ciphertext = await Encrypt();
|
||||
await _db.Context.UserSessions.Where(s => s.Id == _a.SessionId)
|
||||
.ExecuteUpdateAsync(u => u.SetProperty(s => s.IsRevoked, true));
|
||||
Assert.ThrowsAsync<UnauthorizedAccessException>(() => _e2ee.ValidateAsync(ciphertext,
|
||||
var failure = Assert.ThrowsAsync<UnauthorizedAccessException>(() => _e2ee.ValidateAsync(ciphertext,
|
||||
_db.Alice, _db.ChatId, RecipientType.User, null, []));
|
||||
Assert.That(failure!.Message, Is.EqualTo(E2eeProtocol.SigningDeviceRejectedError));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user