You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WalkEncryptionTest.java 37KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. /*
  2. * Copyright (C) 2015, Andrei Pozolotin.
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.transport;
  44. import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.UTF_8;
  45. import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListPBE;
  46. import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListTrans;
  47. import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.folderDelete;
  48. import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.permitLongTests;
  49. import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.policySetup;
  50. import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.product;
  51. import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.proxySetup;
  52. import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.publicAddress;
  53. import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.reportPolicy;
  54. import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.securityProviderName;
  55. import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.textWrite;
  56. import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.transferStream;
  57. import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.verifyFileContent;
  58. import static org.junit.Assert.assertEquals;
  59. import static org.junit.Assert.assertFalse;
  60. import static org.junit.Assert.assertNotNull;
  61. import static org.junit.Assert.assertTrue;
  62. import static org.junit.Assume.assumeTrue;
  63. import java.io.BufferedReader;
  64. import java.io.ByteArrayInputStream;
  65. import java.io.ByteArrayOutputStream;
  66. import java.io.File;
  67. import java.io.FileInputStream;
  68. import java.io.IOException;
  69. import java.io.InputStream;
  70. import java.io.InputStreamReader;
  71. import java.io.OutputStream;
  72. import java.io.PrintWriter;
  73. import java.net.SocketTimeoutException;
  74. import java.net.URL;
  75. import java.net.URLConnection;
  76. import java.net.UnknownHostException;
  77. import java.nio.charset.Charset;
  78. import java.nio.file.Files;
  79. import java.security.GeneralSecurityException;
  80. import java.security.Provider;
  81. import java.security.Security;
  82. import java.util.ArrayList;
  83. import java.util.Collection;
  84. import java.util.List;
  85. import java.util.Properties;
  86. import java.util.Set;
  87. import java.util.TreeSet;
  88. import java.util.UUID;
  89. import javax.crypto.Cipher;
  90. import javax.crypto.SecretKeyFactory;
  91. import org.eclipse.jgit.api.Git;
  92. import org.eclipse.jgit.lib.StoredConfig;
  93. import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
  94. import org.eclipse.jgit.util.FileUtils;
  95. import org.junit.After;
  96. import org.junit.AfterClass;
  97. import org.junit.Before;
  98. import org.junit.BeforeClass;
  99. import org.junit.FixMethodOrder;
  100. import org.junit.Test;
  101. import org.junit.runner.RunWith;
  102. import org.junit.runners.MethodSorters;
  103. import org.junit.runners.Parameterized;
  104. import org.junit.runners.Parameterized.Parameters;
  105. import org.junit.runners.Suite;
  106. import org.slf4j.Logger;
  107. import org.slf4j.LoggerFactory;
  108. /**
  109. * Amazon S3 encryption pipeline test.
  110. *
  111. * See {@link AmazonS3} {@link WalkEncryption}
  112. *
  113. * Note: CI server must provide amazon credentials (access key, secret key,
  114. * bucket name) via one of methods available in {@link Names}.
  115. *
  116. * Note: long running tests are activated by Maven profile "test.long". There is
  117. * also a separate Eclipse m2e launcher for that. See 'pom.xml' and
  118. * 'WalkEncryptionTest.launch'.
  119. */
  120. @RunWith(Suite.class)
  121. @Suite.SuiteClasses({ //
  122. WalkEncryptionTest.Required.class, //
  123. WalkEncryptionTest.MinimalSet.class, //
  124. WalkEncryptionTest.TestablePBE.class, //
  125. WalkEncryptionTest.TestableTransformation.class, //
  126. })
  127. public class WalkEncryptionTest {
  128. /**
  129. * Logger setup: ${project_loc}/tst-rsrc/log4j.properties
  130. */
  131. static final Logger logger = LoggerFactory.getLogger(WalkEncryptionTest.class);
  132. /**
  133. * Property names used in test session.
  134. */
  135. interface Names {
  136. // Names of discovered test properties.
  137. String TEST_BUCKET = "test.bucket";
  138. // Names of test environment variables for CI.
  139. String ENV_ACCESS_KEY = "JGIT_S3_ACCESS_KEY";
  140. String ENV_SECRET_KEY = "JGIT_S3_SECRET_KEY";
  141. String ENV_BUCKET_NAME = "JGIT_S3_BUCKET_NAME";
  142. // Name of test environment variable file path for CI.
  143. String ENV_CONFIG_FILE = "JGIT_S3_CONFIG_FILE";
  144. // Names of test system properties for CI.
  145. String SYS_ACCESS_KEY = "jgit.s3.access.key";
  146. String SYS_SECRET_KEY = "jgit.s3.secret.key";
  147. String SYS_BUCKET_NAME = "jgit.s3.bucket.name";
  148. // Name of test system property file path for CI.
  149. String SYS_CONFIG_FILE = "jgit.s3.config.file";
  150. // Hard coded name of test properties file for CI.
  151. // File format follows AmazonS3.Keys:
  152. // #
  153. // # Required entries:
  154. // #
  155. // accesskey = your-amazon-access-key # default AmazonS3.Keys
  156. // secretkey = your-amazon-secret-key # default AmazonS3.Keys
  157. // test.bucket = your-bucket-for-testing # custom name, for this test
  158. String CONFIG_FILE = "jgit-s3-config.properties";
  159. // Test properties file in [user home] of CI.
  160. String HOME_CONFIG_FILE = System.getProperty("user.home")
  161. + File.separator + CONFIG_FILE;
  162. // Test properties file in [project work directory] of CI.
  163. String WORK_CONFIG_FILE = System.getProperty("user.dir")
  164. + File.separator + CONFIG_FILE;
  165. // Test properties file in [project test source directory] of CI.
  166. String TEST_CONFIG_FILE = System.getProperty("user.dir")
  167. + File.separator + "tst-rsrc" + File.separator + CONFIG_FILE;
  168. }
  169. /**
  170. * Find test properties from various sources in order of priority.
  171. */
  172. static class Props implements WalkEncryptionTest.Names, AmazonS3.Keys {
  173. static boolean haveEnvVar(String name) {
  174. return System.getenv(name) != null;
  175. }
  176. static boolean haveEnvVarFile(String name) {
  177. return haveEnvVar(name) && new File(name).exists();
  178. }
  179. static boolean haveSysProp(String name) {
  180. return System.getProperty(name) != null;
  181. }
  182. static boolean haveSysPropFile(String name) {
  183. return haveSysProp(name) && new File(name).exists();
  184. }
  185. static void loadEnvVar(String source, String target, Properties props) {
  186. props.put(target, System.getenv(source));
  187. }
  188. static void loadSysProp(String source, String target,
  189. Properties props) {
  190. props.put(target, System.getProperty(source));
  191. }
  192. static boolean haveProp(String name, Properties props) {
  193. return props.containsKey(name);
  194. }
  195. static boolean checkTestProps(Properties props) {
  196. return haveProp(ACCESS_KEY, props) && haveProp(SECRET_KEY, props)
  197. && haveProp(TEST_BUCKET, props);
  198. }
  199. static Properties fromEnvVars() {
  200. if (haveEnvVar(ENV_ACCESS_KEY) && haveEnvVar(ENV_SECRET_KEY)
  201. && haveEnvVar(ENV_BUCKET_NAME)) {
  202. Properties props = new Properties();
  203. loadEnvVar(ENV_ACCESS_KEY, ACCESS_KEY, props);
  204. loadEnvVar(ENV_SECRET_KEY, SECRET_KEY, props);
  205. loadEnvVar(ENV_BUCKET_NAME, TEST_BUCKET, props);
  206. return props;
  207. } else {
  208. return null;
  209. }
  210. }
  211. static Properties fromEnvFile() throws Exception {
  212. if (haveEnvVarFile(ENV_CONFIG_FILE)) {
  213. Properties props = new Properties();
  214. props.load(new FileInputStream(ENV_CONFIG_FILE));
  215. if (checkTestProps(props)) {
  216. return props;
  217. } else {
  218. throw new Error("Environment config file is incomplete.");
  219. }
  220. } else {
  221. return null;
  222. }
  223. }
  224. static Properties fromSysProps() {
  225. if (haveSysProp(SYS_ACCESS_KEY) && haveSysProp(SYS_SECRET_KEY)
  226. && haveSysProp(SYS_BUCKET_NAME)) {
  227. Properties props = new Properties();
  228. loadSysProp(SYS_ACCESS_KEY, ACCESS_KEY, props);
  229. loadSysProp(SYS_SECRET_KEY, SECRET_KEY, props);
  230. loadSysProp(SYS_BUCKET_NAME, TEST_BUCKET, props);
  231. return props;
  232. } else {
  233. return null;
  234. }
  235. }
  236. static Properties fromSysFile() throws Exception {
  237. if (haveSysPropFile(SYS_CONFIG_FILE)) {
  238. Properties props = new Properties();
  239. props.load(new FileInputStream(SYS_CONFIG_FILE));
  240. if (checkTestProps(props)) {
  241. return props;
  242. } else {
  243. throw new Error("System props config file is incomplete.");
  244. }
  245. } else {
  246. return null;
  247. }
  248. }
  249. static Properties fromConfigFile(String path) throws Exception {
  250. File file = new File(path);
  251. if (file.exists()) {
  252. Properties props = new Properties();
  253. props.load(new FileInputStream(file));
  254. if (checkTestProps(props)) {
  255. return props;
  256. } else {
  257. throw new Error("Props config file is incomplete: " + path);
  258. }
  259. } else {
  260. return null;
  261. }
  262. }
  263. /**
  264. * Find test properties from various sources in order of priority.
  265. *
  266. * @return result
  267. * @throws Exception
  268. */
  269. static Properties discover() throws Exception {
  270. Properties props;
  271. if ((props = fromEnvVars()) != null) {
  272. logger.debug(
  273. "Using test properties from environment variables.");
  274. return props;
  275. }
  276. if ((props = fromEnvFile()) != null) {
  277. logger.debug(
  278. "Using test properties from environment variable config file.");
  279. return props;
  280. }
  281. if ((props = fromSysProps()) != null) {
  282. logger.debug("Using test properties from system properties.");
  283. return props;
  284. }
  285. if ((props = fromSysFile()) != null) {
  286. logger.debug(
  287. "Using test properties from system property config file.");
  288. return props;
  289. }
  290. if ((props = fromConfigFile(HOME_CONFIG_FILE)) != null) {
  291. logger.debug(
  292. "Using test properties from hard coded ${user.home} file.");
  293. return props;
  294. }
  295. if ((props = fromConfigFile(WORK_CONFIG_FILE)) != null) {
  296. logger.debug(
  297. "Using test properties from hard coded ${user.dir} file.");
  298. return props;
  299. }
  300. if ((props = fromConfigFile(TEST_CONFIG_FILE)) != null) {
  301. logger.debug(
  302. "Using test properties from hard coded ${project.source} file.");
  303. return props;
  304. }
  305. throw new Error("Can not load test properties form any source.");
  306. }
  307. }
  308. /**
  309. * Collection of test utility methods.
  310. */
  311. static class Util {
  312. static final Charset UTF_8 = Charset.forName("UTF-8");
  313. /**
  314. * Read UTF-8 encoded text file into string.
  315. *
  316. * @param file
  317. * @return result
  318. * @throws Exception
  319. */
  320. static String textRead(File file) throws Exception {
  321. return new String(Files.readAllBytes(file.toPath()), UTF_8);
  322. }
  323. /**
  324. * Write string into UTF-8 encoded file.
  325. *
  326. * @param file
  327. * @param text
  328. * @throws Exception
  329. */
  330. static void textWrite(File file, String text) throws Exception {
  331. Files.write(file.toPath(), text.getBytes(UTF_8));
  332. }
  333. static void verifyFileContent(File fileOne, File fileTwo)
  334. throws Exception {
  335. assertTrue(fileOne.length() > 0);
  336. assertTrue(fileTwo.length() > 0);
  337. String textOne = textRead(fileOne);
  338. String textTwo = textRead(fileTwo);
  339. assertEquals(textOne, textTwo);
  340. }
  341. /**
  342. * Create local folder.
  343. *
  344. * @param folder
  345. * @throws Exception
  346. */
  347. static void folderCreate(String folder) throws Exception {
  348. File path = new File(folder);
  349. assertTrue(path.mkdirs());
  350. }
  351. /**
  352. * Delete local folder.
  353. *
  354. * @param folder
  355. * @throws Exception
  356. */
  357. static void folderDelete(String folder) throws Exception {
  358. File path = new File(folder);
  359. FileUtils.delete(path,
  360. FileUtils.RECURSIVE | FileUtils.SKIP_MISSING);
  361. }
  362. /**
  363. * Discover public address of CI server.
  364. *
  365. * @return result
  366. * @throws Exception
  367. */
  368. static String publicAddress() throws Exception {
  369. try {
  370. String service = "http://checkip.amazonaws.com";
  371. URL url = new URL(service);
  372. URLConnection c = url.openConnection();
  373. c.setConnectTimeout(500);
  374. c.setReadTimeout(500);
  375. BufferedReader reader = new BufferedReader(
  376. new InputStreamReader(c.getInputStream()));
  377. try {
  378. return reader.readLine();
  379. } finally {
  380. reader.close();
  381. }
  382. } catch (UnknownHostException | SocketTimeoutException e) {
  383. return "Can't reach http://checkip.amazonaws.com to"
  384. + " determine public address";
  385. }
  386. }
  387. /**
  388. * Discover Password-Based Encryption (PBE) engines providing both
  389. * [SecretKeyFactory] and [AlgorithmParameters].
  390. *
  391. * @return result
  392. */
  393. // https://www.bouncycastle.org/specifications.html
  394. // https://docs.oracle.com/javase/8/docs/technotes/guides/security/SunProviders.html
  395. static List<String> cryptoCipherListPBE() {
  396. return cryptoCipherList(WalkEncryption.Vals.REGEX_PBE);
  397. }
  398. // TODO returns inconsistent list.
  399. static List<String> cryptoCipherListTrans() {
  400. return cryptoCipherList(WalkEncryption.Vals.REGEX_TRANS);
  401. }
  402. static String securityProviderName(String algorithm) throws Exception {
  403. return SecretKeyFactory.getInstance(algorithm).getProvider()
  404. .getName();
  405. }
  406. static List<String> cryptoCipherList(String regex) {
  407. Set<String> source = Security.getAlgorithms("Cipher");
  408. Set<String> target = new TreeSet<String>();
  409. for (String algo : source) {
  410. algo = algo.toUpperCase();
  411. if (algo.matches(regex)) {
  412. target.add(algo);
  413. }
  414. }
  415. return new ArrayList<String>(target);
  416. }
  417. /**
  418. * Stream copy.
  419. *
  420. * @param from
  421. * @param into
  422. * @return count
  423. * @throws IOException
  424. */
  425. static long transferStream(InputStream from, OutputStream into)
  426. throws IOException {
  427. byte[] array = new byte[1 * 1024];
  428. long total = 0;
  429. while (true) {
  430. int count = from.read(array);
  431. if (count == -1) {
  432. break;
  433. }
  434. into.write(array, 0, count);
  435. total += count;
  436. }
  437. return total;
  438. }
  439. /**
  440. * Setup proxy during CI build.
  441. *
  442. * @throws Exception
  443. */
  444. // https://wiki.eclipse.org/Hudson#Accessing_the_Internet_using_Proxy
  445. // http://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html
  446. static void proxySetup() throws Exception {
  447. String keyNoProxy = "no_proxy";
  448. String keyHttpProxy = "http_proxy";
  449. String keyHttpsProxy = "https_proxy";
  450. String no_proxy = System.getProperty(keyNoProxy,
  451. System.getenv(keyNoProxy));
  452. if (no_proxy != null) {
  453. System.setProperty("http.nonProxyHosts", no_proxy);
  454. logger.info("Proxy NOT: " + no_proxy);
  455. }
  456. String http_proxy = System.getProperty(keyHttpProxy,
  457. System.getenv(keyHttpProxy));
  458. if (http_proxy != null) {
  459. URL url = new URL(http_proxy);
  460. System.setProperty("http.proxyHost", url.getHost());
  461. System.setProperty("http.proxyPort", "" + url.getPort());
  462. logger.info("Proxy HTTP: " + http_proxy);
  463. }
  464. String https_proxy = System.getProperty(keyHttpsProxy,
  465. System.getenv(keyHttpsProxy));
  466. if (https_proxy != null) {
  467. URL url = new URL(https_proxy);
  468. System.setProperty("https.proxyHost", url.getHost());
  469. System.setProperty("https.proxyPort", "" + url.getPort());
  470. logger.info("Proxy HTTPS: " + https_proxy);
  471. }
  472. if (no_proxy == null && http_proxy == null && https_proxy == null) {
  473. logger.info("Proxy not used.");
  474. }
  475. }
  476. /**
  477. * Permit long tests on CI or with manual activation.
  478. *
  479. * @return result
  480. */
  481. static boolean permitLongTests() {
  482. return isBuildCI() || isProfileActive();
  483. }
  484. /**
  485. * Using Maven profile activation, see pom.xml
  486. *
  487. * @return result
  488. */
  489. static boolean isProfileActive() {
  490. return Boolean.parseBoolean(System.getProperty("jgit.test.long"));
  491. }
  492. /**
  493. * Detect if build is running on CI.
  494. *
  495. * @return result
  496. */
  497. static boolean isBuildCI() {
  498. return System.getenv("HUDSON_HOME") != null;
  499. }
  500. /**
  501. * Setup JCE security policy restrictions. Can remove restrictions when
  502. * restrictions are present, but can not impose them when restrictions
  503. * are missing.
  504. *
  505. * @param restrictedOn
  506. */
  507. // http://www.docjar.com/html/api/javax/crypto/JceSecurity.java.html
  508. static void policySetup(boolean restrictedOn) {
  509. try {
  510. java.lang.reflect.Field isRestricted = Class
  511. .forName("javax.crypto.JceSecurity")
  512. .getDeclaredField("isRestricted");
  513. isRestricted.setAccessible(true);
  514. isRestricted.set(null, Boolean.valueOf(restrictedOn));
  515. } catch (Throwable e) {
  516. logger.info(
  517. "Could not setup JCE security policy restrictions.");
  518. }
  519. }
  520. static void reportPolicy() {
  521. try {
  522. java.lang.reflect.Field isRestricted = Class
  523. .forName("javax.crypto.JceSecurity")
  524. .getDeclaredField("isRestricted");
  525. isRestricted.setAccessible(true);
  526. logger.info("JCE security policy restricted="
  527. + isRestricted.get(null));
  528. } catch (Throwable e) {
  529. logger.info(
  530. "Could not report JCE security policy restrictions.");
  531. }
  532. }
  533. static List<Object[]> product(List<String> one, List<String> two) {
  534. List<Object[]> result = new ArrayList<Object[]>();
  535. for (String s1 : one) {
  536. for (String s2 : two) {
  537. result.add(new Object[] { s1, s2 });
  538. }
  539. }
  540. return result;
  541. }
  542. }
  543. /**
  544. * Common base for encryption tests.
  545. */
  546. @FixMethodOrder(MethodSorters.NAME_ASCENDING)
  547. public abstract static class Base extends SampleDataRepositoryTestCase {
  548. /**
  549. * S3 URI user used by JGIT to discover connection configuration file.
  550. */
  551. static final String JGIT_USER = "tester-" + System.currentTimeMillis();
  552. /**
  553. * S3 content encoding password used for this test session.
  554. */
  555. static final String JGIT_PASS = "secret-" + System.currentTimeMillis();
  556. /**
  557. * S3 repository configuration file expected by {@link AmazonS3}.
  558. */
  559. static final String JGIT_CONF_FILE = System.getProperty("user.home")
  560. + "/" + JGIT_USER;
  561. /**
  562. * Name representing remote or local JGIT repository.
  563. */
  564. static final String JGIT_REPO_DIR = JGIT_USER + ".jgit";
  565. /**
  566. * Local JGIT repository for this test session.
  567. */
  568. static final String JGIT_LOCAL_DIR = System.getProperty("user.dir")
  569. + "/target/" + JGIT_REPO_DIR;
  570. /**
  571. * Remote JGIT repository for this test session.
  572. */
  573. static final String JGIT_REMOTE_DIR = JGIT_REPO_DIR;
  574. /**
  575. * Generate JGIT S3 connection configuration file.
  576. *
  577. * @param algorithm
  578. * @throws Exception
  579. */
  580. static void configCreate(String algorithm) throws Exception {
  581. Properties props = Props.discover();
  582. props.put(AmazonS3.Keys.PASSWORD, JGIT_PASS);
  583. props.put(AmazonS3.Keys.CRYPTO_ALG, algorithm);
  584. PrintWriter writer = new PrintWriter(JGIT_CONF_FILE);
  585. props.store(writer, "JGIT S3 connection configuration file.");
  586. writer.close();
  587. }
  588. /**
  589. * Generate JGIT S3 connection configuration file.
  590. *
  591. * @param source
  592. * @throws Exception
  593. */
  594. static void configCreate(Properties source) throws Exception {
  595. Properties target = Props.discover();
  596. target.putAll(source);
  597. PrintWriter writer = new PrintWriter(JGIT_CONF_FILE);
  598. target.store(writer, "JGIT S3 connection configuration file.");
  599. writer.close();
  600. }
  601. /**
  602. * Remove JGIT connection configuration file.
  603. *
  604. * @throws Exception
  605. */
  606. static void configDelete() throws Exception {
  607. File path = new File(JGIT_CONF_FILE);
  608. FileUtils.delete(path, FileUtils.SKIP_MISSING);
  609. }
  610. /**
  611. * Generate remote URI for the test session.
  612. *
  613. * @return result
  614. * @throws Exception
  615. */
  616. static String amazonURI() throws Exception {
  617. Properties props = Props.discover();
  618. String bucket = props.getProperty(Names.TEST_BUCKET);
  619. assertNotNull(bucket);
  620. return TransportAmazonS3.S3_SCHEME + "://" + JGIT_USER + "@"
  621. + bucket + "/" + JGIT_REPO_DIR;
  622. }
  623. /**
  624. * Create S3 repository folder.
  625. *
  626. * @throws Exception
  627. */
  628. static void remoteCreate() throws Exception {
  629. Properties props = Props.discover();
  630. props.remove(AmazonS3.Keys.PASSWORD); // Disable encryption.
  631. String bucket = props.getProperty(Names.TEST_BUCKET);
  632. AmazonS3 s3 = new AmazonS3(props);
  633. String path = JGIT_REMOTE_DIR + "/";
  634. s3.put(bucket, path, new byte[0]);
  635. logger.debug("remote create: " + JGIT_REMOTE_DIR);
  636. }
  637. /**
  638. * Delete S3 repository folder.
  639. *
  640. * @throws Exception
  641. */
  642. static void remoteDelete() throws Exception {
  643. Properties props = Props.discover();
  644. props.remove(AmazonS3.Keys.PASSWORD); // Disable encryption.
  645. String bucket = props.getProperty(Names.TEST_BUCKET);
  646. AmazonS3 s3 = new AmazonS3(props);
  647. List<String> list = s3.list(bucket, JGIT_REMOTE_DIR);
  648. for (String path : list) {
  649. path = JGIT_REMOTE_DIR + "/" + path;
  650. s3.delete(bucket, path);
  651. }
  652. logger.debug("remote delete: " + JGIT_REMOTE_DIR);
  653. }
  654. /**
  655. * Verify if we can create/delete remote file.
  656. *
  657. * @throws Exception
  658. */
  659. static void remoteVerify() throws Exception {
  660. Properties props = Props.discover();
  661. String bucket = props.getProperty(Names.TEST_BUCKET);
  662. AmazonS3 s3 = new AmazonS3(props);
  663. String file = JGIT_USER + "-" + UUID.randomUUID().toString();
  664. String path = JGIT_REMOTE_DIR + "/" + file;
  665. s3.put(bucket, path, file.getBytes(UTF_8));
  666. s3.delete(bucket, path);
  667. }
  668. /**
  669. * Verify if any security provider published the algorithm.
  670. *
  671. * @param algorithm
  672. * @return result
  673. */
  674. static boolean isAlgorithmPresent(String algorithm) {
  675. Set<String> cipherSet = Security.getAlgorithms("Cipher");
  676. for (String source : cipherSet) {
  677. // Standard names are not case-sensitive.
  678. // http://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html
  679. String target = algorithm.toUpperCase();
  680. if (source.equalsIgnoreCase(target)) {
  681. return true;
  682. }
  683. }
  684. return false;
  685. }
  686. static boolean isAlgorithmPresent(Properties props) {
  687. String profile = props.getProperty(AmazonS3.Keys.CRYPTO_ALG);
  688. String version = props.getProperty(AmazonS3.Keys.CRYPTO_VER,
  689. WalkEncryption.Vals.DEFAULT_VERS);
  690. String crytoAlgo;
  691. String keyAlgo;
  692. switch (version) {
  693. case WalkEncryption.Vals.DEFAULT_VERS:
  694. case WalkEncryption.JGitV1.VERSION:
  695. crytoAlgo = profile;
  696. keyAlgo = profile;
  697. break;
  698. case WalkEncryption.JGitV2.VERSION:
  699. crytoAlgo = props
  700. .getProperty(profile + WalkEncryption.Keys.X_ALGO);
  701. keyAlgo = props
  702. .getProperty(profile + WalkEncryption.Keys.X_KEY_ALGO);
  703. break;
  704. default:
  705. return false;
  706. }
  707. try {
  708. Cipher.getInstance(crytoAlgo);
  709. SecretKeyFactory.getInstance(keyAlgo);
  710. return true;
  711. } catch (Throwable e) {
  712. return false;
  713. }
  714. }
  715. /**
  716. * Verify if JRE security policy allows the algorithm.
  717. *
  718. * @param algorithm
  719. * @return result
  720. */
  721. static boolean isAlgorithmAllowed(String algorithm) {
  722. try {
  723. WalkEncryption crypto = new WalkEncryption.JetS3tV2(
  724. algorithm, JGIT_PASS);
  725. verifyCrypto(crypto);
  726. return true;
  727. } catch (IOException e) {
  728. return false; // Encryption failure.
  729. } catch (GeneralSecurityException e) {
  730. throw new Error(e); // Construction failure.
  731. }
  732. }
  733. static boolean isAlgorithmAllowed(Properties props) {
  734. try {
  735. WalkEncryption.instance(props);
  736. return true;
  737. } catch (GeneralSecurityException e) {
  738. return false;
  739. }
  740. }
  741. /**
  742. * Verify round trip encryption.
  743. *
  744. * @param crypto
  745. * @throws IOException
  746. */
  747. static void verifyCrypto(WalkEncryption crypto) throws IOException {
  748. String charset = "UTF-8";
  749. String sourceText = "secret-message Свобода 老子";
  750. String targetText;
  751. byte[] cipherText;
  752. {
  753. byte[] origin = sourceText.getBytes(charset);
  754. ByteArrayOutputStream target = new ByteArrayOutputStream();
  755. OutputStream source = crypto.encrypt(target);
  756. source.write(origin);
  757. source.flush();
  758. source.close();
  759. cipherText = target.toByteArray();
  760. }
  761. {
  762. InputStream source = new ByteArrayInputStream(cipherText);
  763. InputStream target = crypto.decrypt(source);
  764. ByteArrayOutputStream result = new ByteArrayOutputStream();
  765. transferStream(target, result);
  766. targetText = result.toString(charset);
  767. }
  768. assertEquals(sourceText, targetText);
  769. }
  770. /**
  771. * Algorithm is testable when it is present and allowed by policy.
  772. *
  773. * @param algorithm
  774. * @return result
  775. */
  776. static boolean isAlgorithmTestable(String algorithm) {
  777. return isAlgorithmPresent(algorithm)
  778. && isAlgorithmAllowed(algorithm);
  779. }
  780. static boolean isAlgorithmTestable(Properties props) {
  781. return isAlgorithmPresent(props) && isAlgorithmAllowed(props);
  782. }
  783. /**
  784. * Log algorithm, provider, testability.
  785. *
  786. * @param algorithm
  787. * @throws Exception
  788. */
  789. static void reportAlgorithmStatus(String algorithm) throws Exception {
  790. final boolean present = isAlgorithmPresent(algorithm);
  791. final boolean allowed = present && isAlgorithmAllowed(algorithm);
  792. final String provider = present ? securityProviderName(algorithm)
  793. : "N/A";
  794. String status = "Algorithm: " + algorithm + " @ " + provider + "; "
  795. + "present/allowed : " + present + "/" + allowed;
  796. if (allowed) {
  797. logger.info("Testing " + status);
  798. } else {
  799. logger.warn("Missing " + status);
  800. }
  801. }
  802. static void reportAlgorithmStatus(Properties props) throws Exception {
  803. final boolean present = isAlgorithmPresent(props);
  804. final boolean allowed = present && isAlgorithmAllowed(props);
  805. String profile = props.getProperty(AmazonS3.Keys.CRYPTO_ALG);
  806. String version = props.getProperty(AmazonS3.Keys.CRYPTO_VER);
  807. StringBuilder status = new StringBuilder();
  808. status.append(" Version: " + version);
  809. status.append(" Profile: " + profile);
  810. status.append(" Present: " + present);
  811. status.append(" Allowed: " + allowed);
  812. if (allowed) {
  813. logger.info("Testing " + status);
  814. } else {
  815. logger.warn("Missing " + status);
  816. }
  817. }
  818. /**
  819. * Verify if we can perform remote tests.
  820. *
  821. * @return result
  822. */
  823. static boolean isTestConfigPresent() {
  824. try {
  825. Props.discover();
  826. return true;
  827. } catch (Throwable e) {
  828. return false;
  829. }
  830. }
  831. static void reportTestConfigPresent() {
  832. if (isTestConfigPresent()) {
  833. logger.info("Amazon S3 test configuration is present.");
  834. } else {
  835. logger.error(
  836. "Amazon S3 test configuration is missing, tests will not run.");
  837. }
  838. }
  839. /**
  840. * Log public address of CI.
  841. *
  842. * @throws Exception
  843. */
  844. static void reportPublicAddress() throws Exception {
  845. logger.info("Public address: " + publicAddress());
  846. }
  847. /**
  848. * BouncyCastle provider class.
  849. *
  850. * Needs extra dependency, see pom.xml
  851. */
  852. // http://search.maven.org/#artifactdetails%7Corg.bouncycastle%7Cbcprov-jdk15on%7C1.52%7Cjar
  853. static final String PROVIDER_BC = "org.bouncycastle.jce.provider.BouncyCastleProvider";
  854. /**
  855. * Load BouncyCastle provider if present.
  856. */
  857. static void loadBouncyCastle() {
  858. try {
  859. Class<?> provider = Class.forName(PROVIDER_BC);
  860. Provider instance = (Provider) provider
  861. .getConstructor(new Class[] {})
  862. .newInstance(new Object[] {});
  863. Security.addProvider(instance);
  864. logger.info("Loaded " + PROVIDER_BC);
  865. } catch (Throwable e) {
  866. logger.warn("Failed to load " + PROVIDER_BC);
  867. }
  868. }
  869. static void reportLongTests() {
  870. if (permitLongTests()) {
  871. logger.info("Long running tests are enabled.");
  872. } else {
  873. logger.warn("Long running tests are disabled.");
  874. }
  875. }
  876. /**
  877. * Non-PBE algorithm, for error check.
  878. */
  879. static final String ALGO_ERROR = "PBKDF2WithHmacSHA1";
  880. /**
  881. * Default JetS3t algorithm present in most JRE.
  882. */
  883. static final String ALGO_JETS3T = "PBEWithMD5AndDES";
  884. /**
  885. * Minimal strength AES based algorithm present in most JRE.
  886. */
  887. static final String ALGO_MINIMAL_AES = "PBEWithHmacSHA1AndAES_128";
  888. /**
  889. * Selected non-AES algorithm present in BouncyCastle provider.
  890. */
  891. static final String ALGO_BOUNCY_CASTLE_CBC = "PBEWithSHAAndTwofish-CBC";
  892. //////////////////////////////////////////////////
  893. @BeforeClass
  894. public static void initialize() throws Exception {
  895. Transport.register(TransportAmazonS3.PROTO_S3);
  896. proxySetup();
  897. reportPolicy();
  898. reportLongTests();
  899. reportPublicAddress();
  900. reportTestConfigPresent();
  901. loadBouncyCastle();
  902. if (isTestConfigPresent()) {
  903. remoteCreate();
  904. }
  905. }
  906. @AfterClass
  907. public static void terminate() throws Exception {
  908. configDelete();
  909. folderDelete(JGIT_LOCAL_DIR);
  910. if (isTestConfigPresent()) {
  911. remoteDelete();
  912. }
  913. }
  914. @Before
  915. @Override
  916. public void setUp() throws Exception {
  917. super.setUp();
  918. }
  919. @After
  920. @Override
  921. public void tearDown() throws Exception {
  922. super.tearDown();
  923. }
  924. /**
  925. * Optional encrypted amazon remote JGIT life cycle test.
  926. *
  927. * @param props
  928. * @throws Exception
  929. */
  930. void cryptoTestIfCan(Properties props) throws Exception {
  931. reportAlgorithmStatus(props);
  932. assumeTrue(isTestConfigPresent());
  933. assumeTrue(isAlgorithmTestable(props));
  934. cryptoTest(props);
  935. }
  936. /**
  937. * Required encrypted amazon remote JGIT life cycle test.
  938. *
  939. * @param props
  940. * @throws Exception
  941. */
  942. void cryptoTest(Properties props) throws Exception {
  943. remoteDelete();
  944. configCreate(props);
  945. folderDelete(JGIT_LOCAL_DIR);
  946. String uri = amazonURI();
  947. // Local repositories.
  948. File dirOne = db.getWorkTree(); // Provided by setup.
  949. File dirTwo = new File(JGIT_LOCAL_DIR);
  950. // Local verification files.
  951. String nameStatic = "master.txt"; // Provided by setup.
  952. String nameDynamic = JGIT_USER + "-" + UUID.randomUUID().toString();
  953. String remote = "remote";
  954. RefSpec specs = new RefSpec("refs/heads/master:refs/heads/master");
  955. { // Push into remote from local one.
  956. StoredConfig config = db.getConfig();
  957. RemoteConfig remoteConfig = new RemoteConfig(config, remote);
  958. remoteConfig.addURI(new URIish(uri));
  959. remoteConfig.update(config);
  960. config.save();
  961. Git git = Git.open(dirOne);
  962. git.checkout().setName("master").call();
  963. git.push().setRemote(remote).setRefSpecs(specs).call();
  964. git.close();
  965. File fileStatic = new File(dirOne, nameStatic);
  966. assertTrue("Provided by setup", fileStatic.exists());
  967. }
  968. { // Clone from remote into local two.
  969. File fileStatic = new File(dirTwo, nameStatic);
  970. assertFalse("Not Provided by setup", fileStatic.exists());
  971. Git git = Git.cloneRepository().setURI(uri).setDirectory(dirTwo)
  972. .call();
  973. git.close();
  974. assertTrue("Provided by clone", fileStatic.exists());
  975. }
  976. { // Verify static file content.
  977. File fileOne = new File(dirOne, nameStatic);
  978. File fileTwo = new File(dirTwo, nameStatic);
  979. verifyFileContent(fileOne, fileTwo);
  980. }
  981. { // Verify new file commit and push from local one.
  982. File fileDynamic = new File(dirOne, nameDynamic);
  983. assertFalse("Not Provided by setup", fileDynamic.exists());
  984. FileUtils.createNewFile(fileDynamic);
  985. textWrite(fileDynamic, nameDynamic);
  986. assertTrue("Provided by create", fileDynamic.exists());
  987. assertTrue("Need content to encrypt", fileDynamic.length() > 0);
  988. Git git = Git.open(dirOne);
  989. git.add().addFilepattern(nameDynamic).call();
  990. git.commit().setMessage(nameDynamic).call();
  991. git.push().setRemote(remote).setRefSpecs(specs).call();
  992. git.close();
  993. }
  994. { // Verify new file pull from remote into local two.
  995. File fileDynamic = new File(dirTwo, nameDynamic);
  996. assertFalse("Not Provided by setup", fileDynamic.exists());
  997. Git git = Git.open(dirTwo);
  998. git.pull().call();
  999. git.close();
  1000. assertTrue("Provided by pull", fileDynamic.exists());
  1001. }
  1002. { // Verify dynamic file content.
  1003. File fileOne = new File(dirOne, nameDynamic);
  1004. File fileTwo = new File(dirTwo, nameDynamic);
  1005. verifyFileContent(fileOne, fileTwo);
  1006. }
  1007. }
  1008. }
  1009. /**
  1010. * Verify prerequisites.
  1011. */
  1012. @FixMethodOrder(MethodSorters.NAME_ASCENDING)
  1013. public static class Required extends Base {
  1014. @Test
  1015. public void test_A1_ValidURI() throws Exception {
  1016. assumeTrue(isTestConfigPresent());
  1017. URIish uri = new URIish(amazonURI());
  1018. assertTrue("uri=" + uri, TransportAmazonS3.PROTO_S3.canHandle(uri));
  1019. }
  1020. @Test(expected = Exception.class)
  1021. public void test_A2_CryptoError() throws Exception {
  1022. assumeTrue(isTestConfigPresent());
  1023. Properties props = new Properties();
  1024. props.put(AmazonS3.Keys.CRYPTO_ALG, ALGO_ERROR);
  1025. props.put(AmazonS3.Keys.PASSWORD, JGIT_PASS);
  1026. cryptoTest(props);
  1027. }
  1028. }
  1029. /**
  1030. * Test minimal set of algorithms.
  1031. */
  1032. @FixMethodOrder(MethodSorters.NAME_ASCENDING)
  1033. public static class MinimalSet extends Base {
  1034. @Test
  1035. public void test_V0_Java7_JET() throws Exception {
  1036. assumeTrue(isTestConfigPresent());
  1037. Properties props = new Properties();
  1038. props.put(AmazonS3.Keys.CRYPTO_ALG, ALGO_JETS3T);
  1039. // Do not set version.
  1040. props.put(AmazonS3.Keys.PASSWORD, JGIT_PASS);
  1041. cryptoTestIfCan(props);
  1042. }
  1043. @Test
  1044. public void test_V1_Java7_GIT() throws Exception {
  1045. assumeTrue(isTestConfigPresent());
  1046. Properties props = new Properties();
  1047. props.put(AmazonS3.Keys.CRYPTO_ALG, ALGO_JETS3T);
  1048. props.put(AmazonS3.Keys.CRYPTO_VER, "1");
  1049. props.put(AmazonS3.Keys.PASSWORD, JGIT_PASS);
  1050. cryptoTestIfCan(props);
  1051. }
  1052. @Test
  1053. public void test_V2_Java7_AES() throws Exception {
  1054. assumeTrue(isTestConfigPresent());
  1055. // String profile = "default";
  1056. String profile = "AES/CBC/PKCS5Padding+PBKDF2WithHmacSHA1";
  1057. Properties props = new Properties();
  1058. props.put(AmazonS3.Keys.CRYPTO_ALG, profile);
  1059. props.put(AmazonS3.Keys.CRYPTO_VER, "2");
  1060. props.put(AmazonS3.Keys.PASSWORD, JGIT_PASS);
  1061. props.put(profile + WalkEncryption.Keys.X_ALGO, "AES/CBC/PKCS5Padding");
  1062. props.put(profile + WalkEncryption.Keys.X_KEY_ALGO, "PBKDF2WithHmacSHA1");
  1063. props.put(profile + WalkEncryption.Keys.X_KEY_SIZE, "128");
  1064. props.put(profile + WalkEncryption.Keys.X_KEY_ITER, "10000");
  1065. props.put(profile + WalkEncryption.Keys.X_KEY_SALT, "e2 55 89 67 8e 8d e8 4c");
  1066. cryptoTestIfCan(props);
  1067. }
  1068. @Test
  1069. public void test_V2_Java8_PBE_AES() throws Exception {
  1070. assumeTrue(isTestConfigPresent());
  1071. String profile = "PBEWithHmacSHA512AndAES_256";
  1072. Properties props = new Properties();
  1073. props.put(AmazonS3.Keys.CRYPTO_ALG, profile);
  1074. props.put(AmazonS3.Keys.CRYPTO_VER, "2");
  1075. props.put(AmazonS3.Keys.PASSWORD, JGIT_PASS);
  1076. props.put(profile + WalkEncryption.Keys.X_ALGO, "PBEWithHmacSHA512AndAES_256");
  1077. props.put(profile + WalkEncryption.Keys.X_KEY_ALGO, "PBEWithHmacSHA512AndAES_256");
  1078. props.put(profile + WalkEncryption.Keys.X_KEY_SIZE, "256");
  1079. props.put(profile + WalkEncryption.Keys.X_KEY_ITER, "10000");
  1080. props.put(profile + WalkEncryption.Keys.X_KEY_SALT, "e2 55 89 67 8e 8d e8 4c");
  1081. policySetup(false);
  1082. cryptoTestIfCan(props);
  1083. }
  1084. }
  1085. /**
  1086. * Test all present and allowed PBE algorithms.
  1087. */
  1088. // https://github.com/junit-team/junit/wiki/Parameterized-tests
  1089. @RunWith(Parameterized.class)
  1090. @FixMethodOrder(MethodSorters.NAME_ASCENDING)
  1091. public static class TestablePBE extends Base {
  1092. @Parameters(name = "Profile: {0} Version: {1}")
  1093. public static Collection<Object[]> argsList() {
  1094. List<String> algorithmList = new ArrayList<String>();
  1095. algorithmList.addAll(cryptoCipherListPBE());
  1096. List<String> versionList = new ArrayList<String>();
  1097. versionList.add("0");
  1098. versionList.add("1");
  1099. return product(algorithmList, versionList);
  1100. }
  1101. final String profile;
  1102. final String version;
  1103. final String password = JGIT_PASS;
  1104. public TestablePBE(String profile, String version) {
  1105. this.profile = profile;
  1106. this.version = version;
  1107. }
  1108. @Test
  1109. public void testCrypto() throws Exception {
  1110. assumeTrue(permitLongTests());
  1111. Properties props = new Properties();
  1112. props.put(AmazonS3.Keys.CRYPTO_ALG, profile);
  1113. props.put(AmazonS3.Keys.CRYPTO_VER, version);
  1114. props.put(AmazonS3.Keys.PASSWORD, password);
  1115. cryptoTestIfCan(props);
  1116. }
  1117. }
  1118. /**
  1119. * Test all present and allowed transformation algorithms.
  1120. */
  1121. // https://github.com/junit-team/junit/wiki/Parameterized-tests
  1122. @RunWith(Parameterized.class)
  1123. @FixMethodOrder(MethodSorters.NAME_ASCENDING)
  1124. public static class TestableTransformation extends Base {
  1125. @Parameters(name = "Profile: {0} Version: {1}")
  1126. public static Collection<Object[]> argsList() {
  1127. List<String> algorithmList = new ArrayList<String>();
  1128. algorithmList.addAll(cryptoCipherListTrans());
  1129. List<String> versionList = new ArrayList<String>();
  1130. versionList.add("1");
  1131. return product(algorithmList, versionList);
  1132. }
  1133. final String profile;
  1134. final String version;
  1135. final String password = JGIT_PASS;
  1136. public TestableTransformation(String profile, String version) {
  1137. this.profile = profile;
  1138. this.version = version;
  1139. }
  1140. @Test
  1141. public void testCrypto() throws Exception {
  1142. assumeTrue(permitLongTests());
  1143. Properties props = new Properties();
  1144. props.put(AmazonS3.Keys.CRYPTO_ALG, profile);
  1145. props.put(AmazonS3.Keys.CRYPTO_VER, version);
  1146. props.put(AmazonS3.Keys.PASSWORD, password);
  1147. cryptoTestIfCan(props);
  1148. }
  1149. }
  1150. }