Skip to content

Commit

Permalink
Adding agent-configuration tests and sorting out the authentication flow
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoblath committed Jun 6, 2024
1 parent b181343 commit eaf1ed4
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 19 deletions.
3 changes: 1 addition & 2 deletions examples/authentications.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"amqp": {
"broker": "rabbit-broker",
"dripline": {
"username": "dripline",
"password": "dripline"
}
Expand Down
6 changes: 2 additions & 4 deletions library/agent_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

#include "agent_config.hh"

#include "logger.hh"
//#include "logger.hh"

using std::string;

LOGGER( dlog, "agent_config" );
//LOGGER( dlog, "agent_config" );

namespace dripline
{
Expand Down
2 changes: 1 addition & 1 deletion library/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace dripline
core::core( const scarab::param_node& a_config, const scarab::authentication& a_auth, const bool a_make_connection ) :
f_address( a_config.get_value("broker", "localhost") ),
f_port( a_config.get_value("broker-port", 5672) ),
f_username( a_auth.get("dripline", "user", "guest") ),
f_username( a_auth.get("dripline", "username", "guest") ),
f_password( a_auth.get("dripline", "password", "guest") ),
f_requests_exchange( a_config.get_value("requests-exchange", "requests") ),
f_alerts_exchange( a_config.get_value("alerts-exchange", "alerts") ),
Expand Down
16 changes: 12 additions & 4 deletions library/dripline_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ LOGGER( dlog, "agent_config" );
namespace dripline
{

dripline_config::dripline_config( const std::string& a_auth_file )
dripline_config::dripline_config()
{
// default dripline configuration
add( "broker-port", 5672 );
Expand All @@ -45,7 +45,7 @@ namespace dripline
{
an_app.add_config_option< std::string >( "-b,--broker", "dripline.broker", "Set the dripline broker address" );
an_app.add_config_option< unsigned >( "-p,--port", "dripline.broker-port", "Set the port for communication with the dripline broker" );
an_app.add_config_option< std::string >( "--auth-file", "dripline.auth-file", "Set the authentication file path" );
an_app.add_config_option< std::string >( "--auth-file", "auth-file", "Set the authentication file path" );
an_app.add_config_option< std::string >( "--requests-exchange", "dripline.requests-exchange", "Set the name of the requests exchange" );
an_app.add_config_option< std::string >( "--alerts-exchange", "dripline.alerts-exchange", "Set the name of the alerts exchange" );
an_app.add_config_option< unsigned >( "--max-payload", "dripline.max-payload-size", "Set the maximum payload size (in bytes)" );
Expand All @@ -58,11 +58,19 @@ namespace dripline
return;
}

void add_dripline_auth_spec( scarab::main_app& an_app )
void add_dripline_auth_spec( scarab::main_app& an_app, bool a_use_auth_file )
{
// The use of an auth file is being maintained for backwards compatibility,
// but is not the preferred method of handling authentication
if( a_use_auth_file )
{
an_app.set_default_auth_file( "authentications.json" );
return;
}

an_app.add_default_auth_spec_group( "dripline",
scarab::param_node(
"user"_a=scarab::param_node(
"username"_a=scarab::param_node(
"default"_a="guest",
"env"_a="DRIPLINE_USER"
),
Expand Down
8 changes: 6 additions & 2 deletions library/dripline_config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ namespace dripline
class DRIPLINE_API dripline_config : public scarab::param_node
{
public:
dripline_config( const std::string& a_auth_file = "" );
dripline_config();
virtual ~dripline_config();
};

/// Add basic AMQP options to an app object
void add_dripline_options( scarab::main_app& an_app );

/// Add default authentication specification
void add_dripline_auth_spec( scarab::main_app& an_app );
/// This can either be done with an authentication specification group or with an auth file, as determined by the a_use_auth_file flag.
/// The use of an auth file is being maintained for backwards compatibility, but is not preferred.
/// For these defaults, it will either specify an auth file or an auth-spec group, but not both.
/// If an auth-spec group is the default, but the user provides an auth file, the latter will override the former.
void add_dripline_auth_spec( scarab::main_app& an_app, bool a_use_auth_file=false );

} /* namespace dripline */
#endif /* DRIPLINE_DRIPLINE_CONFIG_HH_ */
2 changes: 2 additions & 0 deletions testing/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ If you build the image, we recommend you tag the image with something like `ghcr

## The Tests

The next two sub-sections detail the tests that are run. Skip to [the next section](#run-the-tests) to actually run the tests.

### Broker Setup

The first tests run demonstrate that the RabbitMQ broker has been configured correctly once the services are connected. We check that the expected exchanges and queues are in place by sending HTTP requests to the broker and validating the responses. The `newman` CLI application is used to run a Postman collection.
Expand Down
3 changes: 1 addition & 2 deletions testing/integration/authentications.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"amqp": {
"broker": "rabbit-broker",
"dripline": {
"username": "dripline",
"password": "dripline"
},
Expand Down
2 changes: 0 additions & 2 deletions testing/integration/docker-compose-test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
test:
image: ghcr.io/driplineorg/dripline-cpp:${IMG_TAG:-latest-testing}
Expand Down
2 changes: 0 additions & 2 deletions testing/integration/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:

rabbit-broker:
Expand Down
39 changes: 39 additions & 0 deletions testing/test_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,48 @@
*/

#include "agent.hh"
#include "agent_config.hh"

#include "application.hh"

//#include "logger.hh"

#include "catch.hpp"

//LOGGER( talog, "test_agent" );

TEST_CASE( "agent_configuration", "[agent]" )
{
using Catch::Matchers::Equals;

// This setup should match what's done in dl_agent.cc

scarab::main_app the_main;
dripline::agent the_agent;

the_main.default_config() = dripline::agent_config();
// Dripline authentication specification
dripline::add_dripline_auth_spec( the_main );

// end setup

REQUIRE( the_main.default_config()["timeout"]().as_int() == 10 );
REQUIRE( the_main.default_config()["dripline"].is_node() );

REQUIRE( the_main.default_config().has("auth-groups") );
REQUIRE_THAT( the_main.default_config()["auth-groups"]["dripline"]["user"]["default"]().as_string(), Equals("guest") );
REQUIRE_THAT( the_main.default_config()["auth-groups"]["dripline"]["password"]["default"]().as_string(), Equals("guest") );

// pre_callback() runs the configuration stages and authentication step
the_main.pre_callback();

REQUIRE( the_main.primary_config()["timeout"]().as_int() == 10 );
REQUIRE( the_main.primary_config()["dripline"].is_node() );
REQUIRE( the_main.primary_config().has("auth-groups") );
REQUIRE_THAT( the_main.primary_config()["auth-groups"]["dripline"]["user"]["default"]().as_string(), Equals("guest") );
REQUIRE_THAT( the_main.primary_config()["auth-groups"]["dripline"]["password"]["default"]().as_string(), Equals("guest") );
}

TEST_CASE( "sub_agent_get", "[agent]" )
{
std::unique_ptr< dripline::agent > t_agent( new dripline::agent() );
Expand Down

0 comments on commit eaf1ed4

Please sign in to comment.