特权操作的自动化测试

发布于 2024-09-11 14:06:28 字数 326 浏览 5 评论 0原文

如何对需要与持续集成环境中存在的权限级别不同的权限级别的代码进行单元/集成测试?

在我的非 root、CCRB 驱动的构建环境中,我有一些实用程序函数,它们假定以下权限:不保留在我的自动化构建环境中:root权限或特殊帐户和组。 (例如,一个函数将 UID/GID 和补充组更改为指定帐户,更改根目录和当前工作目录,并脱离任何控制终端。)

当然,我们可以手动运行测试,但随后我们可能会忘记运行它们。

其他人是如何解决这个问题的?

How do you unit/integration test code that requires a different privilege level than exists in your continuous integration environment?

In my non-root, CCRB-driven build environment, I've got some utility functions that assume privileges that don't hold in my automated build environment: either root privileges or special accounts and groups. (For example, one function changes UID/GID and supplementary groups to a specified account, changes root and current working directory, and divorces from any controlling terminal.)

We could run the tests by hand, of course, but then we might forget to run them.

How have others tackled this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

池木 2024-09-18 14:06:28

我会尝试分解出可模拟接口背后的安全管理代码,以便在单元测试中我可以根据需要提供虚假权限。

这样,就可以测试在没有所需权限的情况下该函数会失败,以及在授予权限的情况下它会执行其应该执行的操作。

如果没有更具体的细节,很难说更多。

I would try to factor out the security management code behind a mockable interface, so that in unit tests I can provide fake privileges however I want.

This way it would be possible to test both that barring the required privileges the function fails, and that with the privileges granted it does what it is supposed to do.

Without more concrete details it is hard to say more.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文