Package org.mortbay.jetty.testing

Examples of org.mortbay.jetty.testing.ServletTester


      o2c.setProperty("name",o2c.clientId);
      OAuth2Accessor o2a = new OAuth2Accessor(o2c);
      o2a.setProperty("authorized",true);
      SampleOAuth2Provider.generateCode(o2a);

        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AccessTokenServlet2.class, "/token");
        tester.start();

        String postParameter = "grant_type=authorization_code&code="+o2a.code+
                "&client_id=myKey&client_secret=mySecret&state=xyz&redirect_uri=http%3A%2F%2Flocalhost%2FCookieJar%2FCallback";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("POST");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/token");
        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(200,response.getStatus());
        assertEquals("{\"access_token\":\"" + o2a.accessToken +
                "\",\"token_type\":\"" + o2a.tokenType +
                "\",\"expires_in\":\"3600\",\"refresh_token\":\"" + o2a.refreshToken +
View Full Code Here


        o2c.setProperty("name",o2c.clientId);
        OAuth2Accessor o2a = new OAuth2Accessor(o2c);
        o2a.setProperty("authorized",true);
        SampleOAuth2Provider.generateCode(o2a);

        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AccessTokenServlet2.class, "/token");
        tester.start();

        String postParameter = "grant_type=authorization_code&code="+o2a.code+
                "&client_id=myKey&client_secret=invalidSecret&state=xyz&redirect_uri=http%3A%2F%2Flocalhost%2FCookieJar%2FCallback";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("POST");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/token");
        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(401,response.getStatus());
        assertEquals("{\"error\":\"invalid_client\"}",response.getContent());

    }
View Full Code Here

        o2c.setProperty("name",o2c.clientId);
        OAuth2Accessor o2a = new OAuth2Accessor(o2c);
        o2a.setProperty("authorized",true);
        SampleOAuth2Provider.generateCode(o2a);

        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AccessTokenServlet2.class, "/token");
        tester.start();

        String postParameter = "grant_type=authorization_code&code="+o2a.code+
                "&state=xyz&redirect_uri=http%3A%2F%2Flocalhost%2FCookieJar%2FCallback";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("POST");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/token");
        request.setVersion("HTTP/1.1");
        request.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        String userPass = new String(Base64.encodeBase64("myKey:mySecret".getBytes()), "UTF-8");
        request.setHeader("Authorization", "Basic "+userPass);
        request.setContent(postParameter);

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

        assertEquals(200,response.getStatus());
        assertEquals("{\"access_token\":\"" + o2a.accessToken +
                "\",\"token_type\":\"" + o2a.tokenType +
                "\",\"expires_in\":\"3600\",\"refresh_token\":\"" + o2a.refreshToken +
View Full Code Here

        o2c.setProperty("name",o2c.clientId);
        OAuth2Accessor o2a = new OAuth2Accessor(o2c);
        o2a.setProperty("authorized",true);
        SampleOAuth2Provider.generateCode(o2a);

        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AccessTokenServlet2.class, "/token");
        tester.start();

        String postParameter = "grant_type=authorization_code&code="+o2a.code+
                "&state=xyz&redirect_uri=http%3A%2F%2Flocalhost%2FCookieJar%2FCallback";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("POST");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/token");
        request.setVersion("HTTP/1.1");
        request.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        String userPass = new String(Base64.encodeBase64("invalidKey:mySecret".getBytes()), "UTF-8");
        request.setHeader("Authorization", "Basic "+userPass);
        request.setContent(postParameter);

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

        assertEquals(401,response.getStatus());
        assertEquals("{\"error\":\"invalid_client\"}",response.getContent());

    }
View Full Code Here

        o2c.setProperty("name",o2c.clientId);
        OAuth2Accessor o2a = new OAuth2Accessor(o2c);
        o2a.setProperty("authorized",true);
        SampleOAuth2Provider.generateCode(o2a);

        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AccessTokenServlet2.class, "/token");
        tester.start();

        String postParameter = "grant_type=authorization_code&code="+o2a.code+
                "&state=xyz&redirect_uri=http%3A%2F%2Flocalhost%2FCookieJar%2FCallback";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("POST");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/token");
        request.setVersion("HTTP/1.1");
        request.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        String userPass = new String(Base64.encodeBase64("myKey:invalidSecret".getBytes()), "UTF-8");
        request.setHeader("Authorization", "Basic "+userPass);
        request.setContent(postParameter);

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

        assertEquals(401,response.getStatus());
        assertEquals("{\"error\":\"invalid_client\"}",response.getContent());

    }
