@Test
  public void verifyValidServiceTicketWithValidPgtAndProxyHandlerFailing() throws Exception {
    final TicketGrantingTicket tId =
        getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());
    final ServiceTicket sId =
        getCentralAuthenticationService().grantServiceTicket(tId.getId(), TestUtils.getService());

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", TestUtils.getService().getId());
    request.addParameter("ticket", sId.getId());
    request.addParameter("pgtUrl", "https://www.github.com");

    this.serviceValidateController.setProxyHandler(
        new ProxyHandler() {
          @Override
          public String handle(
              final Credential credential, final TicketGrantingTicket proxyGrantingTicketId) {
            return null;
          }

          @Override
          public boolean canHandle(final Credential credential) {
            return true;
          }
        });

    final ModelAndView modelAndView =
        this.serviceValidateController.handleRequestInternal(
            request, new MockHttpServletResponse());
    assertEquals(
        ServiceValidateController.DEFAULT_SERVICE_FAILURE_VIEW_NAME, modelAndView.getViewName());
    assertNull(modelAndView.getModel().get("pgtIou"));
  }
 @Test
 public void testEquals() {
   assertFalse(TestUtils.getCredentialsWithDifferentUsernameAndPassword().equals(null));
   assertFalse(
       TestUtils.getCredentialsWithDifferentUsernameAndPassword()
           .equals(TestUtils.getCredentialsWithSameUsernameAndPassword()));
   assertTrue(
       TestUtils.getCredentialsWithDifferentUsernameAndPassword()
           .equals(TestUtils.getCredentialsWithDifferentUsernameAndPassword()));
 }
  private HttpServletRequest getHttpServletRequest() throws Exception {
    final TicketGrantingTicket tId =
        getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());
    getCentralAuthenticationService().grantServiceTicket(tId.getId(), TestUtils.getService());
    final ServiceTicket sId2 =
        getCentralAuthenticationService().grantServiceTicket(tId.getId(), TestUtils.getService());

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", TestUtils.getService().getId());
    request.addParameter("ticket", sId2.getId());
    request.addParameter("renew", "true");

    return request;
  }
  protected final ModelAndView getModelAndViewUponServiceValidationWithSecurePgtUrl()
      throws Exception {
    final TicketGrantingTicket tId =
        getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());
    final ServiceTicket sId =
        getCentralAuthenticationService().grantServiceTicket(tId.getId(), TestUtils.getService());

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", TestUtils.getService().getId());
    request.addParameter("ticket", sId.getId());
    request.addParameter("pgtUrl", "https://www.github.com");

    return this.serviceValidateController.handleRequestInternal(
        request, new MockHttpServletResponse());
  }
  @Test
  public void verifyValidServiceTicket() throws Exception {
    final TicketGrantingTicket tId =
        getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());
    final ServiceTicket sId =
        getCentralAuthenticationService().grantServiceTicket(tId.getId(), TestUtils.getService());

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", TestUtils.getService().getId());
    request.addParameter("ticket", sId.getId());

    assertEquals(
        ServiceValidateController.DEFAULT_SERVICE_SUCCESS_VIEW_NAME,
        this.serviceValidateController
            .handleRequestInternal(request, new MockHttpServletResponse())
            .getViewName());
  }
  @Test
  public void verifyValidServiceTicketWithValidPgtAndProxyHandling() throws Exception {
    final TicketGrantingTicket tId =
        getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());
    final ServiceTicket sId =
        getCentralAuthenticationService().grantServiceTicket(tId.getId(), TestUtils.getService());

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", TestUtils.getService().getId());
    request.addParameter("ticket", sId.getId());
    request.addParameter("pgtUrl", "https://www.github.com");

    final ModelAndView modelAndView =
        this.serviceValidateController.handleRequestInternal(
            request, new MockHttpServletResponse());
    assertEquals(
        ServiceValidateController.DEFAULT_SERVICE_SUCCESS_VIEW_NAME, modelAndView.getViewName());
    assertNotNull(modelAndView.getModel().get("pgtIou"));
  }
/**
 * @author Scott Battaglia
 * @version $Revision: 1.1 $ $Date: 2005/08/19 18:27:17 $
 * @since 3.1
 */
public class TicketValidationExceptionTests extends TestCase {

  private static final String CODE = "INVALID_SERVICE";

  private Service service = TestUtils.getService();

  public void testThrowableConstructor() {
    final TicketValidationException t = new TicketValidationException(this.service);

    assertSame(CODE, t.getCode());
    assertEquals(this.service, t.getOriginalService());
  }
}
  @Test
  public void verifyValidServiceTicketWithDifferentEncoding() throws Exception {
    this.serviceValidateController.setProxyHandler(new Cas10ProxyHandler());
    final TicketGrantingTicket tId =
        getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());

    final String origSvc = "http://www.jasig.org?param=hello+world";
    final ServiceTicket sId =
        getCentralAuthenticationService()
            .grantServiceTicket(tId.getId(), TestUtils.getService(origSvc));

    final String reqSvc = "http://www.jasig.org?param=hello%20world";

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", TestUtils.getService(reqSvc).getId());
    request.addParameter("ticket", sId.getId());

    assertEquals(
        ServiceValidateController.DEFAULT_SERVICE_SUCCESS_VIEW_NAME,
        this.serviceValidateController
            .handleRequestInternal(request, new MockHttpServletResponse())
            .getViewName());
  }
 @Test
 public void testValidCredentials() {
   assertEquals(
       this.resolver.resolvePrincipal(TestUtils.getHttpBasedServiceCredentials()).getId(),
       TestUtils.getHttpBasedServiceCredentials().getCallbackUrl().toExternalForm());
 }
 @Test
 public void testValidSupportsCredentials() {
   assertTrue(this.resolver.supports(TestUtils.getHttpBasedServiceCredentials()));
 }
 @Test
 public void testInValidSupportsCredentials() {
   assertFalse(this.resolver.supports(TestUtils.getCredentialsWithSameUsernameAndPassword()));
 }
 @Test
 public void testProperUrl() {
   assertEquals(
       TestUtils.CONST_GOOD_URL,
       TestUtils.getHttpBasedServiceCredentials().getCallbackUrl().toExternalForm());
 }
 @Test
 public void testSatisfiesSpecOfFalse2() {
   assertTrue(
       new Cas20ProtocolValidationSpecification(false)
           .isSatisfiedBy(TestUtils.getAssertion(false)));
 }