Skip to content

Commit dce3c95

Browse files
martinzinkcoryan
andauthored
fix(storage): json["projectTeam"] might be present but null (#8446)
Co-authored-by: Carlos O'Ryan <[email protected]>
1 parent 00a12bb commit dce3c95

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

google/cloud/storage/internal/access_control_common_parser.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Status AccessControlCommonParser::FromJson(AccessControlCommon& result,
3636
result.self_link_ = json.value("selfLink", "");
3737
if (json.count("projectTeam") != 0) {
3838
auto tmp = json["projectTeam"];
39+
if (tmp.is_null()) return Status{};
3940
ProjectTeam p;
4041
p.project_number = tmp.value("projectNumber", "");
4142
p.team = tmp.value("team", "");

google/cloud/storage/internal/access_control_common_parser_test.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ TEST(AccessControlCommonParserTest, FromJson) {
3737
EXPECT_THAT(result.bucket(), Eq(bucket));
3838
EXPECT_THAT(result.role(), Eq(role));
3939
EXPECT_THAT(result.email(), Eq(email));
40+
EXPECT_FALSE(result.has_project_team());
41+
}
42+
43+
TEST(AccessControlCommonParserTest, NullProjectTeamIsValid) {
44+
nlohmann::json metadata{{"projectTeam", nullptr}};
45+
internal::AccessControlCommon result{};
46+
auto status = internal::AccessControlCommonParser::FromJson(result, metadata);
47+
ASSERT_STATUS_OK(status);
48+
49+
EXPECT_FALSE(result.has_project_team());
4050
}
4151

4252
} // namespace

0 commit comments

Comments
 (0)