Skip to content
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

Enable ESP to invoke Firebase Security rules. #54

Merged
merged 22 commits into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions contrib/endpoints/src/api_manager/check_security_rules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@ const char kRequest[] = "request";
const char kContentType[] = "Content-Type";
const char kApplication[] = "application/json";

const std::string GetFirebaseServer(const context::RequestContext &context) {
return context.service_context()
->config()
->server_config()
->api_check_security_rules_config()
.firebase_server();
const std::string &GetFirebaseServer(const context::RequestContext &context) {
return context.service_context()->config()->GetFirebaseServer();
}

void SetProtoValue(const std::string &key,
Expand Down
4 changes: 4 additions & 0 deletions contrib/endpoints/src/api_manager/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -513,5 +513,9 @@ void Config::SetJwksUri(const string &issuer, const string &jwks_uri,
}
}

const std::string &Config::GetFirebaseServer() {
return server_config_->api_check_security_rules_config().firebase_server();
}

} // namespace api_manager
} // namespace google
3 changes: 3 additions & 0 deletions contrib/endpoints/src/api_manager/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class Config {
void SetJwksUri(const std::string &issuer, const std::string &jwks_uri,
bool openid_valid);

// Get the Firebase server from Server config
const std::string &GetFirebaseServer();

private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Config);

Expand Down
17 changes: 17 additions & 0 deletions contrib/endpoints/src/api_manager/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,23 @@ TEST(Config, TestCorsDisabled) {
ASSERT_EQ(nullptr, method1);
}

TEST(Config, TestFirebaseServerCheck) {
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, kServiceNameConfig, server_config);
ASSERT_TRUE(config);

auto server = config->GetFirebaseServer();
ASSERT_EQ(server, "https://myfirebaseserver.com/");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a test case with a non-empty server_config, but no api_check_security_rules_config.


} // namespace

} // namespace api_manager
Expand Down
3 changes: 2 additions & 1 deletion contrib/endpoints/src/api_manager/context/service_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class ServiceContext {
}

bool IsRulesCheckEnabled() const {
return RequireAuth() && config_->server_config() &&
return RequireAuth() && service().apis_size() > 0 &&
config_->server_config() &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we call config->GEtFirebaseServer()?

config_->server_config()->has_api_check_security_rules_config() &&
!config_->server_config()
->api_check_security_rules_config()
Expand Down