Repository: mesos Updated Branches: refs/heads/master 58da2a86e -> a62dc9dd3
Fixed ~Authenticator() to discard the promise. Review: https://reviews.apache.org/r/26389 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a62dc9dd Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a62dc9dd Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a62dc9dd Branch: refs/heads/master Commit: a62dc9dd3900758f1ac4932856227fe3707325de Parents: 58da2a8 Author: Vinod Kone <[email protected]> Authored: Sat Oct 4 15:16:18 2014 -0700 Committer: Vinod Kone <[email protected]> Committed: Mon Oct 6 18:24:30 2014 -0700 ---------------------------------------------------------------------- src/sasl/authenticatee.hpp | 5 ++++ src/sasl/authenticator.hpp | 5 ++++ src/tests/sasl_tests.cpp | 57 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/a62dc9dd/src/sasl/authenticatee.hpp ---------------------------------------------------------------------- diff --git a/src/sasl/authenticatee.hpp b/src/sasl/authenticatee.hpp index dd68704..ec2c841 100644 --- a/src/sasl/authenticatee.hpp +++ b/src/sasl/authenticatee.hpp @@ -95,6 +95,11 @@ public: free(secret); } + virtual void finalize() + { + discarded(); // Fail the promise. + } + process::Future<bool> authenticate(const process::UPID& pid) { static process::Once* initialize = new process::Once(); http://git-wip-us.apache.org/repos/asf/mesos/blob/a62dc9dd/src/sasl/authenticator.hpp ---------------------------------------------------------------------- diff --git a/src/sasl/authenticator.hpp b/src/sasl/authenticator.hpp index 35ab794..a3ae2a5 100644 --- a/src/sasl/authenticator.hpp +++ b/src/sasl/authenticator.hpp @@ -85,6 +85,11 @@ public: } } + virtual void finalize() + { + discarded(); // Fail the promise. + } + process::Future<Option<std::string> > authenticate() { static process::Once* initialize = new process::Once(); http://git-wip-us.apache.org/repos/asf/mesos/blob/a62dc9dd/src/tests/sasl_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/sasl_tests.cpp b/src/tests/sasl_tests.cpp index 59e1c95..30556fa 100644 --- a/src/tests/sasl_tests.cpp +++ b/src/tests/sasl_tests.cpp @@ -29,6 +29,10 @@ #include "sasl/authenticatee.hpp" #include "sasl/authenticator.hpp" +#include "tests/mesos.hpp" + +using namespace mesos::internal::tests; + using namespace process; using std::map; @@ -147,6 +151,59 @@ TEST(SASL, failed2) terminate(pid); } + +// This test verifies that the pending future returned by +// 'Authenticator::authenticate()' is properly failed when the Authenticator is +// destructed in the middle of authentication. +TEST(SASL, AuthenticatorDestructionRace) +{ + // Set up secrets. + map<string, string> secrets; + secrets["benh"] = "secret"; + 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 = new Authenticator(message.get().from); + + // Drop the AuthenticationStepMessage from authenticator to keep + // the authentication from getting completed. + Future<AuthenticationStepMessage> authenticationStepMessage = + DROP_PROTOBUF(AuthenticationStepMessage(), _, _); + + Future<Option<string> > principal = authenticator->authenticate(); + + AWAIT_READY(authenticationStepMessage); + + // At this point 'AuthenticatorProcess::authenticate()' has been + // executed and its promise associated with the promise returned + // by 'Authenticator::authenticate()'. + // Authentication should be pending. + ASSERT_TRUE(principal.isPending()); + + // Now delete the authenticator. + delete authenticator; + + // The future should be failed at this point. + AWAIT_FAILED(principal); + + terminate(pid); +} + } // namespace sasl { } // namespace internal { } // namespace mesos {
