-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update the auth check to use service.experimental.authorization.provider #67
Changes from 1 commit
2da31e2
598d1b1
1e3a82d
478ae1d
0eee367
93ed1cc
b8ca462
1fd53e0
bdfe1fc
05df900
2e55ff7
519b540
d33154d
0d78984
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,17 +58,17 @@ TEST(Config, CreateFromBinaryProto) { | |
} | ||
|
||
static const char kServerConfig[] = R"( | ||
service_control_config { | ||
check_aggregator_config { | ||
cache_entries: 1000 | ||
flush_interval_ms: 10 | ||
response_expiration_ms: 20 | ||
service_control_config { | ||
check_aggregator_config { | ||
cache_entries: 1000 | ||
flush_interval_ms: 10 | ||
response_expiration_ms: 20 | ||
} | ||
report_aggregator_config { | ||
cache_entries: 1020 | ||
flush_interval_ms: 15 | ||
} | ||
} | ||
report_aggregator_config { | ||
cache_entries: 1020 | ||
flush_interval_ms: 15 | ||
} | ||
} | ||
)"; | ||
|
||
const char kServiceNameConfig[] = "name: \"service-one\"\n"; | ||
|
@@ -93,13 +93,13 @@ TEST(Config, ServerConfigProto) { | |
} | ||
|
||
static const char kInvalidServerConfig[] = R"( | ||
service_control_config { | ||
type: 1 | ||
config { | ||
cache_entries: 1020 | ||
flush_interval_ms: 15 | ||
service_control_config { | ||
type: 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did this need any changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To follow google's dev guide: https://screenshot.googleplex.com/eLDuLGnpUNd There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, the dev guide only shows the advantage of using raw strings. There is no rules on indentation and here is why: various parsers can treat whitespaces differently. Some may ignore them and some might use them as delimiters. Here is a hint about this in the document: Here is the document link: https://g3doc.corp.google.com/devtools/library_club/g3doc/totw/64.md?cl=head There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The safest thing is to not have any leading or trailing white spaces. That way the strings will work with all parsers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually the raw string style is kinda new to me. And I realized the style even in this file is inconsistent. So I did some search at istio/proxy repo and google3 (https://cs.corp.google.com/search/?q=%22R%5C%22(%22+lang:cc+case:yes) and tried to follow what most people did. I just kept the existing style as it is. No big deal :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose that is because most of google code uses protobufs and they work well with whitespaces. |
||
config { | ||
cache_entries: 1020 | ||
flush_interval_ms: 15 | ||
} | ||
} | ||
} | ||
)"; | ||
|
||
TEST(Config, InvalidServerConfigProto) { | ||
|
@@ -501,35 +501,34 @@ TEST(Config, LoadBackends) { | |
TEST(Config, RpcMethodsWithHttpRules) { | ||
MockApiManagerEnvironmentWithLog env; | ||
|
||
const char config_text[] = | ||
R"( | ||
name : "BookstoreApi" | ||
apis { | ||
name: "Bookstore" | ||
methods { | ||
name: "ListShelves" | ||
request_type_url: "types.googleapis.com/google.protobuf.Empty" | ||
response_type_url: "types.googleapis.com/Bookstore.ListShelvesResponse" | ||
} | ||
methods { | ||
name: "CreateShelves" | ||
request_streaming: true | ||
request_type_url: "types.googleapis.com/Bookstore.Shelf" | ||
response_streaming: true | ||
response_type_url: "types.googleapis.com/Bookstore.Shelf" | ||
} | ||
const char config_text[] = R"( | ||
name : "BookstoreApi" | ||
apis { | ||
name: "Bookstore" | ||
methods { | ||
name: "ListShelves" | ||
request_type_url: "types.googleapis.com/google.protobuf.Empty" | ||
response_type_url: "types.googleapis.com/Bookstore.ListShelvesResponse" | ||
} | ||
http { | ||
rules { | ||
selector: "Bookstore.ListShelves" | ||
get: "/shelves" | ||
} | ||
rules { | ||
selector: "Bookstore.CreateShelves" | ||
post: "/shelves" | ||
} | ||
methods { | ||
name: "CreateShelves" | ||
request_streaming: true | ||
request_type_url: "types.googleapis.com/Bookstore.Shelf" | ||
response_streaming: true | ||
response_type_url: "types.googleapis.com/Bookstore.Shelf" | ||
} | ||
)"; | ||
} | ||
http { | ||
rules { | ||
selector: "Bookstore.ListShelves" | ||
get: "/shelves" | ||
} | ||
rules { | ||
selector: "Bookstore.CreateShelves" | ||
post: "/shelves" | ||
} | ||
} | ||
)"; | ||
|
||
std::unique_ptr<Config> config = Config::Create(&env, config_text, ""); | ||
ASSERT_TRUE(config); | ||
|
@@ -751,41 +750,41 @@ TEST(Config, TestHttpOptions) { | |
MockApiManagerEnvironmentWithLog env; | ||
|
||
static const char config_text[] = R"( | ||
name: "Service.Name" | ||
endpoints { | ||
name: "Service.Name" | ||
allow_cors: true | ||
} | ||
http { | ||
rules { | ||
selector: "ListShelves" | ||
get: "/shelves" | ||
} | ||
rules { | ||
selector: "CorsShelves" | ||
custom: { | ||
kind: "OPTIONS" | ||
path: "/shelves" | ||
} | ||
} | ||
rules { | ||
selector: "CreateShelf" | ||
post: "/shelves" | ||
} | ||
rules { | ||
selector: "GetShelf" | ||
get: "/shelves/{shelf}" | ||
} | ||
rules { | ||
selector: "DeleteShelf" | ||
delete: "/shelves/{shelf}" | ||
} | ||
rules { | ||
selector: "GetShelfBook" | ||
get: "/shelves/{shelf}/books" | ||
} | ||
} | ||
)"; | ||
name: "Service.Name" | ||
endpoints { | ||
name: "Service.Name" | ||
allow_cors: true | ||
} | ||
http { | ||
rules { | ||
selector: "ListShelves" | ||
get: "/shelves" | ||
} | ||
rules { | ||
selector: "CorsShelves" | ||
custom: { | ||
kind: "OPTIONS" | ||
path: "/shelves" | ||
} | ||
} | ||
rules { | ||
selector: "CreateShelf" | ||
post: "/shelves" | ||
} | ||
rules { | ||
selector: "GetShelf" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert the added spaces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The document does not say anything about required indentation. Please read my previous comment. |
||
get: "/shelves/{shelf}" | ||
} | ||
rules { | ||
selector: "DeleteShelf" | ||
delete: "/shelves/{shelf}" | ||
} | ||
rules { | ||
selector: "GetShelfBook" | ||
get: "/shelves/{shelf}/books" | ||
} | ||
} | ||
)"; | ||
|
||
std::unique_ptr<Config> config = Config::Create(&env, config_text, ""); | ||
ASSERT_TRUE(config); | ||
|
@@ -818,22 +817,22 @@ TEST(Config, TestHttpOptionsSelector) { | |
MockApiManagerEnvironmentWithLog env; | ||
|
||
static const char config_text[] = R"( | ||
name: "Service.Name" | ||
endpoints { | ||
name: "Service.Name" | ||
allow_cors: true | ||
} | ||
http { | ||
rules { | ||
selector: "CORS" | ||
get: "/shelves" | ||
} | ||
rules { | ||
selector: "CORS.1" | ||
get: "/shelves/{shelf}" | ||
} | ||
} | ||
)"; | ||
name: "Service.Name" | ||
endpoints { | ||
name: "Service.Name" | ||
allow_cors: true | ||
} | ||
http { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert the added spaces. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
rules { | ||
selector: "CORS" | ||
get: "/shelves" | ||
} | ||
rules { | ||
selector: "CORS.1" | ||
get: "/shelves/{shelf}" | ||
} | ||
} | ||
)"; | ||
|
||
std::unique_ptr<Config> config = Config::Create(&env, config_text, ""); | ||
ASSERT_TRUE(config); | ||
|
@@ -850,18 +849,18 @@ TEST(Config, TestCorsDisabled) { | |
MockApiManagerEnvironmentWithLog env; | ||
|
||
static const char config_text[] = R"( | ||
name: "Service.Name" | ||
http { | ||
rules { | ||
selector: "CORS" | ||
get: "/shelves" | ||
} | ||
rules { | ||
selector: "CORS.1" | ||
get: "/shelves/{shelf}" | ||
} | ||
} | ||
)"; | ||
name: "Service.Name" | ||
http { | ||
rules { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you are changing text by just adding spaces. This was done is many places elsewhere. Can you fix this? It is polluting the actual changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The style is recommended by Google dev guide There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see any such recommendation. It is only an example of a string that can be converted to a proto. |
||
selector: "CORS" | ||
get: "/shelves" | ||
} | ||
rules { | ||
selector: "CORS.1" | ||
get: "/shelves/{shelf}" | ||
} | ||
} | ||
)"; | ||
|
||
std::unique_ptr<Config> config = Config::Create(&env, config_text, ""); | ||
ASSERT_TRUE(config); | ||
|
@@ -870,44 +869,77 @@ TEST(Config, TestCorsDisabled) { | |
ASSERT_EQ(nullptr, method1); | ||
} | ||
|
||
TEST(Config, TestFirebaseServerCheck) { | ||
static const char kServiceConfigWithoutAuthz[] = R"( | ||
name: "Service.Name" | ||
)"; | ||
|
||
static const char kServiceConfigWithAuthz[] = R"( | ||
name: "Service.Name" | ||
experimental { | ||
authorization { | ||
provider: "[email protected]" | ||
} | ||
} | ||
)"; | ||
|
||
static const char kServerConfigWithoutAuthz[] = R"( | ||
service_control_config { | ||
check_aggregator_config { | ||
cache_entries: 1000 | ||
flush_interval_ms: 10 | ||
response_expiration_ms: 20 | ||
} | ||
report_aggregator_config { | ||
cache_entries: 1020 | ||
flush_interval_ms: 15 | ||
} | ||
} | ||
)"; | ||
|
||
static const char kServerConfigWithAuthz[] = R"( | ||
api_check_security_rules_config { | ||
firebase_server: "https://myfirebaseserver.com/" | ||
} | ||
)"; | ||
|
||
TEST(Config, TestFirebaseServerCheckWithServiceAuthzWithoutServerAuthz) { | ||
MockApiManagerEnvironmentWithLog env; | ||
|
||
static const char server_config[] = R"( | ||
api_check_security_rules_config { | ||
firebase_server: "https://myfirebaseserver.com/" | ||
std::unique_ptr<Config> config = | ||
Config::Create(&env, kServiceConfigWithAuthz, kServerConfigWithoutAuthz); | ||
ASSERT_TRUE(config); | ||
|
||
ASSERT_EQ(config->GetFirebaseServer(), "[email protected]"); | ||
} | ||
)"; | ||
|
||
TEST(Config, TestFirebaseServerCheckWithServiceAuthzWithServerAuthz) { | ||
MockApiManagerEnvironmentWithLog env; | ||
|
||
std::unique_ptr<Config> config = | ||
Config::Create(&env, kServiceNameConfig, server_config); | ||
Config::Create(&env, kServiceConfigWithAuthz, kServerConfigWithAuthz); | ||
ASSERT_TRUE(config); | ||
|
||
ASSERT_EQ(config->GetFirebaseServer(), "https://myfirebaseserver.com/"); | ||
} | ||
|
||
TEST(Config, TestEmptyFirebaseServerCheck) { | ||
TEST(Config, TestFirebaseServerCheckWithoutServiceAuthzWithoutServerAuthz) { | ||
MockApiManagerEnvironmentWithLog env; | ||
|
||
static const char server_config[] = R"( | ||
service_control_config { | ||
check_aggregator_config { | ||
cache_entries: 1000 | ||
flush_interval_ms: 10 | ||
response_expiration_ms: 20 | ||
} | ||
report_aggregator_config { | ||
cache_entries: 1020 | ||
flush_interval_ms: 15 | ||
} | ||
std::unique_ptr<Config> config = | ||
Config::Create(&env, kServiceConfigWithoutAuthz, kServerConfigWithoutAuthz); | ||
ASSERT_TRUE(config); | ||
|
||
ASSERT_EQ(config->GetFirebaseServer(), ""); | ||
} | ||
)"; | ||
|
||
TEST(Config, TestFirebaseServerCheckWithoutServiceConfigWithServerConfig) { | ||
MockApiManagerEnvironmentWithLog env; | ||
|
||
std::unique_ptr<Config> config = | ||
Config::Create(&env, kServiceNameConfig, server_config); | ||
Config::Create(&env, kServiceConfigWithoutAuthz, kServerConfigWithAuthz); | ||
ASSERT_TRUE(config); | ||
|
||
ASSERT_TRUE(config->GetFirebaseServer().empty()); | ||
ASSERT_EQ(config->GetFirebaseServer(), "https://myfirebaseserver.com/"); | ||
} | ||
} // namespace | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this config invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a new config introduced in the PR.