incubator-amber-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1050669 [2/2] - in /incubator/amber/trunk/oauth-2.0/oauth2-authzserver: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/amber/ src/main/java/org/apache/amber/oauth2/ src/main/java/org/...
Date Sat, 18 Dec 2010 16:58:50 GMT
Added: incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/OAuthRequestTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/OAuthRequestTest.java?rev=1050669&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/OAuthRequestTest.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/OAuthRequestTest.java Sat Dec 18 16:58:49 2010
@@ -0,0 +1,824 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.amber.oauth2.as;
+
+import java.util.Set;
+import javax.servlet.http.HttpServletRequest;
+
+import junit.framework.Assert;
+
+import org.apache.amber.oauth2.as.request.OAuthAuthzRequest;
+import org.apache.amber.oauth2.as.request.OAuthRequest;
+import org.apache.amber.oauth2.as.request.OAuthTokenRequest;
+import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.error.OAuthError;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.message.types.GrantType;
+import org.apache.amber.oauth2.common.message.types.ResponseType;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.fail;
+
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class OAuthRequestTest {
+
+    @Test
+    public void testWrongResponseGetRequestParam() throws Exception {
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(OAuth.ContentType.URL_ENCODED);
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
+        expect(request.getParameter("param")).andStubReturn("someparam");
+        replay(request);
+
+        try {
+            new OAuthAuthzRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(null);
+        expect(request.getParameter("param")).andStubReturn("someparam");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
+        replay(request);
+
+        try {
+            new OAuthAuthzRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+    }
+
+    @Test
+    public void testCodeRequestInvalidMethod() throws Exception {
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(ResponseType.CODE.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.PUT);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        replay(request);
+
+        OAuthRequest req = null;
+        try {
+            new OAuthAuthzRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+    }
+
+
+    @Test
+    public void testCodeRequestMissingParameter() throws Exception {
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(ResponseType.CODE.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn(null);
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        replay(request);
+
+        OAuthRequest req = null;
+        try {
+            new OAuthAuthzRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(ResponseType.CODE.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn(null);
+        replay(request);
+
+        try {
+            new OAuthAuthzRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+    }
+
+    @Test
+    public void testValidCodeRequest() throws Exception {
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(ResponseType.CODE.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        replay(request);
+
+        OAuthRequest req = null;
+        try {
+            new OAuthAuthzRequest(request);
+        } catch (OAuthProblemException e) {
+            fail("Exception not expected");
+        }
+
+        verify(request);
+
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(ResponseType.CODE.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        replay(request);
+
+        try {
+            new OAuthAuthzRequest(request);
+        } catch (OAuthProblemException e) {
+            fail("Exception not expected");
+        }
+
+        verify(request);
+    }
+
+    @Test
+    public void testTokenWrongGrantType() throws Exception {
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)).andStubReturn(OAuth.ContentType.URL_ENCODED);
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
+        expect(request.getParameter("param")).andStubReturn("someparam");
+        replay(request);
+
+        OAuthRequest req = null;
+        try {
+            req = new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)).andStubReturn(null);
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
+        expect(request.getParameter("param")).andStubReturn("someparam");
+        replay(request);
+
+        try {
+            req = new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+    }
+
+    @Test
+    public void testTokenRequestInvalidMethod() throws Exception {
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.AUTHORIZATION_CODE.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+        reset(request);
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.ASSERTION.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+        verify(request);
+
+        reset(request);
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.PASSWORD.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+        reset(request);
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.REFRESH_TOKEN.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+        verify(request);
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.NONE.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+    }
+
+    @Test
+    public void testTokenRequestInvalidContentType() throws Exception {
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.AUTHORIZATION_CODE.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+        verify(request);
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.ASSERTION.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.PASSWORD.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.REFRESH_TOKEN.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.NONE.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+    }
+
+    @Test
+    public void testTokenAuthCodeRequestMissingParameter() throws Exception {
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.AUTHORIZATION_CODE.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn(null);
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        expect(request.getParameter(OAuth.OAUTH_CODE)).andStubReturn("test_code");
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.AUTHORIZATION_CODE.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn(null);
+        expect(request.getParameter(OAuth.OAUTH_CODE)).andStubReturn("test_code");
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+        verify(request);
+
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.AUTHORIZATION_CODE.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        expect(request.getParameter(OAuth.OAUTH_CODE)).andStubReturn(null);
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+    }
+
+    @Test
+    public void testTokenPasswordRequestMissingParameter() throws Exception {
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.PASSWORD.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
+        expect(request.getParameter(OAuth.OAUTH_USERNAME)).andStubReturn(null);
+        expect(request.getParameter(OAuth.OAUTH_PASSWORD)).andStubReturn("test_password");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+        verify(request);
+
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.PASSWORD.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
+        expect(request.getParameter(OAuth.OAUTH_USERNAME)).andStubReturn("test_username");
+        expect(request.getParameter(OAuth.OAUTH_PASSWORD)).andStubReturn("");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.PASSWORD.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn(null);
+        expect(request.getParameter(OAuth.OAUTH_USERNAME)).andStubReturn("test_username");
+        expect(request.getParameter(OAuth.OAUTH_PASSWORD)).andStubReturn("test_password");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+    }
+
+    @Test
+    public void testTokenAssertionRequestMissingParameter() throws Exception {
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.ASSERTION.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
+
+        expect(request.getParameter(OAuth.OAUTH_ASSERTION)).andStubReturn(null);
+        expect(request.getParameter(OAuth.OAUTH_ASSERTION_TYPE)).andStubReturn("test_type");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.ASSERTION.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
+
+        expect(request.getParameter(OAuth.OAUTH_ASSERTION)).andStubReturn("test_assertion");
+        expect(request.getParameter(OAuth.OAUTH_ASSERTION_TYPE)).andStubReturn(null);
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.ASSERTION.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
+
+        expect(request.getParameter(OAuth.OAUTH_ASSERTION)).andStubReturn("");
+        expect(request.getParameter(OAuth.OAUTH_ASSERTION_TYPE)).andStubReturn("");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+    }
+
+    @Test
+    public void testRefreshTokenRequestMissingParameter() throws Exception {
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.REFRESH_TOKEN.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
+        expect(request.getParameter(OAuth.OAUTH_REFRESH_TOKEN)).andStubReturn(null);
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.REFRESH_TOKEN.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("");
+        expect(request.getParameter(OAuth.OAUTH_REFRESH_TOKEN)).andStubReturn("refresh_token");
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.REFRESH_TOKEN.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://www.example.com/red");
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn(null);
+        expect(request.getParameter(OAuth.OAUTH_REFRESH_TOKEN)).andStubReturn(null);
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
+        replay(request);
+
+        try {
+            new OAuthTokenRequest(request);
+            fail("Exception expected");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+        }
+
+        verify(request);
+    }
+
+    @Test
+    public void testValidTokenRequest() throws Exception {
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.AUTHORIZATION_CODE.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        expect(request.getParameter(OAuth.OAUTH_CODE)).andStubReturn("test_code");
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("test_secret");
+        replay(request);
+
+        OAuthTokenRequest req = null;
+        try {
+            req = new OAuthTokenRequest(request);
+
+        } catch (OAuthProblemException e) {
+            fail("Exception not expected");
+        }
+        Assert.assertEquals(GrantType.AUTHORIZATION_CODE.toString(), req.getGrantType());
+        Assert.assertEquals("test_client", req.getClientId());
+        Assert.assertEquals("http://example.com/callback", req.getRedirectURI());
+        Assert.assertEquals("test_code", req.getCode());
+
+        verify(request);
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.PASSWORD.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
+        expect(request.getParameter(OAuth.OAUTH_USERNAME)).andStubReturn("username_test");
+        expect(request.getParameter(OAuth.OAUTH_PASSWORD)).andStubReturn("test_password");
+        replay(request);
+
+        try {
+            req = new OAuthTokenRequest(request);
+
+        } catch (OAuthProblemException e) {
+            fail("Exception not expected");
+        }
+        Assert.assertEquals("client_id", req.getClientId());
+        Assert.assertEquals("username_test", req.getUsername());
+        Assert.assertEquals("test_password", req.getPassword());
+
+        verify(request);
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.ASSERTION.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_ASSERTION)).andStubReturn("test_assertion");
+        expect(request.getParameter(OAuth.OAUTH_ASSERTION_TYPE)).andStubReturn("test_type");
+        replay(request);
+
+        try {
+            req = new OAuthTokenRequest(request);
+
+        } catch (OAuthProblemException e) {
+            fail("Exception not expected");
+        }
+        Assert.assertEquals("test_assertion", req.getAssertion());
+        Assert.assertEquals("test_type", req.getAssertionType());
+
+        verify(request);
+        reset(request);
+
+        expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
+            .andStubReturn(GrantType.REFRESH_TOKEN.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
+        expect(request.getParameter(OAuth.OAUTH_REFRESH_TOKEN)).andStubReturn("refresh_token");
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
+        replay(request);
+
+        try {
+            req = new OAuthTokenRequest(request);
+
+        } catch (OAuthProblemException e) {
+            fail("Exception not expected");
+        }
+        Assert.assertEquals("client_id", req.getClientId());
+        Assert.assertEquals("refresh_token", req.getRefreshToken());
+        Assert.assertEquals("secret", req.getClientSecret());
+
+        verify(request);
+
+
+    }
+
+    @Test
+    public void testScopes() throws Exception {
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+
+        expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn(ResponseType.CODE.toString());
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("test_client");
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        expect(request.getParameter(OAuth.OAUTH_SCOPE)).andStubReturn("album photo");
+        replay(request);
+
+        OAuthRequest req = null;
+        try {
+            req = new OAuthAuthzRequest(request);
+        } catch (OAuthProblemException e) {
+            fail("Exception not expected");
+        }
+
+        Set<String> scopes = req.getScopes();
+
+        Assert.assertTrue(findScope(scopes, "album"));
+        Assert.assertTrue(findScope(scopes, "photo"));
+
+        verify(request);
+    }
+
+    private boolean findScope(Set<String> scopes, String scope) {
+        for (String s : scopes) {
+            if (s.equals(scope)) {
+                return true;
+            }
+        }
+        return false;
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/OAuthRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/UUIDValueGeneratorTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/UUIDValueGeneratorTest.java?rev=1050669&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/UUIDValueGeneratorTest.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/UUIDValueGeneratorTest.java Sat Dec 18 16:58:49 2010
@@ -0,0 +1,42 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.amber.oauth2.as;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.amber.oauth2.as.issuer.UUIDValueGenerator;
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class UUIDValueGeneratorTest extends Assert {
+    @Test
+    public void testGenerateValue() throws Exception {
+        UUIDValueGenerator uvg = new UUIDValueGenerator();
+        Assert.assertNotNull(uvg.generateValue());
+
+        Assert.assertNotNull(uvg.generateValue("test"));
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/UUIDValueGeneratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/response/OAuthASResponseTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/response/OAuthASResponseTest.java?rev=1050669&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/response/OAuthASResponseTest.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/response/OAuthASResponseTest.java Sat Dec 18 16:58:49 2010
@@ -0,0 +1,141 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.amber.oauth2.as.response;
+
+import org.apache.amber.oauth2.as.response.OAuthASResponse;
+import org.apache.amber.oauth2.common.error.OAuthError;
+import org.apache.amber.oauth2.common.message.OAuthResponse;
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class OAuthASResponseTest {
+
+    @Test
+    public void testAuthzResponse() throws Exception {
+        OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(200)
+            .location("http://www.example.com")
+            .setCode("code")
+            .setAccessToken("access_111")
+            .setExpiresIn("400")
+            .setState("ok")
+            .setParam("testValue", "value2")
+            .buildQueryMessage();
+
+        String url = oAuthResponse.getLocationUri();
+
+        Assert.assertEquals("http://www.example.com?testValue=value2&state=ok&code=code"
+            + "#expires_in=400&access_token=access_111", url);
+        Assert.assertEquals(200, oAuthResponse.getResponseStatus());
+
+    }
+
+    @Test
+    public void testTokenResponse() throws Exception {
+
+        OAuthResponse oAuthResponse = OAuthASResponse.tokenResponse(200).setAccessToken("access_token")
+            .setExpiresIn("200").setRefreshToken("refresh_token2")
+            .buildBodyMessage();
+
+        String body = oAuthResponse.getBody();
+        Assert.assertEquals(
+            "expires_in=200&refresh_token=refresh_token2&access_token=access_token",
+            body);
+
+    }
+
+    @Test
+    public void testTokenResponseAdditionalParam() throws Exception {
+
+        OAuthResponse oAuthResponse = OAuthASResponse.tokenResponse(200).setAccessToken("access_token")
+            .setExpiresIn("200").setRefreshToken("refresh_token2").setParam("some_param", "new_param")
+            .buildBodyMessage();
+
+        String body = oAuthResponse.getBody();
+        Assert.assertEquals(
+            "some_param=new_param&expires_in=200&refresh_token=refresh_token2&access_token=access_token",
+            body);
+
+    }
+
+    @Test
+    public void testErrorResponse() throws Exception {
+
+        OAuthProblemException ex = OAuthProblemException
+            .error(OAuthError.CodeResponse.ACCESS_DENIED, "Access denied")
+            .setParameter("testparameter", "testparameter_value")
+            .scope("album")
+            .uri("http://www.example.com/error");
+
+        OAuthResponse oAuthResponse = OAuthResponse.errorResponse(400).error(ex).buildJSONMessage();
+
+        Assert.assertEquals(
+            "{\"error_uri\":\"http:\\/\\/www.example.com\\/error\",\"error\":\"access_denied\",\""
+                + "error_description\":\"Access denied\"}",
+            oAuthResponse.getBody());
+
+
+        oAuthResponse = OAuthResponse.errorResponse(500)
+            .location("http://www.example.com/redirect?param2=true").error(ex).buildQueryMessage();
+        Assert.assertEquals(
+            "http://www.example.com/redirect?param2=true&error_uri=http%3A%2F%2Fwww.example.com%2Ferror"
+                + "&error=access_denied&error_description=Access+denied",
+            oAuthResponse.getLocationUri());
+    }
+
+    @Test
+    public void testErrorResponse2() throws Exception {
+        OAuthProblemException ex = OAuthProblemException
+            .error(OAuthError.CodeResponse.ACCESS_DENIED, "Access denied")
+            .setParameter("testparameter", "testparameter_value")
+            .scope("album")
+            .uri("http://www.example.com/error");
+
+        OAuthResponse oAuthResponse = OAuthResponse.errorResponse(500)
+            .location("http://www.example.com/redirect?param2=true").error(ex).buildQueryMessage();
+        Assert.assertEquals(
+            "http://www.example.com/redirect?param2=true&error_uri=http%3A%2F%2Fwww.example.com%2Ferror"
+                + "&error=access_denied&error_description=Access+denied",
+            oAuthResponse.getLocationUri());
+    }
+
+    @Test
+    public void testHeaderResponse() throws Exception {
+        OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(400).setCode("oauth_code")
+            .setState("state_ok")
+            .buildHeaderMessage();
+
+        String header = oAuthResponse.getHeader(OAuth.HeaderType.WWW_AUTHENTICATE);
+        Assert.assertEquals("OAuth state=\"state_ok\",code=\"oauth_code\"", header);
+
+        header = oAuthResponse.getHeaders().get(OAuth.HeaderType.WWW_AUTHENTICATE);
+        Assert.assertEquals("OAuth state=\"state_ok\",code=\"oauth_code\"", header);
+    }
+
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/response/OAuthASResponseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/CodeTokenValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/CodeTokenValidatorTest.java?rev=1050669&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/CodeTokenValidatorTest.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/CodeTokenValidatorTest.java Sat Dec 18 16:58:49 2010
@@ -0,0 +1,84 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.amber.oauth2.as.validator;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.amber.oauth2.as.validator.CodeTokenValidator;
+import org.apache.amber.oauth2.common.OAuth;
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class CodeTokenValidatorTest {
+    @Test
+    public void testValidateMethod() throws Exception {
+        HttpServletRequest request = createStrictMock(HttpServletRequest.class);
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
+
+        replay(request);
+        CodeTokenValidator validator = new CodeTokenValidator();
+        validator.validateMethod(request);
+
+        verify(request);
+
+        reset(request);
+
+        request = createStrictMock(HttpServletRequest.class);
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+
+        replay(request);
+        validator = new CodeTokenValidator();
+        validator.validateMethod(request);
+
+        verify(request);
+
+        reset(request);
+
+        request = createStrictMock(HttpServletRequest.class);
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.DELETE);
+
+        replay(request);
+        validator = new CodeTokenValidator();
+
+        try {
+            validator.validateMethod(request);
+            Assert.fail("Expected validation exception");
+        } catch (OAuthProblemException e) {
+            //ok, expected
+        }
+
+        verify(request);
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/CodeTokenValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/TokenValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/TokenValidatorTest.java?rev=1050669&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/TokenValidatorTest.java (added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/TokenValidatorTest.java Sat Dec 18 16:58:49 2010
@@ -0,0 +1,102 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.amber.oauth2.as.validator;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.amber.oauth2.as.validator.TokenValidator;
+import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class TokenValidatorTest {
+    @Test
+    public void testValidateMethod() throws Exception {
+        HttpServletRequest request = createStrictMock(HttpServletRequest.class);
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
+
+        replay(request);
+        TokenValidator validator = new TokenValidator();
+        validator.validateMethod(request);
+
+        verify(request);
+
+        reset(request);
+
+        request = createStrictMock(HttpServletRequest.class);
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
+
+        replay(request);
+        validator = new TokenValidator();
+        validator.validateMethod(request);
+
+        verify(request);
+
+        reset(request);
+
+        request = createStrictMock(HttpServletRequest.class);
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.DELETE);
+
+        replay(request);
+        validator = new TokenValidator();
+
+        try {
+            validator.validateMethod(request);
+            Assert.fail("Expected validation exception");
+        } catch (OAuthProblemException e) {
+            //ok, expected
+        }
+
+        verify(request);
+    }
+
+    @Test
+    public void testRequiredParams() throws Exception {
+        HttpServletRequest request = createStrictMock(HttpServletRequest.class);
+
+        expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.GET);
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+
+        expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
+        expect(request.getParameter(OAuth.OAUTH_RESPONSE_TYPE)).andStubReturn("response_type");
+        expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
+
+        replay(request);
+
+        TokenValidator validator = new TokenValidator();
+        validator.performAllValidations(request);
+        verify(request);
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-authzserver/src/test/java/org/apache/amber/oauth2/as/validator/TokenValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message