You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "avano (via GitHub)" <gi...@apache.org> on 2023/06/19 09:24:19 UTC

[GitHub] [camel-quarkus] avano opened a new pull request, #4999: [closes #4956] Extend netty-http test coverage

avano opened a new pull request, #4999:
URL: https://github.com/apache/camel-quarkus/pull/4999

   <!-- Uncomment and fill this section if your PR is not trivial
   [ ] An issue should be filed for the change unless this is a trivial change (fixing a typo or similar). One issue should ideally be fixed by not more than one commit and the other way round, each commit should fix just one issue, without pulling in other changes.
   [ ] Each commit in the pull request should have a meaningful and properly spelled subject line and body. Copying the title of the associated issue is typically enough. Please include the issue number in the commit message prefixed by #.
   [ ] The pull request description should explain what the pull request does, how, and why. If the info is available in the associated issue or some other external document, a link is enough.
   [ ] Phrases like Fix #<issueNumber> or Fixes #<issueNumber> will auto-close the named issue upon merging the pull request. Using them is typically a good idea.
   [ ] Please run mvn process-resources -Pformat (and amend the changes if necessary) before sending the pull request.
   [ ] Contributor guide is your good friend: https://camel.apache.org/camel-quarkus/latest/contributor-guide.html
   -->


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] avano commented on pull request #4999: [closes #4956] Extend netty-http test coverage

Posted by "avano (via GitHub)" <gi...@apache.org>.
avano commented on PR #4999:
URL: https://github.com/apache/camel-quarkus/pull/4999#issuecomment-1603857299

   @jamesnetherton I can take a look at splitting the http tests in a separate PR


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] jamesnetherton commented on pull request #4999: [closes #4956] Extend netty-http test coverage

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton commented on PR #4999:
URL: https://github.com/apache/camel-quarkus/pull/4999#issuecomment-1600562021

   By introducing a new `netty-http` itest module, we now have tests split between there and `integration-tests/http`. We should maybe consider moving the `netty-http` specific stuff our of `integration-tests/http` and into `integration-tests/netty-http`.
   
   However, that could be non-trivial to do. So not sure if we should address it in this in this PR or do a follow-up. Maybe others have some thoughts on that.
   
   There is also this proposal to add the HTTP tests to `integration-test-groups` https://github.com/apache/camel-quarkus/issues/3087.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] jamesnetherton merged pull request #4999: [closes #4956] Extend netty-http test coverage

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton merged PR #4999:
URL: https://github.com/apache/camel-quarkus/pull/4999


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] jamesnetherton commented on a diff in pull request #4999: [closes #4956] Extend netty-http test coverage

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton commented on code in PR #4999:
URL: https://github.com/apache/camel-quarkus/pull/4999#discussion_r1236732795


