Skip to content

Commit

Permalink
Updated alert acknowledgement integration test for enhanced Alert ACL
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen committed Feb 6, 2010
1 parent 6601291 commit 7063810
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
38 changes: 36 additions & 2 deletions src/org/hyperic/hq/hqapi1/test/AlertAck_test.java
@@ -1,12 +1,16 @@
package org.hyperic.hq.hqapi1.test;

import org.hyperic.hq.hqapi1.types.Alert;
import org.hyperic.hq.hqapi1.types.Resource;
import org.hyperic.hq.hqapi1.types.AlertResponse;
import org.hyperic.hq.hqapi1.types.Escalation;
import org.hyperic.hq.hqapi1.types.Group;
import org.hyperic.hq.hqapi1.types.Operation;
import org.hyperic.hq.hqapi1.types.Resource;
import org.hyperic.hq.hqapi1.types.Role;
import org.hyperic.hq.hqapi1.types.User;
import org.hyperic.hq.hqapi1.types.AlertResponse;
import org.hyperic.hq.hqapi1.AlertApi;

import java.util.Collections;
import java.util.List;

public class AlertAck_test extends AlertTestBase {
Expand Down Expand Up @@ -55,6 +59,36 @@ public void testAckAlertNoPermission() throws Exception {
deleteEscalation(e);
deleteTestUsers(users);
}

public void testAckAlertAlertingPermission() throws Exception {
Resource platform = getLocalPlatformResource(false, false);
Escalation e = createEscalation();
Alert a = generateAlerts(platform, e);
validateAlert(a);

// Create user/group/role with insufficient permissions
List<User> users = createTestUsers(1);
User unprivUser = users.get(0);
Role alertRole = createRole(Collections.singletonList(unprivUser),
Collections.singletonList(Operation.MANAGE_PLATFORM_ALERTS));
Group groupWithRole = createGroup(Collections.singletonList(platform),
Collections.singletonList(alertRole));

AlertApi apiUnpriv = getApi(unprivUser.getName(), TESTUSER_PASSWORD).getAlertApi();

// Test ack (alert will be in Escalation) with an unprivileged user.
// Role needs alerting and at least view resource permissions
// in order to ack alerts
AlertResponse ackResponse = apiUnpriv.ackAlert(a.getId(), "Test ACK", 60000l);
hqAssertFailurePermissionDenied(ackResponse);

// Cleanup
deleteAlertDefinitionByAlert(a);
deleteEscalation(e);
deleteTestUsers(users);
cleanupRole(alertRole);
cleanupGroup(groupWithRole);
}

public void testAckUnacknowledableAlert() throws Exception {
Resource platform = getLocalPlatformResource(false, false);
Expand Down
5 changes: 4 additions & 1 deletion src/org/hyperic/hq/hqapi1/test/HQApiTestBase.java
Expand Up @@ -197,9 +197,12 @@ protected Resource getLocalPlatformResource(boolean verbose,
hqAssertSuccess(resourceResponse);

Resource localPlatform = null;
List<String> invalidPlatforms = new ArrayList<String>();
invalidPlatforms.add("Network Device");
invalidPlatforms.add("Network Host");

for (Resource r : resourceResponse.getResource()) {
if (!r.getResourcePrototype().getName().equals("Network Device")) {
if (!invalidPlatforms.contains(r.getResourcePrototype().getName())) {
localPlatform = r;
break;
}
Expand Down

0 comments on commit 7063810

Please sign in to comment.