Example #1
0
  public void testPerformNoPasswordName() {

    LoginAction action = new LoginAction();

    ActionMapping mapping = new ActionMapping();
    ActionForward failure = new ActionForward("failure", "path", false);
    PxtCookieManager pcm = new PxtCookieManager();
    RhnMockDynaActionForm form = new RhnMockDynaActionForm("loginForm");
    RhnMockHttpServletRequest request = new RhnMockHttpServletRequest();
    RhnMockHttpServletResponse response = new RhnMockHttpServletResponse();

    RequestContext requestContext = new RequestContext(request);

    request.setSession(new MockHttpSession());
    request.setupServerName("mymachine.rhndev.redhat.com");
    WebSession s = requestContext.getWebSession();
    request.addCookie(pcm.createPxtCookie(s.getId(), request, 10));

    mapping.addForwardConfig(failure);
    form.set("username", "someusername");
    form.set("password", "");

    ActionForward rc = action.execute(mapping, form, request, response);

    assertEquals(rc, failure);
  }
Example #2
0
  public void testDisabledUser() {
    LoginAction action = new LoginAction();
    User u = UserTestUtils.findNewUser("testUser", "testOrg" + this.getClass().getSimpleName());
    UserManager.disableUser(u, u);

    ActionMapping mapping = new ActionMapping();
    mapping.addForwardConfig(new ActionForward("failure", "path", false));
    PxtCookieManager pcm = new PxtCookieManager();
    RhnMockDynaActionForm form = new RhnMockDynaActionForm("loginForm");
    RhnMockHttpServletRequest request = new RhnMockHttpServletRequest();
    RhnMockHttpServletResponse response = new RhnMockHttpServletResponse();

    RequestContext requestContext = new RequestContext(request);

    request.setSession(new MockHttpSession());
    request.setupServerName("mymachine.rhndev.redhat.com");
    WebSession s = requestContext.getWebSession();
    request.addCookie(pcm.createPxtCookie(s.getId(), request, 10));

    form.set("username", u.getLogin());
    /**
     * Since we know testUser's password is "password", just set that here. using u.getPassword()
     * will fail when we're using encrypted passwords.
     */
    form.set("password", "password");

    ActionForward rc = action.execute(mapping, form, request, response);

    assertEquals("failure", rc.getName());
  }
Example #3
0
  /**
   * In this test we actually return an HttpServletRequest so this code can be reused by other tests
   * to Login a user and get the Request (with session) that appears logged in. In order for this
   * test to be executed by JUnit we have to wrap its call in the above method with a void return
   * type.
   *
   * @throws Exception
   */
  public HttpServletRequest loginUserIntoSessionTest() throws Exception {
    LoginAction action = new LoginAction();
    User u = UserTestUtils.findNewUser("testUser", "testOrg" + this.getClass().getSimpleName());
    ActionMapping mapping = new ActionMapping();
    mapping.addForwardConfig(new ActionForward("loggedin", "path", false));
    PxtCookieManager pcm = new PxtCookieManager();
    RhnMockDynaActionForm form = new RhnMockDynaActionForm("loginForm");
    RhnMockHttpServletRequest request = new RhnMockHttpServletRequest();
    RhnMockHttpServletResponse response = new RhnMockHttpServletResponse();

    RequestContext requestContext = new RequestContext(request);

    MockHttpSession mockSession = new MockHttpSession();
    mockSession.setupGetAttribute("url_bounce", null);
    mockSession.setupGetAttribute("request_method", "GET");
    request.setSession(mockSession);
    request.setupServerName("mymachine.rhndev.redhat.com");
    WebSession s = requestContext.getWebSession();
    request.addCookie(pcm.createPxtCookie(s.getId(), request, 10));

    form.set("username", u.getLogin());
    /**
     * Since we know testUser's password is "password", just set that here. using u.getPassword()
     * will fail when we're using encrypted passwords.
     */
    form.set("password", "password");
    form.set("request_method", "POST");

    ActionForward rc = action.execute(mapping, form, request, response);

    assertNull(rc);
    return request;
  }
  public void setUp() {
    request = new RhnMockHttpServletRequest();
    session = new RhnMockHttpSession();

    RequestContext requestContext = new RequestContext(request);

    request.setupServerName("mymachine.rhndev.redhat.com");
    request.setSession(session);
    request.setupGetRequestURI("http://localhost:8080");
    WebSession s = requestContext.getWebSession();
    request.addCookie(requestContext.createWebSessionCookie(s.getId(), 10));
    response = new RhnMockHttpServletResponse();
    chain = new MockFilterChain();
  }
 /** {@inheritDoc} */
 public void setUp() throws Exception {
   super.setUp();
   user.addPermanentRole(RoleFactory.ORG_ADMIN);
   UserFactory.save(user);
   ksdata = KickstartDataTest.createKickstartWithOptions(user.getOrg());
   // ksdata = KickstartDataTest.createKickstartWithChannel(user.getOrg());
   mockRequest = new RhnMockHttpServletRequest();
   mockRequest.setupGetRemoteAddr("127.0.0.1");
   request = new RhnHttpServletRequest(mockRequest);
   helper = new KickstartHelper(request);
 }
  public void testProxyFetch() throws Exception {

    String proxyheader =
        "1006681409::1151513167.96:21600.0:VV/xFNEmCYOuHx"
            + "EBAs7BEw==:fjs-0-08.rhndev.redhat.com,1006681408::1151513034."
            + "3:21600.0:w2lm+XWSFJMVCGBK1dZXXQ==:fjs-0-11.rhndev.redhat.com"
            + ",1006678487::1152567362.02:21600.0:t15lgsaTRKpX6AxkUFQ11A==:f"
            + "js-0-12.rhndev.redhat.com";

    // mockRequest.setupAddHeader(KickstartHelper.XRHNPROXYAUTH, proxyheader);
    mockRequest.setupGetHeader(KickstartHelper.XRHNPROXYAUTH, proxyheader);
    helper = new KickstartHelper(request);
    assertEquals("fjs-0-08.rhndev.redhat.com", helper.getKickstartHost());
  }