View Full Code Here

        o2c.setProperty("name",o2c.clientId);
        OAuth2Accessor o2a = new OAuth2Accessor(o2c);
        o2a.setProperty("authorized",true);
        SampleOAuth2Provider.generateCode(o2a);

        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AccessTokenServlet2.class, "/token");
        tester.start();

        String postParameter = "grant_type=authorization_code&code="+o2a.code+
                "&state=xyz&redirect_uri=http%3A%2F%2Flocalhost%2FCookieJar%2FCallback";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("POST");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/token");
        request.setVersion("HTTP/1.1");
        request.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        String userPass = new String(Base64.encodeBase64("myKey+mySecret".getBytes()), "UTF-8");
        request.setHeader("Authorization", "Basic "+userPass);
        request.setContent(postParameter);

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

        assertEquals(401,response.getStatus());
        assertEquals("{\"error\":\"invalid_client\"}",response.getContent());

    }
View Full Code Here

     * Client Password grant
     */
    public void testDoPost7() throws Exception {

        try{
        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AccessTokenServlet2.class, "/token");
        tester.start();

        String postParameter = "grant_type=password&username=yutaka&password=obuchi";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("POST");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/token");
        request.setVersion("HTTP/1.1");
        request.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        String userPass = new String(Base64.encodeBase64("myKey:mySecret".getBytes()), "UTF-8");
        request.setHeader("Authorization", "Basic "+userPass);
        request.setContent(postParameter);

        response.parse(tester.getResponses(request.generate()));
        System.out.println("yutaka"+response.getContent());
        assertEquals(200,response.getStatus());
        Pattern pattern = Pattern.compile("\\{\"access_token\":\".+\",\"token_type\":\"bearer\",\"expires_in\":\"3600\",\"refresh_token\":\".+\"\\}");
        Matcher matcher = pattern.matcher(response.getContent());
        assertTrue(matcher.matches());
View Full Code Here

    }

    public void testDoPost8() throws Exception {


        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AccessTokenServlet2.class, "/token");
        tester.start();

        String postParameter = "grant_type=password&username=invalid&obuchi";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("POST");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/token");
        request.setVersion("HTTP/1.1");
        request.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        String userPass = new String(Base64.encodeBase64("myKey:invalidSecret".getBytes()), "UTF-8");
        request.setHeader("Authorization", "Basic "+userPass);
        request.setContent(postParameter);

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

        assertEquals(401,response.getStatus());
        assertEquals("{\"error\":\"invalid_client\"}",response.getContent());

    }
View Full Code Here

     * Client Credentials grant
     */
    public void testDoPost9() throws Exception {


        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AccessTokenServlet2.class, "/token");
        tester.start();

        String postParameter = "grant_type=client_credentials";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("POST");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/token");
        request.setVersion("HTTP/1.1");
        request.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        String userPass = new String(Base64.encodeBase64("myKey:mySecret".getBytes()), "UTF-8");
        request.setHeader("Authorization", "Basic "+userPass);
        request.setContent(postParameter);

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

        assertEquals(200,response.getStatus());
        Pattern pattern = Pattern.compile("\\{\"access_token\":\".+\",\"token_type\":\"bearer\",\"expires_in\":\"3600\"\\}");
        Matcher matcher = pattern.matcher(response.getContent());
        assertTrue(matcher.matches());
View Full Code Here

    }

    public void testDoPost10() throws Exception {


        ServletTester tester=new ServletTester();
        tester.setContextPath("/test");
        tester.addServlet(AccessTokenServlet2.class, "/token");
        tester.start();

        String postParameter = "grant_type=client_credentials";
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("POST");
        request.setHeader("Host","server.example.com");
        request.setURI("/test/token");
        request.setVersion("HTTP/1.1");
        request.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        String userPass = new String(Base64.encodeBase64("myKey:invalidSecret".getBytes()), "UTF-8");
        request.setHeader("Authorization", "Basic "+userPass);
        request.setContent(postParameter);

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

        assertEquals(401,response.getStatus());
        assertEquals("{\"error\":\"invalid_client\"}",response.getContent());

    }
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.