incubator-amber-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1050674 [2/2] - in /incubator/amber/trunk/oauth-2.0/oauth2-resourceserver: ./ 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/o...
Date Sat, 18 Dec 2010 17:06:22 GMT
Added: incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/QueryOAuthValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/QueryOAuthValidatorTest.java?rev=1050674&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/QueryOAuthValidatorTest.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/QueryOAuthValidatorTest.java
Sat Dec 18 17:06:20 2010
@@ -0,0 +1,120 @@
+/**
+ *       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.rs.validator;
+
+import javax.servlet.http.HttpServletRequest;
+
+import junit.framework.Assert;
+
+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.rs.validator.QueryOAuthValidator;
+import org.junit.Test;
+import org.apache.amber.oauth2.common.utils.OAuthUtils;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+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 QueryOAuthValidatorTest {
+
+
+    @Test
+    public void testValidateWrongVersion() throws Exception {
+
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn("HMAC-SHA1");
+        expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[]
{"access_token"});
+        replay(request);
+        try {
+            QueryOAuthValidator qov = new QueryOAuthValidator();
+            qov.performAllValidations(request);
+            Assert.fail("Exception not thrown.");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+            Assert.assertEquals("Incorrect OAuth version. Found OAuth V1.0.", e.getDescription());
+        }
+        verify(request);
+
+    }
+
+    @Test
+    public void testValidateNoQuery() throws Exception {
+
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null);
+        expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(null);
+        replay(request);
+        try {
+            QueryOAuthValidator qov = new QueryOAuthValidator();
+            qov.performAllValidations(request);
+            Assert.fail("Exception not thrown.");
+        } catch (OAuthProblemException e) {
+            org.junit.Assert.assertTrue(OAuthUtils.isEmpty(e.getError()));
+            Assert.assertEquals("Missing OAuth token.", e.getDescription());
+        }
+        verify(request);
+
+    }
+
+    @Test
+    public void testValidateMultipleTokens() throws Exception {
+
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null);
+        expect(request.getParameterValues(OAuth.OAUTH_TOKEN))
+            .andStubReturn(new String[] {"access_token1", "access_token2"});
+        replay(request);
+        try {
+            QueryOAuthValidator qov = new QueryOAuthValidator();
+            qov.performAllValidations(request);
+            Assert.fail("Exception not thrown.");
+        } catch (OAuthProblemException e) {
+            Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
+            Assert.assertEquals("Multiple tokens attached.", e.getDescription());
+        }
+        verify(request);
+
+    }
+
+    @Test
+    public void testValidateToken() throws Exception {
+
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null);
+        expect(request.getParameterValues(OAuth.OAUTH_TOKEN)).andStubReturn(new String[]
{"access_token1"});
+        replay(request);
+        QueryOAuthValidator qov = new QueryOAuthValidator();
+        qov.performAllValidations(request);
+        verify(request);
+
+    }
+
+
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-resourceserver/src/test/java/org/apache/amber/oauth2/rs/validator/QueryOAuthValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message