camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhira...@apache.org
Subject camel git commit: CAMEL-8426: fixed invalid client id handling in Box component, added integration test for same
Date Mon, 02 Mar 2015 19:05:47 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.14.x 1d08744c2 -> 96ec3ac51


CAMEL-8426: fixed invalid client id handling in Box component, added integration test for
same


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/96ec3ac5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/96ec3ac5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/96ec3ac5

Branch: refs/heads/camel-2.14.x
Commit: 96ec3ac5135e5fb03952b630336a61078de45089
Parents: 1d08744
Author: Dhiraj Bokde <dhirajsb@yahoo.com>
Authored: Mon Mar 2 11:04:54 2015 -0800
Committer: Dhiraj Bokde <dhirajsb@yahoo.com>
Committed: Mon Mar 2 11:05:39 2015 -0800

----------------------------------------------------------------------
 .../component/box/internal/LoginAuthFlowUI.java | 25 ++++++
 .../box/InvalidClientIdIntegrationTest.java     | 83 ++++++++++++++++++++
 2 files changed, 108 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/96ec3ac5/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java
b/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java
index babda28..d5d2d33 100644
--- a/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java
+++ b/components/camel-box/src/main/java/org/apache/camel/component/box/internal/LoginAuthFlowUI.java
@@ -40,15 +40,21 @@ import com.gargoylesoftware.htmlunit.Page;
 import com.gargoylesoftware.htmlunit.ProxyConfig;
 import com.gargoylesoftware.htmlunit.WebClient;
 import com.gargoylesoftware.htmlunit.WebClientOptions;
+import com.gargoylesoftware.htmlunit.WebRequest;
+import com.gargoylesoftware.htmlunit.WebResponse;
 import com.gargoylesoftware.htmlunit.html.HtmlButton;
+import com.gargoylesoftware.htmlunit.html.HtmlDivision;
 import com.gargoylesoftware.htmlunit.html.HtmlForm;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
 import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
 import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
 import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
+import com.gargoylesoftware.htmlunit.util.WebConnectionWrapper;
+
 import org.apache.camel.component.box.BoxConfiguration;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.jsse.SSLContextParameters;
+import org.apache.http.HttpHeaders;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpStatus;
 import org.apache.http.conn.params.ConnRoutePNames;
@@ -95,6 +101,15 @@ public final class LoginAuthFlowUI implements IAuthFlowUI {
             throw ObjectHelper.wrapRuntimeCamelException(e);
         }
 
+        // disable default gzip compression, as htmlunit does not negotiate pages sent with
no compression
+        new WebConnectionWrapper(webClient) {
+            @Override
+            public WebResponse getResponse(WebRequest request) throws IOException {
+                request.setAdditionalHeader(HttpHeaders.ACCEPT_ENCODING, "identity");
+                return super.getResponse(request);
+            }
+        };
+
         // add HTTP proxy if set
         final Map<String, Object> httpParams = configuration.getHttpParams();
         if (httpParams != null && httpParams.get(ConnRoutePNames.DEFAULT_PROXY) !=
null) {
@@ -113,6 +128,16 @@ public final class LoginAuthFlowUI implements IAuthFlowUI {
             viewData.setOptionalState(String.valueOf(csrfId));
             final HtmlPage authPage = webClient.getPage(viewData.buildUrl().toString());
 
+            // look for <div role="error_message">
+            final HtmlDivision div = authPage.getFirstByXPath("//div[contains(concat(' ',
@class, ' '), ' error_message ')]");
+            if (div != null) {
+                final String errorMessage = div.getTextContent()
+                    .replaceAll("\\s+", " ")
+                    .replaceAll(" Show Error Details", ":")
+                    .trim();
+                throw new IllegalArgumentException("Error authorizing application: " + errorMessage);
+            }
+
             // submit login credentials
             final HtmlForm loginForm = authPage.getFormByName("login_form");
             final HtmlTextInput login = loginForm.getInputByName("login");

http://git-wip-us.apache.org/repos/asf/camel/blob/96ec3ac5/components/camel-box/src/test/java/org/apache/camel/component/box/InvalidClientIdIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/test/java/org/apache/camel/component/box/InvalidClientIdIntegrationTest.java
b/components/camel-box/src/test/java/org/apache/camel/component/box/InvalidClientIdIntegrationTest.java
new file mode 100644
index 0000000..8216b5a
--- /dev/null
+++ b/components/camel-box/src/test/java/org/apache/camel/component/box/InvalidClientIdIntegrationTest.java
@@ -0,0 +1,83 @@
+/**
+ * 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.camel.component.box;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.box.internal.BoxApiCollection;
+import org.apache.camel.component.box.internal.IBoxSharedItemsManagerApiMethod;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test Box component configuration.
+ */
+public class InvalidClientIdIntegrationTest extends AbstractBoxTestSupport {
+
+    private static final Logger LOG = LoggerFactory.getLogger(InvalidClientIdIntegrationTest.class);
+    private static final String PATH_PREFIX = BoxApiCollection.getCollection().getApiName(IBoxSharedItemsManagerApiMethod.class).getName();
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        final CamelContext camelContext = super.createCamelContext();
+
+        // set client_id to an invalid value
+        final BoxConfiguration configuration = camelContext.getComponent("box", BoxComponent.class).getConfiguration();
+        configuration.setClientId("bad_client_id");
+
+        // also remove auth secure storage to avoid loading a stored token
+        configuration.setAuthSecureStorage(null);
+
+        return camelContext;
+    }
+
+    @Override
+    protected void startCamelContext() throws Exception {
+        // should throw an exception on start
+        try {
+            super.startCamelContext();
+            fail("Invalid client id MUST cause an IllegalArgumentException on startup");
+        } catch (FailedToCreateRouteException e) {
+            Throwable t = e;
+            while (t.getCause() != null && t.getCause() != e) {
+                t = t.getCause();
+            }
+            assertNotNull("root cause exception", t);
+            assertEquals("illegal argument exception", IllegalArgumentException.class, t.getClass());
+            LOG.debug("Caught expected exception {}", t.getMessage());
+        }
+    }
+
+    @Test
+    public void testInvalidClientId() throws Exception {
+        // do nothing
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // dummy route to force box component startup
+                from("direct://GETSHAREDITEM")
+                    .to("box://" + PATH_PREFIX + "/getSharedItem?inBody=defaultRequest");
+            }
+        };
+    }
+}


Mime
View raw message