fix: F-002: only allow core and capability module to call informTokenModule (#78)

* only allow core and capability module to call informTokenModule

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Iuri Matias
2026-06-08 14:27:07 -04:00
committed by GitHub
co-authored by Copilot Autofix powered by AI
parent 42a8b9ed5c
commit 448aa9002c
6 changed files with 227 additions and 17 deletions
+12 -1
View File
@@ -169,8 +169,19 @@ TEST_F(ModuleProxyTest, InformModuleTokenDelegatesToProvider)
m_provider->init(&api);
ModuleProxy proxy(m_provider);
bool result = proxy.informModuleToken("auth", "target_mod", "tok123");
// informModuleToken is privileged: only the trusted core/capability_module
// channel may plant tokens (F-002). The host seeds the module's own auth
// secret under "core"/"capability_module" at init; the legitimate caller
// presents that secret. Seed it and present it so this exercises the
// delegation path rather than the (now-enforced) authz rejection.
TokenManager::instance().clearAllTokens();
TokenManager::instance().saveToken("capability_module", "trusted-secret");
bool result = proxy.informModuleToken("trusted-secret", "target_mod", "tok123");
EXPECT_TRUE(result);
// Provider's informModuleToken saves via TokenManager
EXPECT_EQ(TokenManager::instance().getToken("target_mod"), "tok123");
// Don't leak the seeded secret into sibling tests sharing the singleton.
TokenManager::instance().clearAllTokens();
}