Skip to content

Commit 6b5f2c2

Browse files
committed
fix conflicting check
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 1a713a2 commit 6b5f2c2

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookFilter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ default WebhookFilter getConflicting(List<? extends WebhookFilter> existing) {
100100
}
101101

102102
// 2. Opposite mode (INCLUDE vs EXCLUDE) — check for overlap
103-
if (Mode.Exclude.equals(f.getMode())
104-
&& Mode.Include.equals(this.getMode())) {
103+
if (f.getMode() != this.getMode()) {
105104
String oldVal = f.getValue().toUpperCase();
106105
String newVal = this.getValue().toUpperCase();
107106

plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/WebhookApiServiceImplTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import com.cloud.cluster.dao.ManagementServerHostDao;
6565
import com.cloud.domain.DomainVO;
6666
import com.cloud.domain.dao.DomainDao;
67+
import com.cloud.event.EventTypes;
6768
import com.cloud.exception.InvalidParameterValueException;
6869
import com.cloud.exception.PermissionDeniedException;
6970
import com.cloud.user.Account;
@@ -1262,6 +1263,28 @@ public void addWebhookFilterConflictsWithExisting() {
12621263
webhookApiServiceImpl.addWebhookFilter(cmd);
12631264
}
12641265

1266+
@Test(expected = InvalidParameterValueException.class)
1267+
public void addWebhookFilterSameEventConflictsWithExisting() {
1268+
AddWebhookFilterCmd cmd = Mockito.mock(AddWebhookFilterCmd.class);
1269+
WebhookVO webhook = Mockito.mock(WebhookVO.class);
1270+
WebhookFilterVO filter = Mockito.mock(WebhookFilterVO.class);
1271+
1272+
Mockito.when(webhook.getId()).thenReturn(1L);
1273+
Mockito.when(filter.getType()).thenReturn(WebhookFilter.Type.EventType);
1274+
Mockito.when(filter.getMode()).thenReturn(WebhookFilter.Mode.Include);
1275+
Mockito.when(filter.getMatchType()).thenReturn(WebhookFilter.MatchType.Exact);
1276+
Mockito.when(filter.getValue()).thenReturn(EventTypes.EVENT_VM_CREATE);
1277+
Mockito.when(cmd.getId()).thenReturn(1L);
1278+
Mockito.when(cmd.getType()).thenReturn(WebhookFilter.Type.EventType.name());
1279+
Mockito.when(cmd.getMode()).thenReturn(WebhookFilter.Mode.Exclude.name());
1280+
Mockito.when(cmd.getMatchType()).thenReturn(WebhookFilter.MatchType.Exact.name());
1281+
Mockito.when(cmd.getValue()).thenReturn(EventTypes.EVENT_VM_CREATE);
1282+
Mockito.when(webhookDao.findById(1L)).thenReturn(webhook);
1283+
Mockito.when(webhookFilterDao.listByWebhook(1L)).thenReturn(List.of(filter));
1284+
1285+
webhookApiServiceImpl.addWebhookFilter(cmd);
1286+
}
1287+
12651288
@Test
12661289
public void deleteWebhookFilterDeletesFilterSuccessfully() {
12671290
DeleteWebhookFilterCmd cmd = Mockito.mock(DeleteWebhookFilterCmd.class);

0 commit comments

Comments
 (0)