forked from ydb-platform/ydb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fstec: Add rules for password strength (ydb-platform#11963)
Co-authored-by: azevaykin <[email protected]>
- Loading branch information
1 parent
961df40
commit e838a62
Showing
21 changed files
with
823 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <ydb/core/protos/auth.pb.h> | ||
#include <vector> | ||
#include <util/generic/string.h> | ||
#include "validators.h" | ||
|
||
|
||
namespace NKikimr::NConfig { | ||
namespace { | ||
|
||
EValidationResult ValidatePasswordComplexity(const NKikimrProto::TPasswordComplexity& passwordComplexity, std::vector<TString>&msg) { | ||
size_t minCountOfRequiredChars = passwordComplexity.GetMinLowerCaseCount() + | ||
passwordComplexity.GetMinUpperCaseCount() + | ||
passwordComplexity.GetMinNumbersCount() + | ||
passwordComplexity.GetMinSpecialCharsCount(); | ||
if (passwordComplexity.GetMinLength() < minCountOfRequiredChars) { | ||
msg = std::vector<TString>{"password_complexity: Min length of password cannot be less than " | ||
"total min counts of lower case chars, upper case chars, numbers and special chars"}; | ||
return EValidationResult::Error; | ||
} | ||
return EValidationResult::Ok; | ||
} | ||
|
||
} // namespace | ||
|
||
EValidationResult ValidateAuthConfig(const NKikimrProto::TAuthConfig& authConfig, std::vector<TString>& msg) { | ||
EValidationResult validatePasswordComplexityResult = ValidatePasswordComplexity(authConfig.GetPasswordComplexity(), msg); | ||
if (validatePasswordComplexityResult == EValidationResult::Error) { | ||
return EValidationResult::Error; | ||
} | ||
if (msg.size() > 0) { | ||
return EValidationResult::Warn; | ||
} | ||
return EValidationResult::Ok; | ||
} | ||
|
||
} // NKikimr::NConfig |
43 changes: 43 additions & 0 deletions
43
ydb/core/config/validation/auth_config_validator_ut/auth_config_validator_ut.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <library/cpp/testing/unittest/registar.h> | ||
#include <ydb/core/config/validation/validators.h> | ||
#include <ydb/core/protos/auth.pb.h> | ||
#include <vector> | ||
|
||
using namespace NKikimr::NConfig; | ||
|
||
Y_UNIT_TEST_SUITE(AuthConfigValidation) { | ||
Y_UNIT_TEST(AcceptValidPasswordComplexity) { | ||
NKikimrProto::TAuthConfig authConfig; | ||
NKikimrProto::TPasswordComplexity* validPasswordComplexity = authConfig.MutablePasswordComplexity(); | ||
|
||
validPasswordComplexity->SetMinLength(8); | ||
validPasswordComplexity->SetMinLowerCaseCount(2); | ||
validPasswordComplexity->SetMinUpperCaseCount(2); | ||
validPasswordComplexity->SetMinNumbersCount(2); | ||
validPasswordComplexity->SetMinSpecialCharsCount(2); | ||
|
||
std::vector<TString> error; | ||
EValidationResult result = ValidateAuthConfig(authConfig, error); | ||
UNIT_ASSERT_EQUAL(result, EValidationResult::Ok); | ||
UNIT_ASSERT_C(error.empty(), "Should not be errors"); | ||
} | ||
|
||
Y_UNIT_TEST(CannotAcceptInvalidPasswordComplexity) { | ||
NKikimrProto::TAuthConfig authConfig; | ||
NKikimrProto::TPasswordComplexity* invalidPasswordComplexity = authConfig.MutablePasswordComplexity(); | ||
|
||
// 8 < 2 + 2 + 2 + 3 | ||
invalidPasswordComplexity->SetMinLength(8); | ||
invalidPasswordComplexity->SetMinLowerCaseCount(2); | ||
invalidPasswordComplexity->SetMinUpperCaseCount(2); | ||
invalidPasswordComplexity->SetMinNumbersCount(2); | ||
invalidPasswordComplexity->SetMinSpecialCharsCount(3); | ||
|
||
std::vector<TString> error; | ||
EValidationResult result = ValidateAuthConfig(authConfig, error); | ||
UNIT_ASSERT_EQUAL(result, EValidationResult::Error); | ||
UNIT_ASSERT_VALUES_EQUAL(error.size(), 1); | ||
UNIT_ASSERT_STRINGS_EQUAL(error.front(), "password_complexity: Min length of password cannot be less than " | ||
"total min counts of lower case chars, upper case chars, numbers and special chars"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
UNITTEST_FOR(ydb/core/config/validation) | ||
|
||
SRC( | ||
auth_config_validator_ut.cpp | ||
) | ||
|
||
YQL_LAST_ABI_VERSION() | ||
|
||
END() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.