Skip to content

Commit

Permalink
Format java files in o.e.equinox.security.tests
Browse files Browse the repository at this point in the history
This was achieved by running:
eclipse -consolelog -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter \
  -config .settings/org.eclipse.jdt.core.prefs . -data `mktemp -d`

Signed-off-by: Torbjörn SVENSSON <[email protected]>
  • Loading branch information
Torbjorn-Svensson committed Nov 3, 2023
1 parent 6e6a86d commit 153af44
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class SecurityTestsActivator implements BundleActivator {
private BundleContext bundleContext;

/*
* Returns the singleton for this Activator. Callers should be aware that
* this will return nulCooll if the bundle is not active.
* Returns the singleton for this Activator. Callers should be aware that this
* will return nulCooll if the bundle is not active.
*/
public static SecurityTestsActivator getDefault() {
return singleton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Base64Test {
final private static String decoded2 = "lazy frog jumped over sleeping dog";
final private static String encoded2 = "bGF6eSBmcm9nIGp1bXBlZCBvdmVyIHNsZWVwaW5nIGRvZw==";

final private static byte[] decoded3 = {5, 0, 0, 12, 32, 1, 127, (byte) 0xFF};
final private static byte[] decoded3 = { 5, 0, 0, 12, 32, 1, 127, (byte) 0xFF };
final private static String encoded3 = "BQAADCABf/8=";

final private static byte[] decoded4 = new byte[0];
Expand Down Expand Up @@ -73,7 +73,7 @@ public void testHandCoded() {
}

/**
* Tests edge conditions: null or empty arguments
* Tests edge conditions: null or empty arguments
*/
@Test
public void testEdge() {
Expand All @@ -89,7 +89,7 @@ public void testEdge() {
}

/**
* Tests round trip using large random sequences
* Tests round trip using large random sequences
*/
@Test
public void testRandom() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
*
* This test is only interested in PBE Ciphers for the secure storage.
*
* !IMPORTANT! It can only pass if crypto.policy is set to 'unlimited' !IMPORTANT!
* !IMPORTANT! It can only pass if crypto.policy is set to 'unlimited'
* !IMPORTANT!
*
* The test "rebuilds" the logic of searching for keyFactories and matching PBE ciphers.
* For these ciphers the "roundtrip" has to be successful, otherwise the SecureStorage
* implementation does not use the cipher correctly and it cannot be used.
* The test "rebuilds" the logic of searching for keyFactories and matching PBE
* ciphers. For these ciphers the "roundtrip" has to be successful, otherwise
* the SecureStorage implementation does not use the cipher correctly and it
* cannot be used.
*/
public class DetectPBECiphersTest {

Expand All @@ -42,16 +44,18 @@ public void testPBEDetect() {
int cipherJVMCount = 0;
Set<String> keyFactories = new HashSet<>();
Provider[] providers = Security.getProviders();
for (Provider p : providers) { //find all key factories
for (Provider p : providers) { // find all key factories
for (Provider.Service service : p.getServices()) {
if (service.getType().equals("SecretKeyFactory") && service.getAlgorithm().indexOf(' ') == -1) {// skips properties like "[Cipher.ABC SupportedPaddings]")
// skip properties like "[Cipher.ABC SupportedPaddings]")
if (service.getType().equals("SecretKeyFactory") && service.getAlgorithm().indexOf(' ') == -1) {
keyFactories.add(service.getAlgorithm());
}
}
}
for (Provider p : providers) { //find all ciphers matching a key factory and start with PBE
for (Provider p : providers) { // find all ciphers matching a key factory and start with PBE
for (Provider.Service service : p.getServices()) {
if (service.getType().equals("Cipher") && service.getAlgorithm().startsWith("PBE") && keyFactories.contains(service.getAlgorithm())) {
if (service.getType().equals("Cipher") && service.getAlgorithm().startsWith("PBE")
&& keyFactories.contains(service.getAlgorithm())) {
cipherJVMCount++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.osgi.framework.*;

/**
* In those tests listener is used to synchronize with the asynchronous registry processing
* when bundle is added / removed.
* In those tests listener is used to synchronize with the asynchronous registry
* processing when bundle is added / removed.
*/
public class DynamicPreferencesTest extends StorageAbstractTest {

Expand Down Expand Up @@ -98,7 +98,7 @@ public void testDynamicMemory() throws Exception {
// check original elements - should be able to read fine
check(preferences);
} finally {
// in case of exception in the process
// in case of exception in the process
if (bundle02 != null)
bundle02.uninstall();
if (bundle01 != null)
Expand Down Expand Up @@ -156,7 +156,7 @@ public void testDynamicPersisted() throws Exception {
check(preferences);
}
} finally {
// in case of exception in the process
// in case of exception in the process
if (bundle02 != null)
bundle02.uninstall();
if (bundle01 != null)
Expand All @@ -177,14 +177,14 @@ protected void checkUnreadable(ISecurePreferences node, String keyToCheck) {
}

protected Map<String, Object> getOptions() {
// Don't specify default password for those tests; they need to have
// password providers
// Don't specify default password for those tests; they need to have
// password providers
return getOptions(null);
}

/**
* Synchronizes to ensure bundle XML contribution has been processed
* before method returns.
* Synchronizes to ensure bundle XML contribution has been processed before
* method returns.
*/
protected Bundle installBundle(String bundlePath) throws MalformedURLException, BundleException, IOException {
BundleContext bundleContext = SecurityTestsActivator.getDefault().getBundleContext();
Expand All @@ -194,7 +194,7 @@ protected Bundle installBundle(String bundlePath) throws MalformedURLException,

try {
bundle = BundleTestingHelper.installBundle("0.1", bundleContext, TEST_FILES_ROOT + bundlePath);
BundleTestingHelper.refreshPackages(bundleContext, new Bundle[] {bundle});
BundleTestingHelper.refreshPackages(bundleContext, new Bundle[] { bundle });
// synchronization: listener should receive 1 group of events
assertTrue(listener.waitFor(1, MAX_TIME_PER_BUNDLE) == 1);
} finally {
Expand All @@ -204,8 +204,8 @@ protected Bundle installBundle(String bundlePath) throws MalformedURLException,
}

/**
* Synchronizes to ensure bundle XML contribution has been processed
* before method returns.
* Synchronizes to ensure bundle XML contribution has been processed before
* method returns.
*/
protected boolean uninstallBundle(Bundle bundle) throws BundleException {
WaitingRegistryListener listener = new WaitingRegistryListener();
Expand All @@ -220,7 +220,7 @@ protected boolean uninstallBundle(Bundle bundle) throws BundleException {
return true;
} finally {
listener.unregister();
// in case of exception in the process
// in case of exception in the process
if (bundle != null)
bundle.uninstall();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import org.junit.Test;

/**
* This is a semi-manual test; expected to be run with modules requiring
* UI interactions. Set configuration before executing this so that desired
* storage module is selected.
* This is a semi-manual test; expected to be run with modules requiring UI
* interactions. Set configuration before executing this so that desired storage
* module is selected.
*/
public class ManualTest {

Expand Down Expand Up @@ -59,35 +59,37 @@ public void testBasic() {
}
}

// @formatter:off
/*
* In theory, all those ciphers support "Raw" key factory format - the SecretKeyFactory
* algorithm should be really irrelevant. That said, Blowfish would not work with JavaCrypt
* - so need to manually test all and exclude those that we know not supported
* (or provide a roundtrip test - if it fails, exclude the value)
[keyFactory] PBKDF2WithHmacSHA1
[keyFactory] DES
[keyFactory] DESede
[keyFactory] PBE
[keyFactory] PBEWithSHA1AndRC2_40
[keyFactory] PBEWithSHA1AndDESede
[keyFactory] PBEWithMD5AndTripleDES
[keyFactory] PBEWithMD5AndDES
[cypher] DES
[cypher] Blowfish
[cypher] RC2
[cypher] AES
[cypher] DESede
[cypher] PBEWithMD5AndDES
[cypher] PBEWithMD5AndTripleDES
[cypher] ARCFOUR
[cypher] RSA
[cypher] AESWrap
[cypher] PBEWithSHA1AndRC2_40
[cypher] PBEWithSHA1AndDESede
[cypher] DESedeWrap
http://java.sun.com/javase/6/docs/technotes/guides/security/StandardNames.html#SecretKeyFactory
http://java.sun.com/j2se/1.4.2/docs/guide/security/jce/JCERefGuide.html#AppA
* [keyFactory] PBKDF2WithHmacSHA1
* [keyFactory] DES
* [keyFactory] DESede
* [keyFactory] PBE
* [keyFactory] PBEWithSHA1AndRC2_40
* [keyFactory] PBEWithSHA1AndDESede
* [keyFactory] PBEWithMD5AndTripleDES
* [keyFactory] PBEWithMD5AndDES
* [cypher] DES
* [cypher] Blowfish
* [cypher] RC2
* [cypher] AES
* [cypher] DESede
* [cypher] PBEWithMD5AndDES
* [cypher] PBEWithMD5AndTripleDES
* [cypher] ARCFOUR
* [cypher] RSA
* [cypher] AESWrap
* [cypher] PBEWithSHA1AndRC2_40
* [cypher] PBEWithSHA1AndDESede
* [cypher] DESedeWrap
* http://java.sun.com/javase/6/docs/technotes/guides/security/StandardNames.html#SecretKeyFactory
* http://java.sun.com/j2se/1.4.2/docs/guide/security/jce/JCERefGuide.html#AppA
*/
// @formatter:on
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ abstract public class SecurePreferencesTest extends StorageAbstractTest {
final private static String unicodeValue = "va\u0432lue\u0433";

protected Map<String, Object> getOptions() {
// Note that if the default password value below is modified,
// Note that if the default password value below is modified,
// the sample storage file needs to be regenerated.
return getOptions("password1");
}
Expand Down Expand Up @@ -83,8 +83,8 @@ private void fill(ISecurePreferences preferences) throws StorageException {
}

/**
* The method reaches into internal classes to check if modified flag is set on secure
* preference data.
* The method reaches into internal classes to check if modified flag is set on
* secure preference data.
*/
private boolean isModified(ISecurePreferences node) {
return InternalExchangeUtils.isModified(node);
Expand Down Expand Up @@ -118,12 +118,12 @@ private void check(ISecurePreferences preferences) throws StorageException {
String[] leafKeys = node3.keys();
assertNotNull(leafKeys);
assertEquals(leafKeys.length, 4);
findAll(new String[] {clearTextKey, key, secondKey, unicodeKey}, leafKeys);
findAll(new String[] { clearTextKey, key, secondKey, unicodeKey }, leafKeys);
}

/**
* Basic test to fill / read Preferences implementation. Also tests removal of a value
* and Preferences#keys().
* Basic test to fill / read Preferences implementation. Also tests removal of a
* value and Preferences#keys().
*/
@Test
public void testPreferences() throws IOException, StorageException {
Expand All @@ -143,7 +143,8 @@ public void testPreferences() throws IOException, StorageException {

/**
* Test relative names, absolute names, and children names
* @throws StorageException
*
* @throws StorageException
*/
@Test
public void testNames() throws IOException, StorageException {
Expand Down Expand Up @@ -193,8 +194,8 @@ public void testNames() throws IOException, StorageException {
}

/**
* Test node existence, resolution: parent -> child; child -> parent,
* compare absolute and relative paths.
* Test node existence, resolution: parent -> child; child -> parent, compare
* absolute and relative paths.
*/
@Test
public void testNodeResolution() throws IOException, StorageException {
Expand Down Expand Up @@ -222,7 +223,7 @@ public void testNodeResolution() throws IOException, StorageException {
ISecurePreferences node3 = preferences.node("/test/cvs/eclipse.org/account1");
assertNotNull(node3);

// relative paths, parents and compare to results from absolute paths:
// relative paths, parents and compare to results from absolute paths:
assertNull(preferences.parent());
assertEquals(nodeRoot, preferences);

Expand All @@ -247,14 +248,15 @@ public void testNodeResolution() throws IOException, StorageException {
assertEquals(node3, relativeNode3);
assertEquals(relativeNode2, relativeNode3.parent());

//check contents to make sure that traversing did not add and new children
// check contents to make sure that traversing did not add and new children
preferences.flush();
check(preferences);
}

/**
* Tests node removal.
* @throws StorageException
*
* @throws StorageException
*/
@Test
public void testNodeRemoval() throws IOException, StorageException {
Expand Down Expand Up @@ -314,7 +316,8 @@ public void testNodeRemoval() throws IOException, StorageException {

/**
* Tests validation of node paths.
* @throws Throwable
*
* @throws Throwable
*/
@Test
public void testPathValidation() throws Throwable {
Expand Down Expand Up @@ -361,16 +364,17 @@ public void testLocation() throws MalformedURLException {

/**
* Tests data types
* @throws StorageException
* @throws IOException
* @throws MalformedURLException
*
* @throws StorageException
* @throws IOException
* @throws MalformedURLException
*/
@Test
public void testDataTypes() throws StorageException, MalformedURLException, IOException {
ISecurePreferences preferences = newPreferences(getStorageLocation(), getOptions());

ISecurePreferences node = preferences.node("/test");
byte[] testArray = new byte[] {0, 4, 12, 75, 84, 12, 1, (byte) 0xFF};
byte[] testArray = new byte[] { 0, 4, 12, 75, 84, 12, 1, (byte) 0xFF };

boolean encrypt = true;

Expand Down Expand Up @@ -410,7 +414,8 @@ public void testDataTypes() throws StorageException, MalformedURLException, IOEx
@Test
public void testIncorrectData() throws IOException {
URL location = getFilePath(sampleLocation);
// Same default password as in the SecurePreferencesTest.getOptions() - same note
// Same default password as in the SecurePreferencesTest.getOptions() - same
// note
// on regenerating data file.
ISecurePreferences preferences = newPreferences(location, getOptions("password1"));
try {
Expand Down Expand Up @@ -503,7 +508,7 @@ public void testModules() throws IOException {
@Test
public void testEdgeCases() throws StorageException, MalformedURLException, IOException {
byte[] expectedEmptyArray = new byte[0];
byte[] wrongArray = new byte[] {1, 2, 3};
byte[] wrongArray = new byte[] { 1, 2, 3 };

{ // block1: fill, check, and save
ISecurePreferences preferences = newPreferences(getStorageLocation(), getOptions());
Expand Down
Loading

0 comments on commit 153af44

Please sign in to comment.