Replace KeystoreKeyring with KmsKeystore comparison

Replace KeystoreKeyring with ComparatorKeyring between KeystoreKeyring and
KmsKeystore. In the opensource version, will replace DummyKeyring with
KmsKeyring directly.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=152893767
This commit is contained in:
guyben 2017-04-11 19:38:14 -07:00 committed by Ben McIlwain
parent dea386d08a
commit ab515cb352
16 changed files with 94 additions and 36 deletions

View file

@ -21,6 +21,8 @@ import google.registry.util.ComparingInvocationHandler;
import google.registry.util.FormattingLogger;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Objects;
@ -43,7 +45,7 @@ import org.bouncycastle.openpgp.PGPPublicKey;
* <p>If both keyrings threw exceptions, there is no check whether the exeptions are the same. The
* assumption is that an error happened in both, but they might report that error differently.
*/
final class ComparatorKeyring extends ComparingInvocationHandler<Keyring> {
public final class ComparatorKeyring extends ComparingInvocationHandler<Keyring> {
@VisibleForTesting
static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
@ -98,6 +100,14 @@ final class ComparatorKeyring extends ComparingInvocationHandler<Keyring> {
return super.stringifyResult(method, a);
}
@Override
protected String stringifyThrown(Method method, Throwable throwable) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
throwable.printStackTrace(printWriter);
return String.format("%s\nStack trace:\n%s", throwable.toString(), stringWriter.toString());
}
// .equals implementation for PGP types.
@VisibleForTesting