@Test public void testInvalidResponse() throws Exception { final String RESPONSE = "<root />"; server.content = RESPONSE.getBytes(server.encoding); try { this.ticketValidator.validate("test", "test"); fail("ValidationException expected due to invalid response."); } catch (final TicketValidationException e) { // expected } } }
@Test public void testNoResponse() throws UnsupportedEncodingException { final String RESPONSE = "<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'><cas:authenticationFailure code=\"INVALID_TICKET\">Ticket ST-1856339-aA5Yuvrxzpv8Tau1cYQ7 not recognized</cas:authenticationFailure></cas:serviceResponse>"; server.content = RESPONSE.getBytes(server.encoding); try { this.ticketValidator.validate("test", "test"); fail("ValidationException expected due to 'no' response"); } catch (final TicketValidationException e) { // expected } }
@Test public void testYesResponseButNoPgt() throws TicketValidationException, UnsupportedEncodingException { final String USERNAME = "username"; final String RESPONSE = "<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'><cas:authenticationSuccess><cas:user>" + USERNAME + "</cas:user></cas:authenticationSuccess></cas:serviceResponse>"; server.content = RESPONSE.getBytes(server.encoding); final Assertion assertion = this.ticketValidator.validate("test", "test"); assertEquals(USERNAME, assertion.getPrincipal().getName()); }
@Test public void testYesResponseWithPgt() throws TicketValidationException, UnsupportedEncodingException { final String USERNAME = "username"; final String PGTIOU = "testPgtIou"; final String PGT = "test"; final String RESPONSE = "<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'><cas:authenticationSuccess><cas:user>" + USERNAME + "</cas:user><cas:proxyGrantingTicket>" + PGTIOU + "</cas:proxyGrantingTicket></cas:authenticationSuccess></cas:serviceResponse>"; server.content = RESPONSE.getBytes(server.encoding); this.proxyGrantingTicketStorage.save(PGTIOU, PGT); final Assertion assertion = this.ticketValidator.validate("test", "test"); assertEquals(USERNAME, assertion.getPrincipal().getName()); // assertEquals(PGT, assertion.getProxyGrantingTicketId()); }
@Test public void testGetAttributes() throws TicketValidationException, UnsupportedEncodingException { final String USERNAME = "username"; final String PGTIOU = "testPgtIou"; final String RESPONSE = "<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'><cas:authenticationSuccess><cas:user>" + USERNAME + "</cas:user><cas:proxyGrantingTicket>" + PGTIOU + "</cas:proxyGrantingTicket><cas:attributes><cas:password>test</cas:password><cas:eduPersonId>id</cas:eduPersonId><cas:longAttribute>test1\n\ntest</cas:longAttribute><cas:multivaluedAttribute>value1</cas:multivaluedAttribute><cas:multivaluedAttribute>value2</cas:multivaluedAttribute></cas:attributes></cas:authenticationSuccess></cas:serviceResponse>"; server.content = RESPONSE.getBytes(server.encoding); final Assertion assertion = this.ticketValidator.validate("test", "test"); assertEquals(USERNAME, assertion.getPrincipal().getName()); assertEquals("test", assertion.getPrincipal().getAttributes().get("password")); assertEquals("id", assertion.getPrincipal().getAttributes().get("eduPersonId")); assertEquals("test1\n\ntest", assertion.getPrincipal().getAttributes().get("longAttribute")); try { List<?> multivalued = (List<?>) assertion.getPrincipal().getAttributes().get("multivaluedAttribute"); assertArrayEquals(new String[] { "value1", "value2" }, multivalued.toArray()); } catch (Exception e) { fail("'multivaluedAttribute' attribute expected as List<Object> object."); } //assertEquals(PGT, assertion.getProxyGrantingTicketId()); }