##########
integration-tests/netty-http/src/main/java/org/apache/camel/quarkus/component/netty/http/NettyHttpRoutes.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.quarkus.component.netty.http;
+
+import java.nio.charset.Charset;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+import io.netty.handler.codec.http.FullHttpRequest;
+import jakarta.inject.Named;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.netty.http.JAASSecurityAuthenticator;
+import org.apache.camel.component.netty.http.NettyHttpComponent;
+import org.apache.camel.component.netty.http.NettyHttpConfiguration;
+import org.apache.camel.component.netty.http.NettyHttpMessage;
+import org.apache.camel.component.netty.http.NettyHttpSecurityConfiguration;
+import org.apache.camel.component.netty.http.SecurityConstraintMapping;
+import org.apache.camel.component.rest.RestConstants;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.apache.camel.quarkus.component.netty.http.auth.TestAuthenticator;
+import org.apache.camel.quarkus.component.netty.http.pojo.UserPojo;
+import org.eclipse.microprofile.config.ConfigProvider;
+
+public class NettyHttpRoutes extends RouteBuilder {
+    @Named("jaasConfig")
+    NettyHttpSecurityConfiguration jaasConfig() {
+        final NettyHttpSecurityConfiguration config = new NettyHttpSecurityConfiguration();
+        config.setRealm("Quarkus");
+        JAASSecurityAuthenticator jaas = new JAASSecurityAuthenticator();
+        jaas.setName("Quarkus");
+        config.setSecurityAuthenticator(jaas);
+        return config;
+    }
+
+    @Named("securityConfig")
+    NettyHttpSecurityConfiguration securityConfiguration() {
+        final NettyHttpSecurityConfiguration config = new NettyHttpSecurityConfiguration();
+        config.setRealm("Quarkus");
+        config.setSecurityAuthenticator(new TestAuthenticator());
+        return config;
+    }
+
+    // Each ACL configuration is using a separate route/endpoint, so all of them are using /* mapping
+    @Named("acladmin")
+    NettyHttpSecurityConfiguration aclAdmin() {
+        final NettyHttpSecurityConfiguration config = securityConfiguration();
+        SecurityConstraintMapping securityConstraintMapping = new SecurityConstraintMapping();
+        securityConstraintMapping.addInclusion("/*", "admin");
+        config.setSecurityConstraint(securityConstraintMapping);
+        return config;
+    }
+
+    @Named("aclguest")
+    NettyHttpSecurityConfiguration aclGuest() {
+        final NettyHttpSecurityConfiguration config = securityConfiguration();
+        SecurityConstraintMapping securityConstraintMapping = new SecurityConstraintMapping();
+        securityConstraintMapping.addInclusion("/*", "admin,guest");
+        config.setSecurityConstraint(securityConstraintMapping);
+        return config;
+    }
+
+    @Named("aclpublic")
+    NettyHttpSecurityConfiguration aclPublic() {
+        final NettyHttpSecurityConfiguration config = securityConfiguration();
+        SecurityConstraintMapping securityConstraintMapping = new SecurityConstraintMapping();
+        securityConstraintMapping.addExclusion("/*");
+        config.setSecurityConstraint(securityConstraintMapping);
+        return config;
+    }
+
+    @Named("aclwildcard")
+    NettyHttpSecurityConfiguration aclWildcard() {
+        final NettyHttpSecurityConfiguration config = securityConfiguration();
+        SecurityConstraintMapping securityConstraintMapping = new SecurityConstraintMapping();
+        securityConstraintMapping.addInclusion("/*", "*");
+        config.setSecurityConstraint(securityConstraintMapping);
+        return config;
+    }
+
+    @Named("netty-http")
+    NettyHttpComponent component() {
+        NettyHttpComponent component = new NettyHttpComponent();
+        NettyHttpConfiguration config = new NettyHttpConfiguration();
+        // This helps to stabilize the tests when running on windows, as occasionally when invoking the same route from a parameterized test,
+        // the next request got the same channel as the previous request that was not fully done yet and it caused the next test to fail.
+        config.setReuseChannel(true);
+        component.setConfiguration(config);
+        return component;
+    }
+
+    @Override
+    public void configure() throws Exception {
+        restConfiguration().component("netty-http")
+                .host("localhost").port(ConfigProvider.getConfig().getValue("camel.netty-http.restPort", Integer.class));
+
+        from("netty-http:http://localhost:{{camel.netty-http.port}}/request")
+                .process(ex -> {
+                    final FullHttpRequest req = ex.getIn(NettyHttpMessage.class).getHttpRequest();
+                    ex.getIn().setBody(
+                            String.join(",", req.method().name(), req.content().toString(Charset.defaultCharset()),
+                                    StreamSupport.stream(req.headers().spliterator(), false)
+                                            .map(h -> h.getKey() + ":" + h.getValue()).collect(Collectors.joining(","))));
+                });
+
+        from("netty-http:http://localhost:{{camel.netty-http.port}}/response").log("${body}");

Review Comment:
   I know the test verifies the 200 status code, but maybe we should transform or echo the body back to the client so that we can verify that the route worked as expected.



##########
integration-tests/netty-http/src/test/java/org/apache/camel/quarkus/component/netty/http/NettyHttpJaasTestResource.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.quarkus.component.netty.http;
+
+import java.util.Map;
+
+public class NettyHttpJaasTestResource extends NettyHttpTestResource {
+    @Override
+    public Map<String, String> start() {
+        // for JVM
+        System.setProperty("java.security.auth.login.config", "src/test/resources/config.jaas");

Review Comment:
   Reading from the source tree will not work when the tests are run in the Quarkus Platform project.
   
   Copy the file to `target` and use that as the path.



##########
integration-tests/netty-http/src/test/java/org/apache/camel/quarkus/component/netty/http/NettyHttpJaasTestResource.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.quarkus.component.netty.http;
+
+import java.util.Map;
+
+public class NettyHttpJaasTestResource extends NettyHttpTestResource {
+    @Override
+    public Map<String, String> start() {
+        // for JVM
+        System.setProperty("java.security.auth.login.config", "src/test/resources/config.jaas");
+        final Map<String, String> properties = super.start();
+        // for native
+        properties.put("java.security.auth.login.config", "src/test/resources/config.jaas");

Review Comment:
   As per previous comment about reading from the source tree.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] jamesnetherton commented on pull request #4999: [closes #4956] Extend netty-http test coverage

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton commented on PR #4999:
URL: https://github.com/apache/camel-quarkus/pull/4999#issuecomment-1603913077

   > @jamesnetherton I can take a look at splitting the http tests in a separate PR
   
   Sounds good, thanks.
   
   Do you mind rebasing with the latest work on main. Just want to make sure everything passes ok with the Quarkus 3.2.0 upgrade.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] avano commented on pull request #4999: [closes #4956] Extend netty-http test coverage

Posted by "avano (via GitHub)" <gi...@apache.org>.
avano commented on PR #4999:
URL: https://github.com/apache/camel-quarkus/pull/4999#issuecomment-1598614219

   it seems that one test is flaky on windows, I'm looking at it


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] avano commented on pull request #4999: [closes #4956] Extend netty-http test coverage

Posted by "avano (via GitHub)" <gi...@apache.org>.
avano commented on PR #4999:
URL: https://github.com/apache/camel-quarkus/pull/4999#issuecomment-1604133736

   > > @jamesnetherton I can take a look at splitting the http tests in a separate PR
   > 
   > Sounds good, thanks.
   > 
   > Do you mind rebasing with the latest work on main. Just want to make sure everything passes ok with the Quarkus 3.2.0 upgrade.
   
   after the upgrade to 3.2.0 I needed to register more classes for reflection [here](https://github.com/avano/camel-quarkus/blob/issue-4956/extensions/netty-http/deployment/src/main/java/org/apache/camel/quarkus/component/netty/http/deployment/NettyHTTPProcessor.java#L38-L44)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] zbendhiba commented on pull request #4999: [closes #4956] Extend netty-http test coverage

Posted by "zbendhiba (via GitHub)" <gi...@apache.org>.
zbendhiba commented on PR #4999:
URL: https://github.com/apache/camel-quarkus/pull/4999#issuecomment-1609149409

   thanks @avano 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org