Skip to content

Commit

Permalink
squash. add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
korydraughn committed Jul 25, 2024
1 parent 0dbcd58 commit 20db9e7
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions unit_tests/src/test_client_connection.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//
// IMPORTANT: Some tests in this file require rodsadmin level privileges!
//

#include <catch2/catch.hpp>

#include "irods/client_connection.hpp"
Expand All @@ -7,8 +11,11 @@
#include "irods/irods_at_scope_exit.hpp"
#include "irods/rcConnect.h"
#include "irods/rodsClient.h"
#include "irods/rodsErrorTable.h"
#include "irods/user_administration.hpp"

#include <errno.h>

#include <algorithm>
#include <array>
#include <string_view>
Expand Down Expand Up @@ -300,3 +307,108 @@ TEST_CASE("#7192: all connections store unique session signatures", "client_conn

CHECK(std::all_of(std::begin(pairs), std::end(pairs), has_unique_session_signatures));
}

// NOLINTNEXTLINE(readability-function-cognitive-complexity)
TEST_CASE("#7155: report underlying error info from server on failed connection")
{
load_client_api_plugins();

rodsEnv env;
_getRodsEnv(env);

SECTION("invalid host")
{
try {
ix::client_connection{"example.org", env.rodsPort, {env.rodsUserName, env.rodsZone}};
}
catch (const irods::exception& e) {
CHECK(e.code() == USER_SOCK_CONNECT_TIMEDOUT);
CHECK_THAT(e.client_display_what(), Catch::Matchers::Contains("_rcConnect: connectToRhost failed"));
}
}

SECTION("invalid port")
{
try {
ix::client_connection{env.rodsHost, 8080, {env.rodsUserName, env.rodsZone}};
}
catch (const irods::exception& e) {
// Assertion fails with including the embedded errno value.
CHECK(e.code() == (USER_SOCK_CONNECT_ERR - ECONNREFUSED));
CHECK_THAT(e.client_display_what(), Catch::Matchers::Contains("_rcConnect: connectToRhost failed"));
}
}

SECTION("invalid username, not proxied")
{
try {
ix::client_connection{env.rodsHost, env.rodsPort, {"invalid", env.rodsZone}};
}
catch (const irods::exception& e) {
CHECK(e.code() == CAT_INVALID_USER);
CHECK_THAT(e.client_display_what(), Catch::Matchers::Contains("Client login error"));
}
}

SECTION("invalid user zone, not proxied")
{
try {
ix::client_connection{env.rodsHost, env.rodsPort, {env.rodsUserName, "invalid"}};
}
catch (const irods::exception& e) {
CHECK(e.code() == CAT_INVALID_USER);
CHECK_THAT(e.client_display_what(), Catch::Matchers::Contains("Client login error"));
}
}

SECTION("deferred connection with empty zone")
{
try {
ix::client_connection conn{ix::defer_connection};
conn.connect(env.rodsHost, env.rodsPort, {env.rodsUserName, ""});
}
catch (const irods::exception& e) {
CHECK(e.code() == SYS_INVALID_INPUT_PARAM);
CHECK_THAT(e.client_display_what(), Catch::Matchers::Contains("Empty zone not allowed"));
}
}

SECTION("proxy tests")
{
ix::client_connection admin_conn;

namespace ia = irods::experimental::administration;

const ia::user other_user{"other_user"};
REQUIRE_NOTHROW(ia::client::add_user(admin_conn, other_user, ia::user_type::rodsadmin));

irods::at_scope_exit remove_proxy_admin{
[&admin_conn, other_user] { ia::client::remove_user(admin_conn, other_user); }};

const auto password = std::to_array("rods");
const ia::user_password_property pwd_property{password.data()};
REQUIRE_NOTHROW(ia::client::modify_user(admin_conn, other_user, pwd_property));

SECTION("proxied user has empty zone name")
{
try {
ix::client_connection{env.rodsHost, env.rodsPort, {env.rodsUserName, env.rodsZone}, {other_user.name, ""}};
}
catch (const irods::exception& e) {
CHECK(e.code() == SYS_INVALID_INPUT_PARAM);
CHECK_THAT(e.client_display_what(), Catch::Matchers::Contains("Empty zone not allowed"));
}
}

SECTION("proxy user has empty zone name")
{
try {
ix::client_connection{env.rodsHost, env.rodsPort, {env.rodsUserName, ""}, {other_user.name, env.rodsZone}};
}
catch (const irods::exception& e) {
CHECK(e.code() == SYS_INVALID_INPUT_PARAM);
CHECK_THAT(e.client_display_what(), Catch::Matchers::Contains("Empty zone not allowed"));
}
}
}
}

0 comments on commit 20db9e7

Please sign in to comment.