// Copyright (c) 2005-2007 Andre Merzky (andre@merzky.net) // Copyright (c) 2005-2007 Hartmut Kaiser (hartmut.kaiser@gmail.com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include "test_attribute.hpp" /////////////////////////////////////////////////////////////////////////////// namespace test_context { ///////////////////////////////////////////////////////////////////////////// class context_tests { private: saga::session s; protected: void check_context_is_in_list(saga::context const& c) { std::list const &ctxs = s.list_contexts(); std::list ::const_iterator it = std::find(ctxs.begin(), ctxs.end(), c); BOOST_CHECK (it != ctxs.end() && *it == c); } void check_context_is_not_in_list(saga::context const& c) { std::list const &ctxs = s.list_contexts(); std::list ::const_iterator it = std::find(ctxs.begin(), ctxs.end(), c); BOOST_CHECK (it == ctxs.end()); } void check_type (saga::context const& c, saga::context::type t) { BOOST_CHECK_EQUAL (c.get_ctype (), t); } public: // FIXME: check for correct default values void UserPass (void) { using namespace saga; saga::context c (saga::context::UserPass); check_type (c, saga::context::UserPass); test_attributes::check_attrib_invalid (c, attributes::context_server); test_attributes::check_attrib (c, attributes::context_user_name, "anonymous", true); test_attributes::check_attrib (c, attributes::context_user_pass, "anon", true); test_attributes::check_attrib_invalid (c, attributes::context_user_cert); test_attributes::check_attrib_invalid (c, attributes::context_cert_dir); test_attributes::check_attrib_invalid (c, attributes::context_user_proxy); test_attributes::check_ro_attrib (c, attributes::context_remote_host, ""); test_attributes::check_ro_attrib (c, attributes::context_remote_id, ""); test_attributes::check_ro_attrib (c, attributes::context_remote_port, ""); s.add_context (c); check_context_is_in_list(c); s.remove_context (c); check_context_is_not_in_list(c); } void MyProxy (void) { using namespace saga; saga::context c (saga::context::MyProxy); check_type (c, saga::context::MyProxy); test_attributes::check_attrib (c, attributes::context_server, "localhost", true); test_attributes::check_attrib (c, attributes::context_user_proxy, std::string("/tmp/x509up_u") + boost::lexical_cast(getpid()), true); test_attributes::check_attrib (c, attributes::context_user_cert, "$HOME/.globus/usercert.pem", true); test_attributes::check_attrib_invalid (c, attributes::context_user_name); test_attributes::check_attrib (c, attributes::context_user_key, "$HOME/.globus/userkey.pem", true); test_attributes::check_attrib (c, attributes::context_user_pass, "", true); test_attributes::check_attrib (c, attributes::context_cert_dir, "/etc/grid-security/certificates/", true); test_attributes::check_ro_attrib (c, attributes::context_remote_host, ""); test_attributes::check_ro_attrib (c, attributes::context_remote_id, ""); test_attributes::check_ro_attrib (c, attributes::context_remote_port, ""); s.add_context (c); check_context_is_in_list(c); s.remove_context (c); check_context_is_not_in_list(c); } void X509 (void) { using namespace saga; saga::context c (saga::context::X509); check_type (c, saga::context::X509); test_attributes::check_attrib_invalid (c, attributes::context_server); test_attributes::check_attrib (c, attributes::context_user_proxy, std::string("/tmp/x509up_u") + boost::lexical_cast(getpid()), true); test_attributes::check_attrib (c, attributes::context_user_cert, "$HOME/.globus/usercert.pem", true); test_attributes::check_attrib (c, attributes::context_user_key, "$HOME/.globus/userkey.pem", true); test_attributes::check_attrib (c, attributes::context_user_pass, "", true); test_attributes::check_attrib (c, attributes::context_cert_dir, "/etc/grid-security/certificates/", true); test_attributes::check_attrib_invalid (c, attributes::context_user_name); test_attributes::check_ro_attrib (c, attributes::context_remote_host, ""); test_attributes::check_ro_attrib (c, attributes::context_remote_id, ""); test_attributes::check_ro_attrib (c, attributes::context_remote_port, ""); s.add_context (c); check_context_is_in_list(c); s.remove_context (c); check_context_is_not_in_list(c); } void Unicore (void) { using namespace saga; saga::context c (saga::context::Unicore); check_type (c, saga::context::Unicore); test_attributes::check_attrib_invalid (c, attributes::context_server); test_attributes::check_attrib_invalid (c, attributes::context_user_name); test_attributes::check_attrib_invalid (c, attributes::context_user_proxy); test_attributes::check_attrib (c, attributes::context_user_cert, "$HOME/.keystore", true); test_attributes::check_attrib (c, attributes::context_user_pass, "anon", true); test_attributes::check_attrib_invalid (c, attributes::context_user_key); test_attributes::check_attrib_invalid (c, attributes::context_cert_dir); test_attributes::check_ro_attrib (c, attributes::context_remote_host, ""); test_attributes::check_ro_attrib (c, attributes::context_remote_id, ""); test_attributes::check_ro_attrib (c, attributes::context_remote_port, ""); s.add_context (c); check_context_is_in_list(c); s.remove_context (c); check_context_is_not_in_list(c); } void SAML (void) { using namespace saga; saga::context c (saga::context::SAML); check_type (c, saga::context::SAML); test_attributes::check_attrib_invalid (c, attributes::context_server); test_attributes::check_attrib (c, attributes::context_user_name, "", true); test_attributes::check_attrib_invalid (c, attributes::context_user_proxy); test_attributes::check_attrib_invalid (c, attributes::context_user_cert); test_attributes::check_attrib (c, attributes::context_user_pass, "", true); test_attributes::check_attrib_invalid (c, attributes::context_user_key); test_attributes::check_attrib_invalid (c, attributes::context_cert_dir); test_attributes::check_ro_attrib (c, attributes::context_remote_host, ""); test_attributes::check_ro_attrib (c, attributes::context_remote_id, ""); test_attributes::check_ro_attrib (c, attributes::context_remote_port, ""); s.add_context (c); check_context_is_in_list(c); s.remove_context (c); check_context_is_not_in_list(c); } void SSH (void) { using namespace saga; saga::context c (saga::context::SSH); check_type (c, saga::context::SSH); test_attributes::check_attrib_invalid (c, attributes::context_server); test_attributes::check_attrib_invalid (c, attributes::context_user_name); test_attributes::check_attrib_invalid (c, attributes::context_user_proxy); test_attributes::check_attrib (c, attributes::context_user_cert, "$HOME/.ssh/id_dsa.pub", true); test_attributes::check_attrib (c, attributes::context_user_pass, "$HOME/.ssh/id_dsa", true); test_attributes::check_attrib_invalid (c, attributes::context_user_key); test_attributes::check_attrib (c, attributes::context_cert_dir, "$HOME/.ssh/", true); test_attributes::check_ro_attrib (c, attributes::context_remote_host, ""); test_attributes::check_ro_attrib (c, attributes::context_remote_id, ""); test_attributes::check_ro_attrib (c, attributes::context_remote_port, ""); s.add_context (c); check_context_is_in_list(c); s.remove_context (c); check_context_is_not_in_list(c); } void Kerberos (void) { using namespace saga; saga::context c (saga::context::Kerberos); check_type (c, saga::context::Kerberos); test_attributes::check_attrib (c, attributes::context_server, "localhost", true); test_attributes::check_attrib (c, attributes::context_user_name, "", true); test_attributes::check_attrib_invalid (c, attributes::context_user_proxy); test_attributes::check_attrib_invalid (c, attributes::context_user_cert); test_attributes::check_attrib (c, attributes::context_user_pass, "", true); test_attributes::check_attrib_invalid (c, attributes::context_user_key); test_attributes::check_attrib_invalid (c, attributes::context_cert_dir); test_attributes::check_ro_attrib (c, attributes::context_remote_host, ""); test_attributes::check_ro_attrib (c, attributes::context_remote_id, ""); test_attributes::check_ro_attrib (c, attributes::context_remote_port, ""); s.add_context (c); check_context_is_in_list(c); s.remove_context (c); } }; class suite : public test_suite { public: suite () : test_suite ("context test suite") { TR1::shared_ptr t(new context_tests); add (BOOST_CLASS_TEST_CASE ( & context_tests::UserPass, t ) ); add (BOOST_CLASS_TEST_CASE ( & context_tests::MyProxy, t ) ); add (BOOST_CLASS_TEST_CASE ( & context_tests::X509, t ) ); add (BOOST_CLASS_TEST_CASE ( & context_tests::Unicore, t ) ); add (BOOST_CLASS_TEST_CASE ( & context_tests::SAML, t ) ); add (BOOST_CLASS_TEST_CASE ( & context_tests::SSH, t ) ); add (BOOST_CLASS_TEST_CASE ( & context_tests::Kerberos, t ) ); } }; }