public void testListLocales() { Object[] o = handler.listLocales(); assertNotNull(o); String[] locales = Config.get().getStringArray("web.supported_locales"); assertNotNull(locales); assertEquals(locales.length, o.length); }
/** {@inheritDoc} */ public void setUp() throws Exception { super.setUp(); user.getOrg().addRole(RoleFactory.SAT_ADMIN); user.addPermanentRole(RoleFactory.SAT_ADMIN); setRequestPathInfo("/admin/config/Restart"); Config.get() .setString( "web.com.redhat.rhn.frontend." + "action.satellite.RestartAction.command", TestRestartCommand.class.getName()); }
public void testLongNames() { int maxLogin = UserDefaults.get().getMaxUserLength(); int maxPassword = UserDefaults.get().getMaxPasswordLength(); int emailLength = UserDefaults.get().getMaxEmailLength(); Config.get().setString(UserDefaults.MAX_USER_LENGTH, String.valueOf(5)); Config.get().setString(UserDefaults.MAX_PASSWORD_LENGTH, String.valueOf(5)); Config.get().setString(UserDefaults.MAX_EMAIL_LENGTH, String.valueOf(5)); String invalidLogin = TestUtils.randomString(); String invalidPassword = "******"; String invalidEmail = "*****@*****.**"; String validPrefix = "Sr."; // Test invalid values command.setLogin(invalidLogin); command.setEmail(invalidEmail); command.setPassword(invalidPassword); command.setPrefix(validPrefix); command.setFirstNames("testuser"); command.setLastName("testuser"); // We should get 4 errors (login, email, password, prefix) Object[] errors = command.validate(); Config.get().setString(UserDefaults.MAX_USER_LENGTH, String.valueOf(maxLogin)); Config.get().setString(UserDefaults.MAX_PASSWORD_LENGTH, String.valueOf(maxPassword)); Config.get().setString(UserDefaults.MAX_EMAIL_LENGTH, String.valueOf(emailLength)); assertEquals(3, errors.length); }
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(); } }
/** * Sets up the proxy information for the wizard. its public in this class because we reuse this in * SSM and only this class knows how to format the name nicely. * * @param ctx the request context needed for user info and things to bind to the request */ public static void setupProxyInfo(RequestContext ctx) { List<OrgProxyServer> proxies = SystemManager.listProxies(ctx.getCurrentUser().getOrg()); if (proxies != null && proxies.size() > 0) { List<LabelValueBean> formatted = new LinkedList<LabelValueBean>(); formatted.add(lvl10n("kickstart.schedule.default.proxy.jsp", "")); Map cnames = new HashMap(); for (OrgProxyServer serv : proxies) { formatted.add(lv(serv.getName() + " (" + serv.getCheckin() + ")", serv.getId().toString())); List proxyCnames = Config.get().getList(VALID_CNAMES + serv.getId().toString()); if (!proxyCnames.isEmpty()) { cnames.put(serv.getId().toString(), proxyCnames); } } ctx.getRequest().setAttribute(HAS_PROXIES, Boolean.TRUE.toString()); ctx.getRequest().setAttribute(PROXIES, formatted); ctx.getRequest().setAttribute(CNAMES, cnames); } else { ctx.getRequest().setAttribute(HAS_PROXIES, Boolean.FALSE.toString()); } }
/** * Create a new organization. * * @param sessionKey User's session key. * @param orgName Organization name. Must meet same criteria as in the web UI. * @param adminLogin New administrator login name for the new org. * @param adminPassword New administrator password. * @param prefix New administrator's prefix. * @param firstName New administrator's first name. * @param lastName New administrator's last name. * @param email New administrator's e-mail. * @param usePamAuth Should PAM authentication be used for new administrators account. * @return Newly created organization object. * @xmlrpc.doc Create a new organization and associated administrator account. * @xmlrpc.param #param("string", "sessionKey") * @xmlrpc.param #param_desc("string", "orgName", "Organization name. Must meet same criteria as * in the web UI.") * @xmlrpc.param #param_desc("string", "adminLogin", "New administrator login name.") * @xmlrpc.param #param_desc("string", "adminPassword", "New administrator password.") * @xmlrpc.param #param_desc("string", "prefix", "New administrator's prefix. Must match one of * the values available in the web UI. (i.e. Dr., Mr., Mrs., Sr., etc.)") * @xmlrpc.param #param_desc("string", "firstName", "New administrator's first name.") * @xmlrpc.param #param_desc("string", "lastName", "New administrator's first name.") * @xmlrpc.param #param_desc("string", "email", "New administrator's e-mail.") * @xmlrpc.param #param_desc("boolean", "usePamAuth", "True if PAM authentication should be used * for the new administrator account.") * @xmlrpc.returntype $OrgDtoSerializer */ public OrgDto create( String sessionKey, String orgName, String adminLogin, String adminPassword, String prefix, String firstName, String lastName, String email, Boolean usePamAuth) { log.debug("OrgHandler.create"); getSatAdmin(sessionKey); validateCreateOrgData(orgName, adminPassword, firstName, lastName, email, usePamAuth); CreateOrgCommand cmd = new CreateOrgCommand(orgName, adminLogin, adminPassword, email); cmd.setFirstName(firstName); cmd.setLastName(lastName); cmd.setPrefix(prefix); String pamAuthService = Config.get().getString(ConfigDefaults.WEB_PAM_AUTH_SERVICE); if (usePamAuth) { if (pamAuthService != null && pamAuthService.trim().length() > 0) { cmd.setUsePam(usePamAuth); } else { // The user wants to use pam authentication, but the server has not been // configured to use pam... Throw an error... throw new PamAuthNotConfiguredException(); } } ValidatorError[] verrors = cmd.store(); if (verrors != null) { throw new ValidationException(verrors[0].getMessage()); } return OrgManager.toDetailsDto(cmd.getNewOrg()); }