public void testPerformExecute() throws Exception {
    UserEditSetupAction action = new UserEditSetupAction();
    ActionHelper sah = new ActionHelper();
    sah.setUpAction(action);
    sah.getRequest().setRequestURL("foo");

    User user = sah.getUser();
    user.setTitle("Test title");
    // Lets add some roles
    Iterator it = UserFactory.IMPLIEDROLES.iterator();
    user.addPermanentRole(RoleFactory.ORG_ADMIN);
    while (it.hasNext()) {
      Role cr = (Role) it.next();
      user.getOrg().addRole(cr);
      user.addPermanentRole(cr);
    }

    setupExpectations(sah.getForm(), sah.getUser());

    // Below we test to make sure that some of
    // the strings in the form are localized
    TestUtils.enableLocalizationDebugMode();
    try {
      sah.executeAction();

      // verify the dyna form got the right values we expected.
      sah.getForm().verify();

      assertEquals(sah.getUser().getLastLoggedIn(), sah.getRequest().getAttribute("lastLoggedIn"));
      // Verify some more intensive stuff
      assertNotNull(sah.getRequest().getAttribute("adminRoles"));
      assertNotNull(sah.getRequest().getAttribute("regularRoles"));
      List<UserRoleStatusBean> regularRoles =
          (List<UserRoleStatusBean>) sah.getRequest().getAttribute("regularRoles");
      assertEquals(5, regularRoles.size());
      UserRoleStatusBean lv = regularRoles.get(0);
      assertTrue(TestUtils.isLocalized(lv.getName()));
      assertEquals(true, lv.isDisabled());
      assertNotNull(sah.getRequest().getAttribute("disabledRoles"));
      assertTrue(sah.getRequest().getAttribute("user") instanceof User);

      // If we have pam setup where we're testing, make sure displaypam was set
      String pamAuthService = Config.get().getString(ConfigDefaults.WEB_PAM_AUTH_SERVICE);
      if (pamAuthService != null && pamAuthService.trim().length() > 0) {
        assertNotNull(sah.getRequest().getAttribute("displaypam"));
      }
    } finally {
      TestUtils.disableLocalizationDebugMode();
    }
  }
Ejemplo n.º 2
0
 /**
  * Adds a role to the given user
  *
  * @param loggedInUser The current user
  * @param login The login for the user you would like to add the role to
  * @param role The role you would like to give the user
  * @return Returns 1 if successful (exception otherwise)
  * @throws FaultException A FaultException is thrown if the user doesn't have access to lookup the
  *     user corresponding to login or if the user does not exist.
  * @xmlrpc.doc Adds a role to a user.
  * @xmlrpc.param #param("string", "sessionKey")
  * @xmlrpc.param #param_desc("string", "login", "User login name to update.")
  * @xmlrpc.param #param_desc("string", "role", "Role label to add. Can be any of: satellite_admin,
  *     org_admin, channel_admin, config_admin, system_group_admin, activation_key_admin, or
  *     monitoring_admin.")
  * @xmlrpc.returntype #return_int_success()
  */
 public int addRole(User loggedInUser, String login, String role) throws FaultException {
   validateRoleInputs(role, loggedInUser);
   if (RoleFactory.SAT_ADMIN.getLabel().equals(role)) {
     return modifySatAdminRole(loggedInUser, login, true);
   }
   User target = XmlRpcUserHelper.getInstance().lookupTargetUser(loggedInUser, login);
   // Retrieve the role object corresponding to the role label passed in and
   // add to user
   Role r = RoleFactory.lookupByLabel(role);
   target.addPermanentRole(r);
   UserManager.storeUser(target);
   return 1;
 }
  public void testSelectAll() throws Exception {
    BaseSystemListAction action = createAction();
    ActionHelper ah = new ActionHelper();
    ah.setUpAction(action);
    ah.setupProcessPagination();

    User user = ah.getUser();
    user.addPermanentRole(RoleFactory.ORG_ADMIN);
    UserManager.storeUser(user);
    ah.getRequest().setupAddParameter("items_on_page", (String[]) null);
    ah.getRequest().setupAddParameter("items_selected", (String[]) null);
    ah.executeAction("selectall");
    // This test only ensures that 'Select All' doesn't blow up.
    // To really test that something got selected, we would have to create an
    // appropriate system for each of the subclasses. The fact that the set cleaner
    // doesn't clean servers that should stay in the set is already tested by
    // testAddOne()
  }
  public void testAddOne() throws Exception {
    BaseSystemListAction action = createAction();
    ActionHelper ah = new ActionHelper();
    ah.setUpAction(action);
    ah.setupProcessPagination();

    User user = ah.getUser();
    user.addPermanentRole(RoleFactory.ORG_ADMIN);
    // Create a server that can be put in the set. Note that the
    // server is not set up entirely right for subclasses, which would
    // only display servers with certain attributes, e.g. a satellite.
    // But this test is only concerned with keeping a server in the set
    // w/o having it cleaned up by the set cleaner
    Server server =
        ServerFactoryTest.createTestServer(
            user, true, ServerConstants.getServerGroupTypeEnterpriseEntitled());
    UserManager.storeUser(user);
    String sid = server.getId().toString();
    ah.getRequest().setupAddParameter("items_on_page", (String[]) null);
    ah.getRequest().setupAddParameter("items_selected", new String[] {sid});
    ah.executeAction("updatelist");

    RhnSetActionTest.verifyRhnSetData(ah.getUser(), RhnSetDecl.SYSTEMS, 1);
  }
Ejemplo n.º 5
0
 /**
  * Simple test illustrating how roles work. Note that the channel_admin role is implied for an org
  * admin iff the org has the channel_admin role.
  */
 public void testAddRole() {
   User user = UserTestUtils.findNewUser("testuser", "testorg");
   user.addPermanentRole(RoleFactory.ORG_ADMIN);
   assertTrue(user.hasRole(RoleFactory.CHANNEL_ADMIN));
 }