Package org.mortbay.jetty.testing

Examples of org.mortbay.jetty.testing.ServletTester


    /*
     * Authorization Code Grant
     */
    public void testDoGet1() throws Exception {

        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AuthorizationServlet2.class, "/authorize");
        tester.setResourceBase("./web");
        tester.addServlet(JspServlet.class, "*.jsp");
        tester.start();

        String queryParameter = "response_type=code&client_id=myKey&state=xyz&redirect_uri=http%3A%2F%2Flocalhost%2FCookieJar%2FCallback";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("GET");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/authorize"+"?"+queryParameter);
        request.setVersion("HTTP/1.1");

        response.parse(tester.getResponses(request.generate()));

        assertEquals(200,response.getStatus());
        assertTrue(response.getContent().contains("<h3>\"CookieJar\" is trying to access your information.</h3>"));
        assertTrue(response.getContent().contains("<form name=\"authZForm\" action=\"auth\" method=\"POST\">\n" +
                "        <input type=\"text\" name=\"userId\" value=\"\" size=\"20\" /><br>\n" +
View Full Code Here


    /*
     * Error Case: unknown client id with error=invalid_client
     */
    public void testDoGet2() throws Exception {

        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AuthorizationServlet2.class, "/authorize");
        tester.setResourceBase("./web");
        tester.addServlet(JspServlet.class, "*.jsp");
        tester.start();

        String queryParameter = "response_type=code&client_id=invalidKey&state=xyz&redirect_uri=http%3A%2F%2Flocalhost%2FCookieJar%2FCallback";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("GET");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/authorize"+"?"+queryParameter);
        request.setVersion("HTTP/1.1");

        response.parse(tester.getResponses(request.generate()));

        assertEquals(302,response.getStatus());
        assertEquals("http://localhost/CookieJar/Callback?error=invalid_client&state=xyz",response.getHeader("location"));

    }
View Full Code Here

    /*
     * implicit grant
     */
    public void testDoGet3() throws Exception {

        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AuthorizationServlet2.class, "/authorize");
        tester.setResourceBase("./web");
        tester.addServlet(JspServlet.class, "*.jsp");
        tester.start();

        String queryParameter = "response_type=token&client_id=myKey&state=xyz&redirect_uri=http%3A%2F%2Flocalhost%2FCookieJar%2FCallback";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("GET");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/authorize"+"?"+queryParameter);
        request.setVersion("HTTP/1.1");

        response.parse(tester.getResponses(request.generate()));

        assertEquals(200,response.getStatus());
        assertTrue(response.getContent().contains("<h3>\"CookieJar\" is trying to access your information.</h3>"));
        assertTrue(response.getContent().contains("<form name=\"authZForm\" action=\"auth\" method=\"POST\">\n" +
                "        <input type=\"text\" name=\"userId\" value=\"\" size=\"20\" /><br>\n" +
View Full Code Here

    /*
     * implicit grant2
     */
    public void testDoGet4() throws Exception {

        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AuthorizationServlet2.class, "/authorize");
        tester.setResourceBase("./web");
        tester.addServlet(JspServlet.class, "*.jsp");
        tester.start();

        String queryParameter = "response_type=token&client_id=myKey&state=xyz&redirect_uri=http%3A%2F%2Flocalhost%2FCookieJar%2FCallback";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("GET");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/authorize"+"?"+queryParameter);
        request.setVersion("HTTP/1.1");

        response.parse(tester.getResponses(request.generate()));

        assertEquals(200,response.getStatus());
        assertTrue(response.getContent().contains("<h3>\"CookieJar\" is trying to access your information.</h3>"));
        assertTrue(response.getContent().contains("<form name=\"authZForm\" action=\"auth\" method=\"POST\">\n" +
                "        <input type=\"text\" name=\"userId\" value=\"\" size=\"20\" /><br>\n" +
                "        <input type=\"hidden\" name=\"redirect_uri\" value=\"http://localhost/CookieJar/Callback\"/>\n" +
                "        <input type=\"hidden\" name=\"client_id\" value=\"myKey\"/>        \n" +
                "        <input type=\"submit\" name=\"Authorize\" value=\"Authorize\"/>\n" +
                "    </form>"));


        request = new HttpTester();
        response = new HttpTester();

        String postParameter = "userId=yutaka&response_type=token&client_id=myKey&state=xyz"+
                "&redirect_uri=http%3A%2F%2Flocalhost%2FCookieJar%2FCallback";

        request.setMethod("POST");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/authorize");
        request.setVersion("HTTP/1.1");
        request.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        request.setContent(postParameter);

        response.parse(tester.getResponses(request.generate()));

        assertEquals(302,response.getStatus());
        Pattern pattern = Pattern.compile("http://localhost/CookieJar/Callback#access_token=.+&token_type=bearer&expires_in=3600&state=xyz");
        Matcher matcher = pattern.matcher(response.getHeader("Location"));
        assertTrue(matcher.matches());
View Full Code Here

    }

    public void testDoGet5() throws Exception {

        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AuthorizationServlet2.class, "/authorize");
        tester.setResourceBase("./web");
        tester.addServlet(JspServlet.class, "*.jsp");
        tester.start();

        String queryParameter = "response_type=token&client_id=invalidKey&state=xyz&redirect_uri=http%3A%2F%2Flocalhost%2FCookieJar%2FCallback";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("GET");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/authorize"+"?"+queryParameter);
        request.setVersion("HTTP/1.1");

        response.parse(tester.getResponses(request.generate()));

        assertEquals(302,response.getStatus());
        assertEquals("http://localhost/CookieJar/Callback?error=invalid_client&state=xyz",response.getHeader("location"));

    }
View Full Code Here

    private ServletTester tester;

    @Before
    public void setUp() throws Exception {
        tester = new ServletTester();
        tester.setContextPath("/");
        tester.addServlet(TestableServlet.class, "/*");
        tester.start();
        content = "test";
        acceptHeader = null;
View Full Code Here

   
    /* ------------------------------------------------------------ */
    protected void setUp() throws Exception
    {
        super.setUp();
        tester=new ServletTester();
        tester.setContextPath("/context");
        tester.addServlet(TestServlet.class, "/servlet/*");
        tester.addServlet(HelloServlet.class, "/hello/*");
        tester.addServlet("org.mortbay.jetty.servlet.DefaultServlet", "/");
        tester.start();
View Full Code Here

    private final int NUM_LOOPS = 10;
    private final int MAX_QOS = 5;
   
    protected void setUp() throws Exception
    {
        _tester = new ServletTester();
        _tester.setContextPath("/context");
        _tester.addServlet(TestServlet.class, "/test");
        TestServlet.__maxSleepers=0;
        TestServlet.__sleepers=0;
       
View Full Code Here

    private int _port;
   
    private int _maxRequestMs = 200;
    protected void setUp() throws Exception
    {
        _tester = new ServletTester();
        HttpURI uri=new HttpURI(_tester.createSocketConnector(true));
        _host=uri.getHost();
        _port=uri.getPort();
       
        _tester.setContextPath("/ctx");
View Full Code Here

     *
     * @throws Exception
     */
    public void testSelfRefForwardDenialOfService() throws Exception
    {
        ServletTester tester = new ServletTester();
        tester.setContextPath("/tests");
     
        ServletHolder dispatch = tester.addServlet(DispatchServlet.class,"/dispatch/*");
        tester.addServlet(DefaultServlet.class,"/");
        tester.start();
       
        StringBuffer req1 = new StringBuffer();
        req1.append("GET /tests/dispatch/includeN/"+dispatch.getName()+" HTTP/1.1\n");
        req1.append("Host: tester\n");
        req1.append("Connection: close\n");
        req1.append("\n");

        String response = tester.getResponses(req1.toString());
       
        String msg = "Response code on SelfRefDoS";

        assertFalse(msg + " should not be code 500.",response.startsWith("HTTP/1.1 500 "));
        assertTrue(msg + " should return error code 403 (Forbidden)", response.startsWith("HTTP/1.1 403 "));
View Full Code Here

TOP

Related Classes of org.mortbay.jetty.testing.ServletTester

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.