mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor testcase
This commit is contained in:
@@ -91,7 +91,7 @@ public class FileConfigLoader implements ConfigLoader {
|
||||
}
|
||||
}
|
||||
|
||||
String getFilePath(String protocol) {
|
||||
public String getFilePath(String protocol) {
|
||||
String filePath = null;
|
||||
|
||||
filePath = protocol.substring(PROTOCOL_PREFIX.length());
|
||||
|
||||
@@ -83,7 +83,7 @@ public class HttpConfigLoader implements ConfigLoader {
|
||||
}
|
||||
}
|
||||
|
||||
URL getUrl(String protocol) throws MalformedURLException {
|
||||
public URL getUrl(String protocol) throws MalformedURLException {
|
||||
return new URL(protocol.substring(PROTOCOL_PREFIX.length() - 7));
|
||||
}
|
||||
|
||||
|
||||
+13
-12
@@ -32,17 +32,16 @@ import java.util.Properties;
|
||||
|
||||
/**
|
||||
* RSA 解密器, 支持证书
|
||||
*
|
||||
*/
|
||||
public class RsaDecrypter extends AbstractDecrypter {
|
||||
|
||||
private static Log log = LogFactory.getLog(RsaDecrypter.class);
|
||||
private static Log log = LogFactory.getLog(RsaDecrypter.class);
|
||||
|
||||
public static final String KEY = "config.decrypt.key";
|
||||
public static final String KEY_FILE = "config.decrypt.keyFile";
|
||||
public static final String X509_FILE = "config.decrypt.x509File";
|
||||
public static final String KEY = "config.decrypt.key";
|
||||
public static final String KEY_FILE = "config.decrypt.keyFile";
|
||||
public static final String X509_FILE = "config.decrypt.x509File";
|
||||
|
||||
protected static final String DEFAULT_PUBLIC_KEY_STRING = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKHGwq7q2RmwuRgKxBypQHw0mYu4BQZ3eMsTrdK8E6igRcxsobUC7uT0SoxIjl1WveWniCASejoQtn/BY6hVKWsCAwEAAQ==";
|
||||
public static final String DEFAULT_PUBLIC_KEY_STRING = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKHGwq7q2RmwuRgKxBypQHw0mYu4BQZ3eMsTrdK8E6igRcxsobUC7uT0SoxIjl1WveWniCASejoQtn/BY6hVKWsCAwEAAQ==";
|
||||
|
||||
public String getId() {
|
||||
return "RSA";
|
||||
@@ -54,9 +53,10 @@ public class RsaDecrypter extends AbstractDecrypter {
|
||||
* 如果是密钥字符串, key 是 config.decrypt.key
|
||||
* 如果是密钥文件, key 是 config.decrypt.keyFile
|
||||
* 如果是证书文件, key 是 config.decrypt.x509File
|
||||
*
|
||||
*
|
||||
* 如果不指定密钥, 将使用默认密钥
|
||||
* </pre>
|
||||
*
|
||||
* @param parameters 密文参数
|
||||
* @param info
|
||||
* @return
|
||||
@@ -83,10 +83,11 @@ public class RsaDecrypter extends AbstractDecrypter {
|
||||
|
||||
/**
|
||||
* 通过指定
|
||||
*
|
||||
* @param info
|
||||
* @return
|
||||
*/
|
||||
PublicKey getPublicKey(Properties info) {
|
||||
public PublicKey getPublicKey(Properties info) {
|
||||
String key = null;
|
||||
String publicKeyFile = null;
|
||||
String x509File = null;
|
||||
@@ -118,7 +119,7 @@ public class RsaDecrypter extends AbstractDecrypter {
|
||||
return getPublicKeyByString(key);
|
||||
}
|
||||
|
||||
PublicKey getPublicKeyByString(String publicKeyString) {
|
||||
public PublicKey getPublicKeyByString(String publicKeyString) {
|
||||
if (publicKeyString == null || publicKeyString.length() == 0) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Decrypt by default key");
|
||||
@@ -137,7 +138,7 @@ public class RsaDecrypter extends AbstractDecrypter {
|
||||
}
|
||||
}
|
||||
|
||||
PublicKey getPublicKeyByPublicKeyFile(String publicKeyFile) {
|
||||
public PublicKey getPublicKeyByPublicKeyFile(String publicKeyFile) {
|
||||
if (publicKeyFile == null || publicKeyFile.length() == 0) {
|
||||
return getPublicKeyByString(null);
|
||||
}
|
||||
@@ -147,7 +148,7 @@ public class RsaDecrypter extends AbstractDecrypter {
|
||||
in = new FileInputStream(publicKeyFile);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
int len = 0;
|
||||
byte[] b = new byte[512/8];
|
||||
byte[] b = new byte[512 / 8];
|
||||
while ((len = in.read(b)) != -1) {
|
||||
out.write(b, 0, len);
|
||||
}
|
||||
@@ -163,7 +164,7 @@ public class RsaDecrypter extends AbstractDecrypter {
|
||||
}
|
||||
}
|
||||
|
||||
PublicKey getPublicKeyByX509(String x509File) {
|
||||
public PublicKey getPublicKeyByX509(String x509File) {
|
||||
if (x509File == null || x509File.length() == 0) {
|
||||
return getPublicKeyByString(null);
|
||||
}
|
||||
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
package com.alibaba.druid.filter.config;
|
||||
package com.alibaba.druid.bvt.filter.config;
|
||||
|
||||
import com.alibaba.druid.filter.config.ConfigFileGenerator;
|
||||
import com.alibaba.druid.filter.config.ConfigFilter;
|
||||
import com.alibaba.druid.filter.config.loader.impl.FileConfigLoader;
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.alibaba.druid.filter.config.loader;
|
||||
package com.alibaba.druid.bvt.filter.config;
|
||||
|
||||
import com.alibaba.druid.filter.config.loader.ConfigLoader;
|
||||
import com.alibaba.druid.filter.config.loader.ConfigLoaderFactory;
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.alibaba.druid.bvt.filter.config;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
import com.alibaba.druid.filter.config.ConfigFilterTest;
|
||||
import com.alibaba.druid.filter.config.loader.ConfigLoaderFactoryTest;
|
||||
import com.alibaba.druid.filter.config.loader.impl.FileConfigLoaderTest;
|
||||
import com.alibaba.druid.filter.config.loader.impl.FileConfigLoaderTest1;
|
||||
import com.alibaba.druid.filter.config.loader.impl.HttpConfigLoaderTest;
|
||||
|
||||
/**
|
||||
* @author Jonas Yang
|
||||
*/
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({
|
||||
ConfigLoaderFactoryTest.class,
|
||||
FileConfigLoaderTest.class,
|
||||
FileConfigLoaderTest1.class,
|
||||
HttpConfigLoaderTest.class,
|
||||
ConfigFilterTest.class
|
||||
})
|
||||
public class ConfigTestSuite {
|
||||
}
|
||||
+5
-1
@@ -1,8 +1,12 @@
|
||||
package com.alibaba.druid.filter.config.security.decrypter;
|
||||
package com.alibaba.druid.bvt.filter.config;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.druid.filter.config.security.decrypter.DecryptException;
|
||||
import com.alibaba.druid.filter.config.security.decrypter.DecrypterFactory;
|
||||
import com.alibaba.druid.filter.config.security.decrypter.RsaDecrypter;
|
||||
|
||||
/**
|
||||
* @author Jonas Yang
|
||||
*/
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.alibaba.druid.bvt.filter.config;
|
||||
|
||||
import com.alibaba.druid.filter.config.security.decrypter.DecrypterFactoryTest;
|
||||
import com.alibaba.druid.filter.config.security.decrypter.RsaDecrypterTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
/**
|
||||
* @author Jonas Yang
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({
|
||||
RsaDecrypterTest.class,
|
||||
DecrypterFactoryTest.class
|
||||
})
|
||||
public class DecrypterTestSuite {
|
||||
}
|
||||
+3
-1
@@ -1,8 +1,10 @@
|
||||
package com.alibaba.druid.filter.config.loader.impl;
|
||||
package com.alibaba.druid.bvt.filter.config;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.druid.filter.config.loader.impl.FileConfigLoader;
|
||||
|
||||
/**
|
||||
* @author Jonas Yang
|
||||
*/
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
package com.alibaba.druid.filter.config.loader.impl;
|
||||
package com.alibaba.druid.bvt.filter.config;
|
||||
|
||||
import com.alibaba.druid.filter.config.ConfigFileGenerator;
|
||||
import com.alibaba.druid.filter.config.loader.impl.FileConfigLoader;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
+3
-1
@@ -1,8 +1,10 @@
|
||||
package com.alibaba.druid.filter.config.loader.impl;
|
||||
package com.alibaba.druid.bvt.filter.config;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.druid.filter.config.loader.impl.HttpConfigLoader;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
+4
-1
@@ -1,5 +1,8 @@
|
||||
package com.alibaba.druid.filter.config.security.decrypter;
|
||||
package com.alibaba.druid.bvt.filter.config;
|
||||
|
||||
import com.alibaba.druid.filter.config.security.decrypter.DecryptException;
|
||||
import com.alibaba.druid.filter.config.security.decrypter.RsaDecrypter;
|
||||
import com.alibaba.druid.filter.config.security.decrypter.SensitiveParameters;
|
||||
import com.alibaba.druid.util.Base64;
|
||||
import junit.framework.Assert;
|
||||
import org.junit.After;
|
||||
Reference in New Issue
Block a user