Skip to content

Commit f099e3d

Browse files
authored
Document proto bytes field decoding with a test (#1509)
1 parent c971240 commit f099e3d

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

ydb/library/yaml_config/yaml_config_parser.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -943,10 +943,12 @@ namespace NKikimr::NYaml {
943943
return result;
944944
}
945945

946-
void Parse(const TString& data, NKikimrConfig::TAppConfig& config) {
946+
void Parse(const TString& data, NKikimrConfig::TAppConfig& config, bool needsTransforming) {
947947
auto yamlNode = YAML::Load(data);
948948
NJson::TJsonValue jsonNode = Yaml2Json(yamlNode, true);
949-
TransformConfig(jsonNode);
949+
if (needsTransforming) {
950+
TransformConfig(jsonNode);
951+
}
950952
NProtobufJson::MergeJson2Proto(jsonNode, config, GetJsonToProtoConfig());
951953
}
952954
}

ydb/library/yaml_config/yaml_config_parser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ namespace NKikimr::NYaml {
1919

2020
void TransformConfig(NJson::TJsonValue& config, bool relaxed = false);
2121

22-
void Parse(const TString& data, NKikimrConfig::TAppConfig& config);
22+
void Parse(const TString& data, NKikimrConfig::TAppConfig& config, bool needsTransforming = true);
2323
}

ydb/library/yaml_config/yaml_config_ut.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "yaml_config.h"
2+
#include "yaml_config_parser.h"
23

34
#include <library/cpp/testing/unittest/registar.h>
45

@@ -1767,4 +1768,24 @@ obj: {value: 2} # comment2
17671768
UNIT_ASSERT_VALUES_EQUAL(res, exp);
17681769
}
17691770
}
1771+
1772+
Y_UNIT_TEST(ProtoBytesFieldDoesNotDecodeBase64) {
1773+
// "c2FtcGxlLXBpbgo=" -> base64 decode -> "sample-pin"
1774+
TString config = R"(
1775+
pdisk_key_config:
1776+
keys:
1777+
- container_path: "/a/b/c"
1778+
pin: "c2FtcGxlLXBpbgo="
1779+
id: "sample-encryption-key"
1780+
version: 1
1781+
)";
1782+
NKikimrConfig::TAppConfig cfg;
1783+
NKikimr::NYaml::Parse(config, cfg, false);
1784+
1785+
UNIT_ASSERT(cfg.has_pdiskkeyconfig());
1786+
auto keys = cfg.pdiskkeyconfig().GetKeys();
1787+
UNIT_ASSERT_VALUES_EQUAL(keys.end() - keys.begin(), 1);
1788+
auto key = keys.at(0);
1789+
UNIT_ASSERT_VALUES_EQUAL("c2FtcGxlLXBpbgo=", key.pin());
1790+
}
17701791
}

0 commit comments

Comments
 (0)