ReATest: enhancing policy-as-code workflows through automated test case generation from Rego policies
摘要
Policy-as-code (PaC) has emerged as a key practice in development, security, and operations, enabling organizations to specify, manage, and enforce access control policies as part of the software delivery pipeline. At the core of PaC, Rego, the policy language of Open Policy Agent, is widely used to implement authorization rules in cloud-native and microservice environments. However, testing Rego policies remains a major challenge, as current practices rely heavily on manual or ad-hoc test case design, often leading to insufficient coverage and latent security risks. This article introduces ReATest, an automated approach to enhancing PaC workflows through systematic test case generation from Rego specifications. ReATest defines a specialized Rego Flow Graph (RFG) that represents the structural relationships among Rego rules, conditions, and policy decisions. This representation enables systematic exploration of policy execution paths to generate an initial test suite. The resulting suite is then optimized using the Grey Wolf Optimization algorithm to reduce redundant test cases and improve overall testing efficiency. The approach was evaluated on Rego policies from open-source repositories. Experimental results show that ReATest achieved an average 35.43% reduction in test suite size, retaining 64.57% of the generated test cases; overall, this corresponds to 69.77% fewer tests compared to the published baselines.