@@ -179,6 +179,46 @@ public void getViolationsByProjectTest() {
179
179
assertThat (jsonObject1 .getJsonObject ("component" ).getString ("name" )).isEqualTo ("Acme Component 0" );
180
180
}
181
181
182
+ @ Test
183
+ public void getViolationsByProjectIssue2766 () {
184
+ initializeWithPermissions (Permissions .VIEW_POLICY_VIOLATION );
185
+
186
+ final Project projectA = qm .createProject ("acme-app-a" , null , "1.0" , null , null , null , true , false );
187
+ final var componentA = new Component ();
188
+ componentA .setProject (projectA );
189
+ componentA .setName ("acme-lib-a" );
190
+ componentA .setVersion ("1.0.1" );
191
+ qm .persist (componentA );
192
+
193
+ final Project projectB = qm .createProject ("acme-app-b" , null , "2.0" , null , null , null , true , false );
194
+ final var componentB = new Component ();
195
+ componentB .setProject (projectB );
196
+ componentB .setName ("acme-lib-b" );
197
+ componentB .setVersion ("2.0.1" );
198
+ qm .persist (componentB );
199
+
200
+ final Policy policy = qm .createPolicy ("policy" , Policy .Operator .ALL , Policy .ViolationState .FAIL );
201
+ final PolicyCondition condition = qm .createPolicyCondition (policy , PolicyCondition .Subject .VERSION , PolicyCondition .Operator .NUMERIC_EQUAL , "1.0.1" );
202
+ final var violation = new PolicyViolation ();
203
+ violation .setPolicyCondition (condition );
204
+ violation .setComponent (componentA );
205
+ violation .setType (PolicyViolation .Type .OPERATIONAL );
206
+ violation .setTimestamp (new Date ());
207
+ qm .persist (violation );
208
+
209
+ // Requesting violations for projectB must not yield violations for projectA.
210
+ final Response response = target (V1_POLICY_VIOLATION )
211
+ .path ("/project/" + projectB .getUuid ())
212
+ .request ()
213
+ .header (X_API_KEY , apiKey )
214
+ .get ();
215
+ assertThat (response .getStatus ()).isEqualTo (Response .Status .OK .getStatusCode ());
216
+ assertThat (response .getHeaderString (TOTAL_COUNT_HEADER )).isEqualTo ("0" );
217
+
218
+ final JsonArray jsonArray = parseJsonArray (response );
219
+ assertThat (jsonArray ).hasSize (0 );
220
+ }
221
+
182
222
@ Test
183
223
public void getViolationsByProjectUnauthorizedTest () {
184
224
final Response response = target (V1_POLICY_VIOLATION )
0 commit comments