Skip to content

Commit 052523e

Browse files
authored
Update googleapis with latest CheckError codes (#722)
1 parent a2379d8 commit 052523e

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

repositories.bzl

+3-5
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,6 @@ cc_proto_library(
511511
"google/api/log.proto",
512512
"google/api/logging.proto",
513513
"google/api/metric.proto",
514-
"google/api/experimental/experimental.proto",
515-
"google/api/experimental/authorization_config.proto",
516514
"google/api/monitored_resource.proto",
517515
"google/api/monitoring.proto",
518516
"google/api/resource.proto",
@@ -551,9 +549,9 @@ cc_proto_library(
551549
name = "googleapis_git",
552550
build_file_content = BUILD,
553551
patch_cmds = ["find . -type f -name '*BUILD*' | xargs rm"],
554-
strip_prefix = "googleapis-32a10f69e2c9ce15bba13ab1ff928bacebb25160", # May 20, 2019
555-
url = "https://github.com/googleapis/googleapis/archive/32a10f69e2c9ce15bba13ab1ff928bacebb25160.tar.gz",
556-
sha256 = "6861efa8619579e06e70dd4765cdf6cef1ecad6a1a2026ad750541e99552bf71",
552+
strip_prefix = "googleapis-ae7a4cc69cc1e206b16f1b9db803907d7a3d97c8", # Oct 22, 2019
553+
url = "https://github.com/googleapis/googleapis/archive/ae7a4cc69cc1e206b16f1b9db803907d7a3d97c8.tar.gz",
554+
sha256 = "f96e11515c302045e8ab6708ba68d7cea8a02e2a96add92033315ff894076980",
557555
)
558556

559557
if bind:

src/api_manager/service_control/check_response_test.cc

+34-4
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,49 @@ TEST(CheckResponseTest,
123123
EXPECT_EQ(Code::PERMISSION_DENIED, result.code());
124124
}
125125

126+
TEST(CheckResponseTest, WhenResponseIsBlockedWithSecurityPolicyViolated) {
127+
Status result =
128+
ConvertCheckErrorToStatus(CheckError::SECURITY_POLICY_VIOLATED);
129+
EXPECT_EQ(Code::PERMISSION_DENIED, result.code());
130+
}
131+
132+
TEST(CheckResponseTest, WhenResponseIsBlockedWithInvalidCredentail) {
133+
Status result = ConvertCheckErrorToStatus(CheckError::INVALID_CREDENTIAL);
134+
EXPECT_EQ(Code::PERMISSION_DENIED, result.code());
135+
}
136+
137+
TEST(CheckResponseTest, WhenResponseIsBlockedWithLocationPolicyViolated) {
138+
Status result =
139+
ConvertCheckErrorToStatus(CheckError::LOCATION_POLICY_VIOLATED);
140+
EXPECT_EQ(Code::PERMISSION_DENIED, result.code());
141+
}
142+
143+
TEST(CheckResponseTest, WhenResponseIsBlockedWithConsumerInvalid) {
144+
Status result = ConvertCheckErrorToStatus(CheckError::CONSUMER_INVALID);
145+
EXPECT_EQ(Code::PERMISSION_DENIED, result.code());
146+
}
147+
126148
TEST(CheckResponseTest, FailOpenWhenResponseIsUnknownNamespaceLookup) {
127149
EXPECT_TRUE(
128150
ConvertCheckErrorToStatus(CheckError::NAMESPACE_LOOKUP_UNAVAILABLE).ok());
129151
}
130152

131-
TEST(CheckResponseTest, FailOpenWhenResponseIsUnknownBillingStatus) {
153+
TEST(CheckResponseTest, UnavailableCheckErrorStatus) {
132154
EXPECT_TRUE(
133155
ConvertCheckErrorToStatus(CheckError::BILLING_STATUS_UNAVAILABLE).ok());
134-
}
135-
136-
TEST(CheckResponseTest, FailOpenWhenResponseIsUnknownServiceStatus) {
137156
EXPECT_TRUE(
138157
ConvertCheckErrorToStatus(CheckError::SERVICE_STATUS_UNAVAILABLE).ok());
158+
EXPECT_TRUE(
159+
ConvertCheckErrorToStatus(CheckError::QUOTA_CHECK_UNAVAILABLE).ok());
160+
EXPECT_TRUE(ConvertCheckErrorToStatus(
161+
CheckError::CLOUD_RESOURCE_MANAGER_BACKEND_UNAVAILABLE)
162+
.ok());
163+
EXPECT_TRUE(
164+
ConvertCheckErrorToStatus(CheckError::SECURITY_POLICY_BACKEND_UNAVAILABLE)
165+
.ok());
166+
EXPECT_TRUE(
167+
ConvertCheckErrorToStatus(CheckError::LOCATION_POLICY_BACKEND_UNAVAILABLE)
168+
.ok());
139169
}
140170

141171
} // namespace service_control

src/api_manager/service_control/proto.cc

+22
Original file line numberDiff line numberDiff line change
@@ -1470,9 +1470,31 @@ Status Proto::ConvertCheckResponse(const CheckResponse& check_response,
14701470
std::string("API ") + service_name +
14711471
" has billing disabled. Please enable it.",
14721472
Status::SERVICE_CONTROL);
1473+
case CheckError::SECURITY_POLICY_VIOLATED:
1474+
return Status(Code::PERMISSION_DENIED,
1475+
"Request is not allowed as per security policies.",
1476+
Status::SERVICE_CONTROL);
1477+
case CheckError::INVALID_CREDENTIAL:
1478+
return Status(Code::PERMISSION_DENIED,
1479+
"The credential in the request can not be verified",
1480+
Status::SERVICE_CONTROL);
1481+
case CheckError::LOCATION_POLICY_VIOLATED:
1482+
return Status(Code::PERMISSION_DENIED,
1483+
"Request is not allowed as per location policies.",
1484+
Status::SERVICE_CONTROL);
1485+
case CheckError::CONSUMER_INVALID:
1486+
return Status(Code::PERMISSION_DENIED,
1487+
"The consumer from the API key does not represent"
1488+
" a valid consumer folder or organization",
1489+
Status::SERVICE_CONTROL);
1490+
14731491
case CheckError::NAMESPACE_LOOKUP_UNAVAILABLE:
14741492
case CheckError::SERVICE_STATUS_UNAVAILABLE:
14751493
case CheckError::BILLING_STATUS_UNAVAILABLE:
1494+
case CheckError::QUOTA_CHECK_UNAVAILABLE:
1495+
case CheckError::CLOUD_RESOURCE_MANAGER_BACKEND_UNAVAILABLE:
1496+
case CheckError::SECURITY_POLICY_BACKEND_UNAVAILABLE:
1497+
case CheckError::LOCATION_POLICY_BACKEND_UNAVAILABLE:
14761498
// Fail open for internal server errors per recommendation
14771499
return Status::OK;
14781500
default:

0 commit comments

Comments
 (0)