Skip to content

Commit

Permalink
add test with groups
Browse files Browse the repository at this point in the history
  • Loading branch information
kunga committed Dec 31, 2024
1 parent c063137 commit 14454da
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ydb/core/tx/schemeshard/ut_helpers/ls_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <ydb/core/scheme/scheme_tablecell.h>
#include <ydb/core/scheme/scheme_tabledefs.h>
#include <ydb/core/scheme/scheme_types_proto.h>
#include <ydb/library/login/protos/login.pb.h>
#include <ydb/public/lib/scheme_types/scheme_type_id.h>
#include <ydb/public/api/protos/ydb_cms.pb.h>
#include <ydb/core/protos/pqconfig.pb.h>
Expand Down Expand Up @@ -1243,6 +1244,22 @@ TCheckFunc HasOwner(const TString& owner) {
};
}

TCheckFunc HasGroup(const TString& group, const TSet<TString> members) {
return [=](const NKikimrScheme::TEvDescribeSchemeResult& record) {
std::optional<TSet<TString>> actualMembers;
for (const auto& sid : record.GetPathDescription().GetDomainDescription().GetSecurityState().GetSids()) {
if (sid.GetName() == group) {
actualMembers.emplace();
for (const auto& member : sid.GetMembers()) {
actualMembers->insert(member);
}
}
}
UNIT_ASSERT_C(actualMembers.has_value(), "Group " + group + " not found");
UNIT_ASSERT_VALUES_EQUAL(members, actualMembers.value());
};
}

void CheckRight(const NKikimrScheme::TEvDescribeSchemeResult& record, const TString& right, bool mustHave, bool isEffective) {
const auto& self = record.GetPathDescription().GetSelf();
TSecurityObject src(self.GetOwner(), isEffective ? self.GetEffectiveACL() : self.GetACL(), false);
Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/schemeshard/ut_helpers/ls_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ namespace NLs {
void NoBackupInFly(const NKikimrScheme::TEvDescribeSchemeResult& record);
TCheckFunc BackupHistoryCount(ui64 count);

TCheckFunc HasGroup(const TString& group, const TSet<TString> members);
TCheckFunc HasOwner(const TString& owner);
TCheckFunc HasRight(const TString& right);
TCheckFunc HasNoRight(const TString& right);
Expand Down
27 changes: 27 additions & 0 deletions ydb/core/tx/schemeshard/ut_login/ut_login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,33 @@ Y_UNIT_TEST_SUITE(TSchemeShardLoginTest) {
}
}

Y_UNIT_TEST(RemoveLogin_Groups) {
TTestBasicRuntime runtime;
TTestEnv env(runtime);
ui64 txId = 100;
CreateAlterLoginCreateUser(runtime, ++txId, "/MyRoot", "user1", "password1");
CreateAlterLoginCreateUser(runtime, ++txId, "/MyRoot", "user2", "password2");
auto resultLogin = Login(runtime, "user1", "password1");
UNIT_ASSERT_VALUES_EQUAL(resultLogin.error(), "");

CreateAlterLoginCreateGroup(runtime, ++txId, "/MyRoot", "group");
AlterLoginAddGroupMembership(runtime, ++txId, "/MyRoot", "user1", "group");
AlterLoginAddGroupMembership(runtime, ++txId, "/MyRoot", "user2", "group");

TestDescribeResult(DescribePath(runtime, "/MyRoot"),
{NLs::HasGroup("group", {"user1", "user2"})});

CreateAlterLoginRemoveUser(runtime, ++txId, "/MyRoot", "user1");

// check user has been removed:
{
TestDescribeResult(DescribePath(runtime, "/MyRoot"),
{NLs::HasGroup("group", {"user2"})});
auto resultLogin = Login(runtime, "user1", "password1");
UNIT_ASSERT_VALUES_EQUAL(resultLogin.GetError(), "Cannot find user: user1");
}
}

Y_UNIT_TEST(RemoveLogin_Owner) {
TTestBasicRuntime runtime;
TTestEnv env(runtime);
Expand Down

0 comments on commit 14454da

Please sign in to comment.