Exemplo n.º 1
0
TEST_F(RegistrarTest, readmit)
{
  Registrar registrar(state);
  AWAIT_READY(registrar.recover(MasterInfo()));

  SlaveInfo info1;
  info1.set_hostname("localhost");

  // Missing ID results in a failure.
  AWAIT_EXPECT_FAILED(registrar.readmit(info1));

  SlaveID id1;
  id1.set_value("1");
  info1.mutable_id()->CopyFrom(id1);

  SlaveID id2;
  id2.set_value("2");

  SlaveInfo info2;
  info2.set_hostname("localhost");
  info2.mutable_id()->CopyFrom(id2);

  AWAIT_EQ(true, registrar.admit(info1));

  AWAIT_EQ(true, registrar.readmit(info1));

  AWAIT_EQ(false, registrar.readmit(info2));
}
Exemplo n.º 2
0
// Bad password should return an authentication failure.
TEST(SASL, failed1)
{
  // Set up secrets.
  map<string, string> secrets;
  secrets["benh"] = "secret1";
  sasl::secrets::load(secrets);

  // Launch a dummy process (somebody to send the AuthenticateMessage).
  UPID pid = spawn(new ProcessBase(), true);

  Credential credential;
  credential.set_principal("benh");
  credential.set_secret("secret");

  Authenticatee authenticatee(credential, UPID());

  Future<Message> message =
    FUTURE_MESSAGE(Eq(AuthenticateMessage().GetTypeName()), _, _);

  Future<bool> client = authenticatee.authenticate(pid);

  AWAIT_READY(message);

  Authenticator authenticator(message.get().from);

  Future<bool> server = authenticator.authenticate();

  AWAIT_EQ(false, client);
  AWAIT_EQ(false, server);

  terminate(pid);
}
Exemplo n.º 3
0
TEST_F(RegistrarTest, admit)
{
  Registrar registrar(state);

  SlaveID id1;
  id1.set_value("1");

  SlaveInfo info1;
  info1.set_hostname("localhost");
  info1.mutable_id()->CopyFrom(id1);

  AWAIT_EQ(true, registrar.admit(id1, info1));
  AWAIT_EQ(false, registrar.admit(id1, info1));
}
// This test verifies that a missing secret fails the authenticatee.
TYPED_TEST(CRAMMD5Authentication, AuthenticateeSecretMissing)
{
  Credential credential;
  credential.set_principal("benh");

  Try<Authenticatee*> authenticatee = TypeParam::TypeAuthenticatee::create();
  CHECK_SOME(authenticatee);

  Future<bool> future =
    authenticatee.get()->authenticate(UPID(), UPID(), credential);

  AWAIT_EQ(false, future);

  delete authenticatee.get();
}
Exemplo n.º 5
0
TEST_F(RegistrarTest, recover)
{
  Registrar registrar(state);

  SlaveInfo slave;
  slave.set_hostname("localhost");
  SlaveID id;
  id.set_value("1");
  slave.mutable_id()->CopyFrom(id);

  // Operations preceding recovery will fail.
  AWAIT_EXPECT_FAILED(registrar.admit(slave));
  AWAIT_EXPECT_FAILED(registrar.readmit(slave));
  AWAIT_EXPECT_FAILED(registrar.remove(slave));

  MasterInfo info;
  info.set_id("foobar");
  info.set_ip(0);
  info.set_port(5050);
  info.set_pid("0:5050");

  Future<Registry> registry = registrar.recover(info);

  // Before waiting for the recovery to complete, invoke some
  // operations to ensure they do not fail.
  Future<bool> admit = registrar.admit(slave);
  Future<bool> readmit = registrar.readmit(slave);
  Future<bool> remove = registrar.remove(slave);

  AWAIT_READY(registry);
  EXPECT_EQ(info, registry.get().master().info());

  AWAIT_EQ(true, admit);
  AWAIT_EQ(true, readmit);
  AWAIT_EQ(true, remove);
}
TYPED_TEST(CRAMMD5Authentication, Success)
{
  // Launch a dummy process (somebody to send the AuthenticateMessage).
  UPID pid = spawn(new ProcessBase(), true);

  Credential credential1;
  credential1.set_principal("benh");
  credential1.set_secret("secret");

  Credentials credentials;
  Credential* credential2 = credentials.add_credentials();
  credential2->set_principal(credential1.principal());
  credential2->set_secret(credential1.secret());

  Future<Message> message =
    FUTURE_MESSAGE(Eq(AuthenticateMessage().GetTypeName()), _, _);

  Try<Authenticatee*> authenticatee = TypeParam::TypeAuthenticatee::create();
  CHECK_SOME(authenticatee);

  Future<bool> client =
    authenticatee.get()->authenticate(pid, UPID(), credential1);

  AWAIT_READY(message);

  Try<Authenticator*> authenticator = TypeParam::TypeAuthenticator::create();
  CHECK_SOME(authenticator);

  EXPECT_SOME(authenticator.get()->initialize(credentials));

  Future<Option<string>> principal =
    authenticator.get()->authenticate(message.get().from);

  AWAIT_EQ(true, client);
  AWAIT_READY(principal);
  EXPECT_SOME_EQ("benh", principal.get());

  terminate(pid);

  delete authenticator.get();
  delete authenticatee.get();
}