-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IGNITE-20654 Forbid H2 connection "init" setting (#10997)
- Loading branch information
1 parent
63476a7
commit ccab242
Showing
4 changed files
with
136 additions
and
0 deletions.
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
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
87 changes: 87 additions & 0 deletions
87
...test/java/org/apache/ignite/internal/processors/cache/index/H2ConnectionSettingsTest.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,87 @@ | ||
/* | ||
* 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.ignite.internal.processors.cache.index; | ||
|
||
import java.io.File; | ||
import java.nio.file.Paths; | ||
import javax.sql.DataSource; | ||
import org.apache.ignite.IgniteCheckedException; | ||
import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory; | ||
import org.apache.ignite.configuration.CacheConfiguration; | ||
import org.apache.ignite.configuration.IgniteConfiguration; | ||
import org.apache.ignite.configuration.IgniteReflectionFactory; | ||
import org.apache.ignite.internal.IgniteEx; | ||
import org.apache.ignite.internal.util.typedef.F; | ||
import org.apache.ignite.internal.util.typedef.internal.U; | ||
import org.apache.ignite.testframework.GridTestUtils; | ||
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; | ||
import org.junit.Test; | ||
|
||
/** */ | ||
public class H2ConnectionSettingsTest extends GridCommonAbstractTest { | ||
/** {@inheritDoc} */ | ||
@Override protected void afterTest() { | ||
stopAllGrids(); | ||
} | ||
|
||
/** */ | ||
@Test | ||
public void testInitForbidden() throws Exception { | ||
IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName()) | ||
.setCacheConfiguration(cacheConfiguration()); | ||
|
||
GridTestUtils.assertThrowsWithCause(() -> startGrid(cfg), org.h2.jdbc.JdbcSQLException.class); | ||
|
||
assertFalse(checkFile().exists()); | ||
} | ||
|
||
/** */ | ||
@Test | ||
public void testInitForbiddenInDynamic() throws Exception { | ||
IgniteEx ign = startGrid(); | ||
|
||
IgniteEx cln = startClientGrid(1); | ||
|
||
GridTestUtils.assertThrowsWithCause(() -> cln.createCache(cacheConfiguration()), org.h2.jdbc.JdbcSQLException.class); | ||
|
||
assertFalse(checkFile().exists()); | ||
|
||
assertNotNull(ign.createCache(DEFAULT_CACHE_NAME)); | ||
} | ||
|
||
/** */ | ||
private CacheConfiguration<Integer, Integer> cacheConfiguration() throws Exception { | ||
CacheJdbcPojoStoreFactory<Integer, Integer> factory = new CacheJdbcPojoStoreFactory<>(); | ||
|
||
checkFile().delete(); | ||
|
||
String init = "//javascript\njava.lang.Runtime.getRuntime().exec(\"touch " + checkFile().getAbsolutePath() + " \")"; | ||
String url = "jdbc:h2:mem:test;init=CREATE TRIGGER h BEFORE SELECT ON INFORMATION_SCHEMA.CATALOGS AS '" + init + "'"; | ||
|
||
IgniteReflectionFactory<DataSource> reflectionFactory = new IgniteReflectionFactory<>(org.h2.jdbcx.JdbcDataSource.class); | ||
reflectionFactory.setProperties(F.asMap("url", url)); | ||
|
||
return new CacheConfiguration<Integer, Integer>(DEFAULT_CACHE_NAME) | ||
.setCacheStoreFactory(factory.setDataSourceFactory(reflectionFactory)); | ||
} | ||
|
||
/** */ | ||
private File checkFile() throws IgniteCheckedException { | ||
return Paths.get(U.defaultWorkDirectory(), "init_check").toFile(); | ||
} | ||
} |
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
ccab242
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have added a "Security Model" section to our documentation [1].
It explains why we don't consider this an issue.
[1] 7b8b4ba