[PAN-2652] Refactor Privacy acceptance test and add Privacy Ibft test (#1483)

* Add IBFT2 Privacy Acceptance test

* Refactor eea conditions

* Refactor privacy test utils

* Refactor privacy tests

* Fix typo

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
This commit is contained in:
Ivaylo Kirilov
2019-05-24 00:31:17 +05:30
committed by Eric Kellstrand
parent fc4f9917b7
commit e91ba1efea
27 changed files with 1481 additions and 701 deletions

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed 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 tech.pegasys.orion.testutil;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Base64;
import net.consensys.cava.bytes.Bytes;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class OrionKeyGenerator {
private static final Logger LOG = LogManager.getLogger();
public static KeyPair generateKeys() throws NoSuchAlgorithmException {
final KeyPair keyPair = KeyPairGenerator.getInstance("Ed25519").generateKeyPair();
final PublicKey pubKey = keyPair.getPublic();
final PrivateKey privKey = keyPair.getPrivate();
LOG.debug("pubkey : " + pubKey);
LOG.debug("pubkey bytes: " + Bytes.wrap(pubKey.getEncoded()).toHexString());
LOG.debug("pubkey b64 : " + Base64.getEncoder().encodeToString(pubKey.getEncoded()));
LOG.debug("privkey : " + privKey);
LOG.debug("privkey bytes: " + Bytes.wrap(privKey.getEncoded()).toHexString());
LOG.debug("privkey b64 : " + Base64.getEncoder().encodeToString(privKey.getEncoded()));
return keyPair;
}
}

View File

@@ -12,30 +12,86 @@
*/
package tech.pegasys.orion.testutil;
import static java.nio.charset.StandardCharsets.UTF_8;
import static net.consensys.cava.io.file.Files.copyResource;
import java.io.IOException;
import java.nio.file.Path;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Base64;
import com.google.common.io.CharSink;
import com.google.common.io.Files;
import net.consensys.orion.cmd.Orion;
import net.consensys.orion.config.Config;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters;
import org.bouncycastle.crypto.params.Ed25519PublicKeyParameters;
public class OrionTestHarnessFactory {
private static final Logger LOG = LogManager.getLogger();
protected static final String HOST = "127.0.0.1";
public static OrionTestHarness create(
final Path tempDir,
final Ed25519PublicKeyParameters pubKey,
final String pubKeyPath,
final Ed25519PrivateKeyParameters privKey,
final String privKeyPath,
final String... othernodes)
throws IOException {
return create(
tempDir, pubKeyPath, privKeyPath, pubKey.getEncoded(), privKey.getEncoded(), othernodes);
}
public static OrionTestHarness create(
final Path tempDir,
final PublicKey pubKey,
final String pubKeyPath,
final PrivateKey privKey,
final String privKeyPath,
final String... othernodes)
throws IOException {
return create(
tempDir, pubKeyPath, privKeyPath, pubKey.getEncoded(), privKey.getEncoded(), othernodes);
}
private static OrionTestHarness create(
final Path tempDir,
final String pubKeyPath,
final String privKeyPath,
final byte[] encodedPubKey,
final byte[] encodedPrivKey,
final String[] othernodes)
throws IOException {
final Path pubKeyFile = tempDir.resolve(pubKeyPath);
final CharSink pubKeySink = Files.asCharSink(pubKeyFile.toFile(), UTF_8);
pubKeySink.write(Base64.getEncoder().encodeToString(encodedPubKey));
final Path privKeyFile = tempDir.resolve(privKeyPath);
final CharSink privKeySink = Files.asCharSink(privKeyFile.toFile(), UTF_8);
privKeySink.write(Base64.getEncoder().encodeToString(encodedPrivKey));
return create(tempDir, pubKeyFile, privKeyFile, othernodes);
}
public static OrionTestHarness create(
final Path tempDir,
final String pubKeyPath,
final String privKeyPath,
final String... othernodes)
throws Exception {
throws IOException {
Path key1pub = copyResource(pubKeyPath, tempDir.resolve(pubKeyPath));
Path key1key = copyResource(privKeyPath, tempDir.resolve(privKeyPath));
return create(tempDir, key1pub, key1key, othernodes);
}
public static OrionTestHarness create(
final Path tempDir, final Path key1pub, final Path key1key, final String... othernodes) {
// @formatter:off
String confString =
"tls=\"off\"\n"