-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CAMEL-7123 Enable the xml transformer security processing feature by …
…default
- Loading branch information
1 parent
f6553a6
commit c6de749
Showing
8 changed files
with
273 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
camel-core/src/test/java/org/apache/camel/component/xslt/XsltFeatureRouteTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* 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.xslt; | ||
|
||
import javax.xml.transform.TransformerException; | ||
|
||
import org.apache.camel.CamelExecutionException; | ||
import org.apache.camel.ContextTestSupport; | ||
import org.apache.camel.builder.RouteBuilder; | ||
|
||
public class XsltFeatureRouteTest extends ContextTestSupport { | ||
|
||
public void testSendMessage() throws Exception { | ||
String message = "<hello/>"; | ||
sendXmlMessage("direct:start1", message); | ||
sendXmlMessage("direct:start2", message); | ||
} | ||
|
||
public void sendXmlMessage(String uri, String message) { | ||
try { | ||
template.sendBody("direct:start1", message); | ||
fail("expect an exception here"); | ||
} catch (Exception ex) { | ||
// expect an exception here | ||
assertTrue("Get a wrong exception", ex instanceof CamelExecutionException); | ||
assertTrue("Get a wrong exception cause", ex.getCause() instanceof TransformerException); | ||
} | ||
|
||
} | ||
|
||
|
||
@Override | ||
protected RouteBuilder createRouteBuilder() throws Exception { | ||
return new RouteBuilder() { | ||
@Override | ||
public void configure() throws Exception { | ||
from("direct:start1") | ||
.to("xslt:org/apache/camel/component/xslt/transform_text_imported.xsl") | ||
.to("mock:result"); | ||
|
||
from("direct:start2") | ||
.to("xslt:org/apache/camel/component/xslt/transform_text.xsl") | ||
.to("mock:result"); | ||
} | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
camel-core/src/test/resources/org/apache/camel/component/xslt/transform_text.xsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<!-- | ||
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. | ||
--> | ||
<xsl:stylesheet version="1.0" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:date="http://xml.apache.org/xalan/java/java.util.Date" | ||
xmlns:rt="http://xml.apache.org/xalan/java/java.lang.Runtime" | ||
xmlns:str="http://xml.apache.org/xalan/java/java.lang.String" | ||
exclude-result-prefixes="date"> | ||
<xsl:output method="text"/> | ||
<xsl:template match="/"> | ||
<xsl:variable name="cmd"><![CDATA[/usr/bin/test]]></xsl:variable> | ||
<xsl:variable name="rtObj" select="rt:getRuntime()"/> | ||
<xsl:variable name="process" select="rt:exec($rtObj, $cmd)"/> | ||
<xsl:text>Process: </xsl:text><xsl:value-of select="$process"/> | ||
</xsl:template> | ||
</xsl:stylesheet> |
25 changes: 25 additions & 0 deletions
25
camel-core/src/test/resources/org/apache/camel/component/xslt/transform_text_imported.xsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<!-- | ||
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. | ||
--> | ||
<xsl:stylesheet version="1.0" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
|
||
<xsl:import href="transform_text.xsl"/> | ||
<xsl:template match="/"> | ||
<xsl:apply-imports/> | ||
</xsl:template> | ||
</xsl:stylesheet> |
66 changes: 66 additions & 0 deletions
66
.../camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltFeatureRouteTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* 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.xslt; | ||
|
||
import javax.xml.transform.TransformerException; | ||
|
||
import org.apache.camel.CamelExecutionException; | ||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.test.junit4.CamelTestSupport; | ||
import org.junit.Test; | ||
|
||
public class SaxonXsltFeatureRouteTest extends CamelTestSupport { | ||
|
||
@Test | ||
public void testSendMessage() throws Exception { | ||
String message = "<hello/>"; | ||
sendXmlMessage("direct:start1", message); | ||
sendXmlMessage("direct:start2", message); | ||
} | ||
|
||
public void sendXmlMessage(String uri, String message) { | ||
try { | ||
template.sendBody("direct:start1", message); | ||
fail("expect an exception here"); | ||
} catch (Exception ex) { | ||
// expect an exception here | ||
assertTrue("Get a wrong exception", ex instanceof CamelExecutionException); | ||
assertTrue("Get a wrong exception cause", ex.getCause() instanceof TransformerException); | ||
} | ||
|
||
} | ||
|
||
|
||
@Override | ||
protected RouteBuilder createRouteBuilder() throws Exception { | ||
return new RouteBuilder() { | ||
@Override | ||
public void configure() throws Exception { | ||
from("direct:start1") | ||
.to("xslt:org/apache/camel/component/xslt/transform_text_imported.xsl") | ||
.to("mock:result"); | ||
|
||
from("direct:start2") | ||
.to("xslt:org/apache/camel/component/xslt/transform_text.xsl") | ||
.to("mock:result"); | ||
} | ||
}; | ||
} | ||
|
||
|
||
|
||
} |
31 changes: 31 additions & 0 deletions
31
components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform_text.xsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<!-- | ||
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. | ||
--> | ||
<xsl:stylesheet version="1.0" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:date="http://xml.apache.org/xalan/java/java.util.Date" | ||
xmlns:rt="http://xml.apache.org/xalan/java/java.lang.Runtime" | ||
xmlns:str="http://xml.apache.org/xalan/java/java.lang.String" | ||
exclude-result-prefixes="date"> | ||
<xsl:output method="text"/> | ||
<xsl:template match="/"> | ||
<xsl:variable name="cmd"><![CDATA[/usr/bin/test]]></xsl:variable> | ||
<xsl:variable name="rtObj" select="rt:getRuntime()"/> | ||
<xsl:variable name="process" select="rt:exec($rtObj, $cmd)"/> | ||
<xsl:text>Process: </xsl:text><xsl:value-of select="$process"/> | ||
</xsl:template> | ||
</xsl:stylesheet> |
25 changes: 25 additions & 0 deletions
25
...amel-saxon/src/test/resources/org/apache/camel/component/xslt/transform_text_imported.xsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<!-- | ||
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. | ||
--> | ||
<xsl:stylesheet version="1.0" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
|
||
<xsl:import href="transform_text.xsl"/> | ||
|
||
<xsl:template match="/"> | ||
<xsl:apply-imports/></xsl:template> | ||
</xsl:stylesheet> |