Skip to content

Commit

Permalink
[FOLD] Address PR ValidatorKeys comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bachase committed Jul 5, 2017
1 parent d20650e commit 58bf7a5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/ripple/app/misc/ValidatorKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
//==============================================================================

#ifndef RIPPLE_APP_MISC_VALIDATOR_IDENTITY_H_INCLUDED
#define RIPPLE_APP_MISC_VALIDATOR_IDENTITY_H_INCLUDED
#ifndef RIPPLE_APP_MISC_VALIDATOR_KEYS_H_INCLUDED
#define RIPPLE_APP_MISC_VALIDATOR_KEYS_H_INCLUDED

#include <ripple/beast/utility/Journal.h>
#include <ripple/protocol/PublicKey.h>
Expand All @@ -30,7 +30,7 @@ namespace ripple {
class Config;

/** Validator keys and manifest as set in configuration file. Values will be
emtpy if not configured as a validator or not configured with a manifest.
empty if not configured as a validator or not configured with a manifest.
*/
class ValidatorKeys
{
Expand Down
11 changes: 10 additions & 1 deletion src/ripple/app/misc/impl/ValidatorKeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
namespace ripple {
ValidatorKeys::ValidatorKeys(Config const& config, beast::Journal j)
{
if (config.exists(SECTION_VALIDATOR_TOKEN) &&
config.exists(SECTION_VALIDATION_SEED))
{
configInvalid_ = true;
JLOG(j.fatal()) << "Cannot specify both [" SECTION_VALIDATION_SEED
"] and [" SECTION_VALIDATOR_TOKEN "]";
return;
}

if (config.exists(SECTION_VALIDATOR_TOKEN))
{
if (auto const token = ValidatorToken::make_ValidatorToken(
Expand All @@ -41,7 +50,7 @@ ValidatorKeys::ValidatorKeys(Config const& config, beast::Journal j)
{
configInvalid_ = true;
JLOG(j.fatal())
<< "Invalid entry in validator token configuration.";
<< "Invalid token specified in [" SECTION_VALIDATOR_TOKEN "]";
}
}
else if (config.exists(SECTION_VALIDATION_SEED))
Expand Down
14 changes: 9 additions & 5 deletions src/test/app/ValidatorKeys_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ class ValidatorKeys_test : public beast::unit_test::suite
Config c;
ValidatorKeys k{c, j};
BEAST_EXPECT(k.publicKey.size() == 0);
BEAST_EXPECT(k.secretKey.size() == 0);
BEAST_EXPECT(k.manifest.empty());
BEAST_EXPECT(!k.configInvalid());

}
{
// validation seed section -> empty manifest and valid seeds
Expand All @@ -104,6 +106,7 @@ class ValidatorKeys_test : public beast::unit_test::suite
ValidatorKeys k{c, j};
BEAST_EXPECT(k.configInvalid());
BEAST_EXPECT(k.publicKey.size() == 0);
BEAST_EXPECT(k.secretKey.size() == 0);
BEAST_EXPECT(k.manifest.empty());
}

Expand All @@ -125,20 +128,21 @@ class ValidatorKeys_test : public beast::unit_test::suite
ValidatorKeys k{c, j};
BEAST_EXPECT(k.configInvalid());
BEAST_EXPECT(k.publicKey.size() == 0);
BEAST_EXPECT(k.secretKey.size() == 0);
BEAST_EXPECT(k.manifest.empty());
}

{
// Token takes precedence over seed
// Cannot specify both
Config c;
c.section(SECTION_VALIDATION_SEED).append(seed);
c.section(SECTION_VALIDATOR_TOKEN).append(tokenBlob);
ValidatorKeys k{c, j};

BEAST_EXPECT(k.publicKey == tokenPublicKey);
BEAST_EXPECT(k.secretKey == tokenSecretKey);
BEAST_EXPECT(k.manifest == tokenManifest);
BEAST_EXPECT(!k.configInvalid());
BEAST_EXPECT(k.configInvalid());
BEAST_EXPECT(k.publicKey.size() == 0);
BEAST_EXPECT(k.secretKey.size() == 0);
BEAST_EXPECT(k.manifest.empty());
}

}
Expand Down

0 comments on commit 58bf7a5

Please sign in to comment.