Skip to content

Commit

Permalink
transfer CreateRole tests to ExecutorItf
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Boldyrev <miboldyrev@gmail.com>
  • Loading branch information
MBoldyrev committed Nov 16, 2019
1 parent 59e96bb commit ffb71f3
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 288 deletions.
6 changes: 0 additions & 6 deletions test/integration/acceptance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ target_link_libraries(create_domain_test
integration_framework
)

addtest(create_role_test create_role_test.cpp)
target_link_libraries(create_role_test
acceptance_fixture
integration_framework
)

addtest(get_transactions_test get_transactions_test.cpp)
target_link_libraries(get_transactions_test
acceptance_fixture
Expand Down
204 changes: 0 additions & 204 deletions test/integration/acceptance/create_role_test.cpp

This file was deleted.

7 changes: 7 additions & 0 deletions test/integration/executor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ target_link_libraries(create_account_test
executor_fixture_param_provider
)

addtest(create_role_test create_role_test.cpp)
target_link_libraries(create_role_test
command_permission_test
executor_fixture
executor_fixture_param_provider
)

addtest(get_account_assets_test get_account_assets_test.cpp)
target_link_libraries(get_account_assets_test
executor_fixture
Expand Down
118 changes: 118 additions & 0 deletions test/integration/executor/create_role_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#include "integration/executor/executor_fixture.hpp"

#include <gtest/gtest.h>
#include "common/result.hpp"
#include "framework/common_constants.hpp"
#include "integration/executor/command_permission_test.hpp"
#include "integration/executor/executor_fixture_param_provider.hpp"
#include "module/shared_model/mock_objects_factories/mock_command_factory.hpp"
#include "module/shared_model/mock_objects_factories/mock_query_factory.hpp"

using namespace common_constants;
using namespace executor_testing;
using namespace framework::expected;
using namespace shared_model::interface::types;

using shared_model::interface::permissions::Grantable;
using shared_model::interface::permissions::Role;

static const RoleIdType kAnotherRole("another_role");

class CreateRoleTest : public ExecutorTestBase {
public:
iroha::ametsuchi::CommandResult createRole(
const AccountIdType &issuer,
const shared_model::interface::RolePermissionSet &permissions,
bool validation_enabled = true) {
return getItf().executeCommandAsAccount(
*getItf().getMockCommandFactory()->constructCreateRole(kAnotherRole,
permissions),
issuer,
validation_enabled);
}

auto getRolePerms(const RoleIdType &role) {
return getItf().executeQueryAndConvertResult(
*getItf().getMockQueryFactory()->constructGetRolePermissions(role));
}

void checkRole(
const RoleIdType &role,
const shared_model::interface::RolePermissionSet &ref_permissions) {
getRolePerms(role).specific_response.match(
[&](const auto &test_permissions) {
EXPECT_EQ(test_permissions.value.rolePermissions(), ref_permissions)
<< "Wrong set of permissions for role " << role;
},
[](const auto &e) { ADD_FAILURE() << e.error->toString(); });
}

void checkNoSuchRole(const RoleIdType &role) {
assertResultError(getRolePerms(role).specific_response);
}
};

using CreateRoleBasicTest = BasicExecutorTest<CreateRoleTest>;

/**
* @given a user with all kCreateRole permission
* @when executes CreateRole command with empty permission set
* @then the command succeeds and the role is created
*/
TEST_P(CreateRoleBasicTest, ValidEmptyPerms) {
getItf().createUserWithPerms(
kUser, kDomain, kUserKeypair.publicKey(), {Role::kCreateRole});
assertResultValue(createRole(kUserId, {}));
checkRole(kAnotherRole, {});
}

/**
* @given a user with all related permissions
* @when executes CreateRole command with occupied name and other permissions
* @then the command does not succeed and the existing role is not changed
*/
TEST_P(CreateRoleBasicTest, NameExists) {
ASSERT_NO_FATAL_FAILURE({
getItf().createUserWithPerms(kUser,
kDomain,
kUserKeypair.publicKey(),
{Role::kCreateRole, Role::kCreateAsset});
assertResultValue(createRole(kUserId, {Role::kCreateRole}));
checkRole(kAnotherRole, {Role::kCreateRole});
});
checkCommandError(createRole(kUserId, {Role::kCreateAsset}), 3);
checkRole(kAnotherRole, {Role::kCreateRole});
}

INSTANTIATE_TEST_CASE_P(Base,
CreateRoleBasicTest,
executor_testing::getExecutorTestParams(),
executor_testing::paramToString);

using CreateRolePermissionTest =
command_permission_test::CommandPermissionTest<CreateRoleTest>;

TEST_P(CreateRolePermissionTest, CommandPermissionTest) {
ASSERT_NO_FATAL_FAILURE(getItf().createDomain(kSecondDomain));
ASSERT_NO_FATAL_FAILURE(prepareState({}, {Role::kCreateAsset}));

if (checkResponse(createRole(
getActor(), {Role::kCreateAsset}, getValidationEnabled()))) {
checkRole(kAnotherRole, {Role::kCreateAsset});
} else {
checkNoSuchRole(kAnotherRole);
}
}

INSTANTIATE_TEST_CASE_P(Common,
CreateRolePermissionTest,
command_permission_test::getParams(boost::none,
boost::none,
Role::kCreateRole,
boost::none),
command_permission_test::paramToString);

0 comments on commit ffb71f3

Please sign in to comment.