Authorize data sync on connected agent registration

This commit is contained in:
2026-09-22 16:47:52 +08:00
parent 49c07cca30
commit e26535781d
17 changed files with 194 additions and 110 deletions
@@ -39,6 +39,29 @@ public sealed class RemoteReportingTests
Assert.True(ReportingAuthorization.IsAllowed(config, "account-a", "stable-group", ReportingChatType.Group, ReportingDataType.TaskResult));
}
[Fact]
public void ConnectionWildcardAuthorizesEveryVerifiedChatType()
{
var config = new ReportingConfig
{
Enabled = true,
ConfigVersion = 1,
Accounts = [new AccountReportingConfig
{
AccountId = "account-a", Enabled = true,
AllowedChats =
[
new AllowedChat { Type = ReportingChatType.Group, ChatId = "*", Enabled = true, IdentityVerified = true },
new AllowedChat { Type = ReportingChatType.Private, ChatId = "*", Enabled = true, IdentityVerified = true }
]
}]
};
Assert.True(ReportingAuthorization.IsAllowed(config, "account-a", "group-1@chatroom", ReportingChatType.Group, ReportingDataType.Message));
Assert.True(ReportingAuthorization.IsAllowed(config, "account-a", "private-1", ReportingChatType.Private, ReportingDataType.Message));
Assert.False(ReportingAuthorization.IsAllowed(config, "account-b", "private-1", ReportingChatType.Private, ReportingDataType.Message));
}
[Fact]
public void ReadTaskResultsRequireEveryWhitelistedScope()
{
@@ -29,14 +29,14 @@ public sealed class ServiceBoundaryTests
}
[Fact]
public void DatabaseSyncIsExplicitOptInByDefault()
public void DatabaseSyncIsAuthorizedByAgentConnectionByDefault()
{
var options = new ServiceOptions
{
CredentialFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")),
DataDirectory = Path.GetTempPath()
};
Assert.False(options.EnableDataSync);
Assert.True(options.EnableDataSync);
}
[Fact]