诛是什么意思| 亚麻是什么面料| 东北人喜欢吃什么菜| 十恶大败是什么意思| 什么的北风| 甲沟炎什么症状| 妙不可言是什么意思| 头皮痛什么原因引起的| movefree是什么药| 1998年属什么生肖| 抓龙筋什么意思| 芙蓉花是什么花| 正团级是什么军衔| 后位子宫什么意思| 什么样的降落伞| 武汉有什么好玩的地方| 梦见大蒜是什么意思| 送哥们什么礼物好| 什么时间入伏| 什么情况会胎停| 合拢是什么意思| 四史指的是什么| 长时间手淫有什么危害| 大学生入伍有什么好处| 得了肠胃炎吃什么最好| 涤纶是什么面料优缺点| 眼睛为什么会近视| 143是什么意思| 什么是调剂| 芒果和什么相克| 抗氧化性是什么意思| 失眠挂什么科| 酌情处理是什么意思| 1930年属什么| 肚脐眼位置疼是什么原因| 痰栓是什么意思| 顽固是什么意思| 合财是什么意思| 红花泡水喝有什么功效和作用| 鼻子经常出血是什么病征兆| 别有洞天是什么生肖| 王八看绿豆是什么意思| 什么人容易得血栓| fsa是什么意思| 王者风范是什么意思| 器材是什么意思| 女性睾酮低意味着什么| 荨麻疹要用什么药| 春节的习俗是什么| 山竹是什么季节的水果| 洗衣机不出水是什么原因| 生水是什么意思| 手指缝痒是什么原因| 脂溢性皮炎是什么原因引起的| 赢荡为什么传位嬴稷| 减肥吃什么药好| 西药是用什么材料做的| 波美度是什么意思| 阳历一月份是什么星座| 强制是什么意思| 心肌缺血用什么药效果最好| 骨穿刺主要检查什么病| 孩子吐了吃什么药| 米咖色是什么颜色| 炸酱面用什么酱| pdr是什么意思| 夜卧早起是什么意思| 掉头发是什么原因导致的| ih医学上是什么意思| 前列腺是什么意思| 慢性萎缩性胃炎是什么意思| 心脏大是什么病严重吗| 田七和三七有什么区别| 洛阳以前叫什么名字| 尿路感染吃什么药效果最好| 穿什么衣服| as材质是什么材料| 毛血旺是什么菜| 高大的动物是什么生肖| 为什么要吃叶酸| 猫五行属什么| 暗物质和暗能量是什么| 手麻了是什么原因| 高血压是什么原因引起的| 李子吃了有什么好处| 什么水果是温性的| 肝火旺吃什么中药| 爱出汗是什么原因| 海藻面膜有什么作用| 陪衬是什么意思| 嗜睡乏力没精神容易疲劳是什么原因| 孕妇感冒了可以吃什么药| 停职是什么意思| 外阴白斑挂什么科| 四百多分能上什么大学| 什么手机电池最耐用| 早餐吃什么英语怎么说| dha是什么| 梨是什么季节的水果| 运交华盖是什么意思| 慕名而来是什么意思| 蜱虫是什么| 男人下巴有痣代表什么| 12月14是什么星座| 婴儿蓝是什么颜色| sf什么意思| 桔梗是什么东西| 小孩干呕是什么原因| 人丹是什么药| 汉武帝叫什么| 茵陈和什么泡水喝对肝脏最好| 中暑了吃什么| 西瓜为什么是红色的| lucas是什么意思| 欲是什么意思| 阳明病是什么意思| 什么样的操场| 脚心疼是什么原因| 铁观音适合什么季节喝| pct偏高说明什么| 肝实质回声不均匀是什么意思| 诟病是什么意思| 婴儿游泳有什么好处和坏处| 曹操的父亲叫什么名字| 牙龈长泡是什么原因| 大叔是什么意思| 除湿气吃什么好| ufc什么意思| 宝宝吃益生菌有什么好处和坏处| 夏至为什么吃馄饨| legion什么牌子| 球菌阳性是什么意思| 水饮是什么意思| 眼睛为什么不怕冷| 挖野菜是什么意思| 颈椎病用什么药最好| trust阴性tppa阳性说明什么| 检查梅毒挂什么科| 吃什么养肝| 公分的单位是什么| 牛仔布料是什么面料| 1月1日是什么节| 什么越来越什么| 大致正常心电图是什么意思| 土猪肉和普通猪肉有什么分别| 有什么聚会玩的游戏| 资金流入股价下跌为什么| 印第安老斑鸠什么意思| 什么颜色的床单有助于睡眠| 缺碘会有什么症状| 胎盘分级0级什么意思| 不孝有三无后为大是什么意思| 新奇的什么| 太安鱼是什么鱼| 什么叫卒中| 欲加之罪何患无辞是什么意思| 单人旁的字有什么| 痛风是什么原因造成的| 宝宝大便绿色是什么原因| 心慌气短吃什么药最好| 身份证后4位代表什么| 孕妇为什么不能吃韭菜| 纪委书记是什么级别| 蓝色配什么颜色好看| 黑色素沉淀是什么原因引起的| 臭屁是什么意思| 拉肚子应该挂什么科| 马和驴为什么能杂交| 泌尿外科主要检查什么| 什么树| 阳寿是什么意思| 瓷娃娃什么意思| 支原体阳性是什么意思| 劳力士手表什么档次| 陕西有什么特产| 丹五行属性是什么| 途明是什么档次的包| 白水晶五行属什么| 人为什么会抑郁| 孕妇羊水多是什么原因造成的| 鬼迷心窍什么意思| 白内障的主要症状是什么| 梦见理发是什么意思| 茄子与什么相克| 声泪俱下是什么意思| 云南雪燕有什么作用| 什么是创业板股票| 五红汤什么时候喝最好| 酒精和碘伏有什么区别| 吃什么补充黄体酮| 为什么发际线高| 什么是微商| 海鸥吃什么| 尿道口长肉芽是什么| 梦见栽花是什么意思| 跟单员是做什么的| 黑猫进家门预示着什么| ivu是什么检查| 圣诞礼物什么时候送| 梦见打死黄鼠狼是什么意思| 胸部痛是什么原因| 在家无聊可以做什么| 邪魅一笑是什么意思| 有机什么意思| 身上痒什么原因| 小腹胀是什么原因女性| 臭虫长什么样子图片| 不变应万变是什么意思| 什么的李逵| 大象的鼻子像什么| callme是什么意思| 肌酸激酶高是什么意思| 乳腺结节不能吃什么食物| 胎盘厚度代表什么| 灶王爷叫什么名字| 禾末念什么| 吃什么对牙齿好| 为什么喝水血糖也会高| ddg是什么意思| 过敏性鼻炎用什么药| 木灵念什么| 脚底冰凉是什么原因| 突然流鼻血是什么征兆| 火箭是干什么用的| 为什么说白痰要人命| 1969年属鸡是什么命| 4.22什么星座| 苹果煮水喝有什么好处和坏处| 迪根是什么药| poison是什么意思| 谦虚的什么| 结婚40年是什么婚| 88属什么生肖| messi是什么意思| 什么零食好吃| 93什么意思| 升血小板吃什么药| 大象鼻子为什么那么长| 阳历7月15日是什么星座| 腰椎生理曲度变直是什么意思| 孕妇手麻是什么原因引起的| 王菲属什么生肖| 农历8月20日是什么星座| 经常头疼是什么原因| 真丝棉是什么面料| 机翻是什么意思| 吸渣体质是什么意思| 芥末是什么做的| 窈窕淑女君子好逑是什么意思| 黄瓜有什么营养| 肚脐的左边疼是什么原因| 补办身份证需要什么| 保底和底薪有什么区别| 肥胖纹长什么样| 口周读什么| 闪光点是什么意思| 为什么会缺钙| 肛裂出血用什么药| 梦见给别人理发是什么意思| 小孩表演后卸妆用什么| 心电图窦性心律什么意思| 理想型是什么意思| 血糖高能吃什么蔬菜| 轻度强化是什么意思| 百度
blob: a53143c19b072aacf32eb094256f279a2db05d8f [file] [log] [blame]
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Unit tests for functions in google_apis/google_api_keys.h.
//
// Because the file deals with a lot of preprocessor defines and
// optionally includes an internal header, the way we test is by
// including the .cc file multiple times with different defines set.
// This is a little unorthodox, but it lets us test the behavior as
// close to unmodified as possible.
#include "google_apis/google_api_keys_unittest.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_command_line.h"
#include "base/test/scoped_feature_list.h"
#include "base/version_info/channel.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "google_apis/api_key_cache.h"
#include "google_apis/default_api_keys.h"
#include "google_apis/gaia/gaia_config.h"
#include "google_apis/gaia/gaia_switches.h"
#include "google_apis/google_api_keys.h"
GoogleAPIKeysTest::GoogleAPIKeysTest() : env_(base::Environment::Create()) {
static_assert(9 == 3 + 2 * google_apis::CLIENT_NUM_ITEMS,
"Unexpected number of key entries.");
env_cache_[0].variable_name = "GOOGLE_API_KEY";
env_cache_[1].variable_name = "GOOGLE_CLIENT_ID_MAIN";
env_cache_[2].variable_name = "GOOGLE_CLIENT_SECRET_MAIN";
env_cache_[3].variable_name = "GOOGLE_CLIENT_ID_REMOTING";
env_cache_[4].variable_name = "GOOGLE_CLIENT_SECRET_REMOTING";
env_cache_[5].variable_name = "GOOGLE_CLIENT_ID_REMOTING_HOST";
env_cache_[6].variable_name = "GOOGLE_CLIENT_SECRET_REMOTING_HOST";
env_cache_[7].variable_name = "GOOGLE_DEFAULT_CLIENT_ID";
env_cache_[8].variable_name = "GOOGLE_DEFAULT_CLIENT_SECRET";
}
GoogleAPIKeysTest::~GoogleAPIKeysTest() {}
void GoogleAPIKeysTest::SetUp() {
// Unset all environment variables that can affect these tests,
// for the duration of the tests.
for (size_t i = 0; i < std::size(env_cache_); ++i) {
EnvironmentCache& cache = env_cache_[i];
cache.was_set = env_->HasVar(cache.variable_name);
cache.value.clear();
if (cache.was_set) {
cache.value = env_->GetVar(cache.variable_name).value();
env_->UnSetVar(cache.variable_name);
}
}
}
void GoogleAPIKeysTest::TearDown() {
// Restore environment.
for (size_t i = 0; i < std::size(env_cache_); ++i) {
EnvironmentCache& cache = env_cache_[i];
if (cache.was_set) {
env_->SetVar(cache.variable_name, cache.value);
}
}
}
base::FilePath GetTestFilePath(const std::string& relative_path) {
base::FilePath path;
if (!base::PathService::Get(base::DIR_SRC_TEST_DATA_ROOT, &path)) {
return base::FilePath();
}
return path.AppendASCII("google_apis")
.AppendASCII("test")
.AppendASCII("data")
.AppendASCII("gaia")
.AppendASCII(relative_path);
}
#if defined(USE_OFFICIAL_GOOGLE_API_KEYS)
// Test official build behavior, since we are in a checkout where this
// is possible.
namespace official_build {
// We start every test by creating a clean environment for the
// preprocessor defines used in define_baked_in_api_keys-inc.cc
#undef GOOGLE_API_KEY
#undef GOOGLE_CLIENT_ID_MAIN
#undef GOOGLE_CLIENT_SECRET_MAIN
#undef GOOGLE_CLIENT_ID_REMOTING
#undef GOOGLE_CLIENT_SECRET_REMOTING
#undef GOOGLE_CLIENT_ID_REMOTING_HOST
#undef GOOGLE_CLIENT_SECRET_REMOTING_HOST
#undef GOOGLE_DEFAULT_CLIENT_ID
#undef GOOGLE_DEFAULT_CLIENT_SECRET
// Try setting some keys, these should be ignored since it's a build
// with official keys.
#define GOOGLE_API_KEY "bogus api_key"
#define GOOGLE_CLIENT_ID_MAIN "bogus client_id_main"
// Undef include guard so things get defined again, within this namespace.
#undef GOOGLE_APIS_GOOGLE_API_KEYS_H_
#undef GOOGLE_APIS_INTERNAL_GOOGLE_CHROME_API_KEYS_
#undef GOOGLE_APIS_INTERNAL_METRICS_SIGNING_KEY_H_
#include "google_apis/internal/google_chrome_api_keys.h"
#include "google_apis/internal/metrics_signing_key.h"
// This file must be included after the internal files defining official keys.
#include "google_apis/default_api_keys-inc.cc"
} // namespace official_build
TEST_F(GoogleAPIKeysTest, OfficialKeys) {
google_apis::ApiKeyCache api_key_cache(
official_build::GetDefaultApiKeysFromDefinedValues());
auto scoped_override =
google_apis::SetScopedApiKeyCacheForTesting(&api_key_cache);
EXPECT_TRUE(google_apis::HasAPIKeyConfigured());
EXPECT_TRUE(google_apis::HasOAuthClientConfigured());
std::string api_key = google_apis::GetAPIKey();
std::string id_main =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN);
std::string secret_main =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN);
std::string id_remoting =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING);
std::string secret_remoting =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING);
std::string id_remoting_host =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST);
std::string secret_remoting_host =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING_HOST);
EXPECT_NE(0u, api_key.size());
EXPECT_NE(google_apis::DefaultApiKeys::kUnsetApiToken, api_key);
EXPECT_NE("bogus api_key", api_key);
EXPECT_NE(0u, id_main.size());
EXPECT_NE(google_apis::DefaultApiKeys::kUnsetApiToken, id_main);
EXPECT_NE("bogus client_id_main", id_main);
EXPECT_NE(0u, secret_main.size());
EXPECT_NE(google_apis::DefaultApiKeys::kUnsetApiToken, secret_main);
EXPECT_NE(0u, id_remoting.size());
EXPECT_NE(google_apis::DefaultApiKeys::kUnsetApiToken, id_remoting);
EXPECT_NE(0u, secret_remoting.size());
EXPECT_NE(google_apis::DefaultApiKeys::kUnsetApiToken, secret_remoting);
EXPECT_NE(0u, id_remoting_host.size());
EXPECT_NE(google_apis::DefaultApiKeys::kUnsetApiToken, id_remoting_host);
EXPECT_NE(0u, secret_remoting_host.size());
EXPECT_NE(google_apis::DefaultApiKeys::kUnsetApiToken, secret_remoting_host);
}
#endif // defined(USE_OFFICIAL_GOOGLE_API_KEYS)
// After this test, for the remainder of this compilation unit, we
// need official keys to not be used.
#undef BUILDFLAG_INTERNAL_CHROMIUM_BRANDING
#undef BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING
#define BUILDFLAG_INTERNAL_CHROMIUM_BRANDING() (1)
#define BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING() (0)
#undef USE_OFFICIAL_GOOGLE_API_KEYS
// Test the set of keys temporarily baked into Chromium by default.
namespace default_keys {
// We start every test by creating a clean environment for the
// preprocessor defines used in define_baked_in_api_keys-inc.cc
#undef GOOGLE_API_KEY
#undef GOOGLE_CLIENT_ID_MAIN
#undef GOOGLE_CLIENT_SECRET_MAIN
#undef GOOGLE_CLIENT_ID_REMOTING
#undef GOOGLE_CLIENT_SECRET_REMOTING
#undef GOOGLE_CLIENT_ID_REMOTING_HOST
#undef GOOGLE_CLIENT_SECRET_REMOTING_HOST
#undef GOOGLE_DEFAULT_CLIENT_ID
#undef GOOGLE_DEFAULT_CLIENT_SECRET
#include "google_apis/default_api_keys-inc.cc"
} // namespace default_keys
TEST_F(GoogleAPIKeysTest, DefaultKeys) {
google_apis::ApiKeyCache api_key_cache(
default_keys::GetDefaultApiKeysFromDefinedValues());
auto scoped_override =
google_apis::SetScopedApiKeyCacheForTesting(&api_key_cache);
EXPECT_FALSE(google_apis::HasAPIKeyConfigured());
EXPECT_FALSE(google_apis::HasOAuthClientConfigured());
std::string api_key = google_apis::GetAPIKey();
std::string id_main =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN);
std::string secret_main =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN);
std::string id_remoting =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING);
std::string secret_remoting =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING);
std::string id_remoting_host =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST);
std::string secret_remoting_host =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING_HOST);
EXPECT_EQ(google_apis::DefaultApiKeys::kUnsetApiToken, api_key);
EXPECT_EQ(google_apis::DefaultApiKeys::kUnsetApiToken, id_main);
EXPECT_EQ(google_apis::DefaultApiKeys::kUnsetApiToken, secret_main);
EXPECT_EQ(google_apis::DefaultApiKeys::kUnsetApiToken, id_remoting);
EXPECT_EQ(google_apis::DefaultApiKeys::kUnsetApiToken, secret_remoting);
EXPECT_EQ(google_apis::DefaultApiKeys::kUnsetApiToken, id_remoting_host);
EXPECT_EQ(google_apis::DefaultApiKeys::kUnsetApiToken, secret_remoting_host);
}
// Override a couple of keys, leave the rest default.
namespace override_some_keys {
// We start every test by creating a clean environment for the
// preprocessor defines used in define_baked_in_api_keys-inc.cc
#undef GOOGLE_API_KEY
#undef GOOGLE_CLIENT_ID_MAIN
#undef GOOGLE_CLIENT_SECRET_MAIN
#undef GOOGLE_CLIENT_ID_REMOTING
#undef GOOGLE_CLIENT_SECRET_REMOTING
#undef GOOGLE_CLIENT_ID_REMOTING_HOST
#undef GOOGLE_CLIENT_SECRET_REMOTING_HOST
#undef GOOGLE_DEFAULT_CLIENT_ID
#undef GOOGLE_DEFAULT_CLIENT_SECRET
#define GOOGLE_API_KEY "API_KEY override"
#define GOOGLE_CLIENT_ID_REMOTING "CLIENT_ID_REMOTING override"
#include "google_apis/default_api_keys-inc.cc"
} // namespace override_some_keys
TEST_F(GoogleAPIKeysTest, OverrideSomeKeys) {
google_apis::ApiKeyCache api_key_cache(
override_some_keys::GetDefaultApiKeysFromDefinedValues());
auto scoped_override =
google_apis::SetScopedApiKeyCacheForTesting(&api_key_cache);
EXPECT_TRUE(google_apis::HasAPIKeyConfigured());
EXPECT_FALSE(google_apis::HasOAuthClientConfigured());
std::string api_key = google_apis::GetAPIKey();
std::string id_main =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN);
std::string secret_main =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN);
std::string id_remoting =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING);
std::string secret_remoting =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING);
std::string id_remoting_host =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST);
std::string secret_remoting_host =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING_HOST);
EXPECT_EQ("API_KEY override", api_key);
EXPECT_EQ(google_apis::DefaultApiKeys::kUnsetApiToken, id_main);
EXPECT_EQ(google_apis::DefaultApiKeys::kUnsetApiToken, secret_main);
EXPECT_EQ("CLIENT_ID_REMOTING override", id_remoting);
EXPECT_EQ(google_apis::DefaultApiKeys::kUnsetApiToken, secret_remoting);
EXPECT_EQ(google_apis::DefaultApiKeys::kUnsetApiToken, id_remoting_host);
EXPECT_EQ(google_apis::DefaultApiKeys::kUnsetApiToken, secret_remoting_host);
}
// Override all keys.
namespace override_all_keys {
// We start every test by creating a clean environment for the
// preprocessor defines used in define_baked_in_api_keys-inc.cc
#undef GOOGLE_API_KEY
#undef GOOGLE_CLIENT_ID_MAIN
#undef GOOGLE_CLIENT_SECRET_MAIN
#undef GOOGLE_CLIENT_ID_REMOTING
#undef GOOGLE_CLIENT_SECRET_REMOTING
#undef GOOGLE_CLIENT_ID_REMOTING_HOST
#undef GOOGLE_CLIENT_SECRET_REMOTING_HOST
#undef GOOGLE_DEFAULT_CLIENT_ID
#undef GOOGLE_DEFAULT_CLIENT_SECRET
#define GOOGLE_API_KEY "API_KEY"
#define GOOGLE_CLIENT_ID_MAIN "ID_MAIN"
#define GOOGLE_CLIENT_SECRET_MAIN "SECRET_MAIN"
#define GOOGLE_CLIENT_ID_REMOTING "ID_REMOTING"
#define GOOGLE_CLIENT_SECRET_REMOTING "SECRET_REMOTING"
#define GOOGLE_CLIENT_ID_REMOTING_HOST "ID_REMOTING_HOST"
#define GOOGLE_CLIENT_SECRET_REMOTING_HOST "SECRET_REMOTING_HOST"
#include "google_apis/default_api_keys-inc.cc"
} // namespace override_all_keys
TEST_F(GoogleAPIKeysTest, OverrideAllKeys) {
google_apis::ApiKeyCache api_key_cache(
override_all_keys::GetDefaultApiKeysFromDefinedValues());
auto scoped_override =
google_apis::SetScopedApiKeyCacheForTesting(&api_key_cache);
EXPECT_TRUE(google_apis::HasAPIKeyConfigured());
EXPECT_TRUE(google_apis::HasOAuthClientConfigured());
std::string api_key = google_apis::GetAPIKey();
std::string id_main =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN);
std::string secret_main =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN);
std::string id_remoting =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING);
std::string secret_remoting =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING);
std::string id_remoting_host =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST);
std::string secret_remoting_host =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING_HOST);
EXPECT_EQ("API_KEY", api_key);
EXPECT_EQ("ID_MAIN", id_main);
EXPECT_EQ("SECRET_MAIN", secret_main);
EXPECT_EQ("ID_REMOTING", id_remoting);
EXPECT_EQ("SECRET_REMOTING", secret_remoting);
EXPECT_EQ("ID_REMOTING_HOST", id_remoting_host);
EXPECT_EQ("SECRET_REMOTING_HOST", secret_remoting_host);
}
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Override all keys using both preprocessor defines and environment
// variables. The environment variables should win.
namespace override_all_keys_env {
// We start every test by creating a clean environment for the
// preprocessor defines used in define_baked_in_api_keys-inc.cc
#undef GOOGLE_API_KEY
#undef GOOGLE_CLIENT_ID_MAIN
#undef GOOGLE_CLIENT_SECRET_MAIN
#undef GOOGLE_CLIENT_ID_REMOTING
#undef GOOGLE_CLIENT_SECRET_REMOTING
#undef GOOGLE_CLIENT_ID_REMOTING_HOST
#undef GOOGLE_CLIENT_SECRET_REMOTING_HOST
#undef GOOGLE_DEFAULT_CLIENT_ID
#undef GOOGLE_DEFAULT_CLIENT_SECRET
#define GOOGLE_API_KEY "API_KEY"
#define GOOGLE_CLIENT_ID_MAIN "ID_MAIN"
#define GOOGLE_CLIENT_SECRET_MAIN "SECRET_MAIN"
#define GOOGLE_CLIENT_ID_REMOTING "ID_REMOTING"
#define GOOGLE_CLIENT_SECRET_REMOTING "SECRET_REMOTING"
#define GOOGLE_CLIENT_ID_REMOTING_HOST "ID_REMOTING_HOST"
#define GOOGLE_CLIENT_SECRET_REMOTING_HOST "SECRET_REMOTING_HOST"
#include "google_apis/default_api_keys-inc.cc"
} // namespace override_all_keys_env
TEST_F(GoogleAPIKeysTest, OverrideAllKeysUsingEnvironment) {
std::unique_ptr<base::Environment> env(base::Environment::Create());
env->SetVar("GOOGLE_API_KEY", "env-API_KEY");
env->SetVar("GOOGLE_CLIENT_ID_MAIN", "env-ID_MAIN");
env->SetVar("GOOGLE_CLIENT_ID_REMOTING", "env-ID_REMOTING");
env->SetVar("GOOGLE_CLIENT_ID_REMOTING_HOST", "env-ID_REMOTING_HOST");
env->SetVar("GOOGLE_CLIENT_SECRET_MAIN", "env-SECRET_MAIN");
env->SetVar("GOOGLE_CLIENT_SECRET_REMOTING", "env-SECRET_REMOTING");
env->SetVar("GOOGLE_CLIENT_SECRET_REMOTING_HOST", "env-SECRET_REMOTING_HOST");
google_apis::ApiKeyCache api_key_cache(
override_all_keys_env::GetDefaultApiKeysFromDefinedValues());
auto scoped_override =
google_apis::SetScopedApiKeyCacheForTesting(&api_key_cache);
EXPECT_TRUE(google_apis::HasAPIKeyConfigured());
EXPECT_TRUE(google_apis::HasOAuthClientConfigured());
// It's important that the first call to Get() only happen after the
// environment variables have been set.
std::string api_key = google_apis::GetAPIKey();
std::string id_main =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN);
std::string secret_main =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN);
std::string id_remoting =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING);
std::string secret_remoting =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING);
std::string id_remoting_host =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST);
std::string secret_remoting_host =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING_HOST);
EXPECT_EQ("env-API_KEY", api_key);
EXPECT_EQ("env-ID_MAIN", id_main);
EXPECT_EQ("env-SECRET_MAIN", secret_main);
EXPECT_EQ("env-ID_REMOTING", id_remoting);
EXPECT_EQ("env-SECRET_REMOTING", secret_remoting);
EXPECT_EQ("env-ID_REMOTING_HOST", id_remoting_host);
EXPECT_EQ("env-SECRET_REMOTING_HOST", secret_remoting_host);
}
#endif // !BUILDFLAG(GOOGLE_CHROME_BRANDING)
#if BUILDFLAG(SUPPORT_EXTERNAL_GOOGLE_API_KEY)
// Override all keys using both preprocessor defines and setters.
// Setters should win.
namespace override_all_keys_setters {
// We start every test by creating a clean environment for the
// preprocessor defines used in define_baked_in_api_keys-inc.cc
#undef GOOGLE_API_KEY
#undef GOOGLE_CLIENT_ID_MAIN
#undef GOOGLE_CLIENT_SECRET_MAIN
#undef GOOGLE_CLIENT_ID_REMOTING
#undef GOOGLE_CLIENT_SECRET_REMOTING
#undef GOOGLE_CLIENT_ID_REMOTING_HOST
#undef GOOGLE_CLIENT_SECRET_REMOTING_HOST
#undef GOOGLE_DEFAULT_CLIENT_ID
#undef GOOGLE_DEFAULT_CLIENT_SECRET
#define GOOGLE_API_KEY "API_KEY"
#define GOOGLE_CLIENT_ID_MAIN "ID_MAIN"
#define GOOGLE_CLIENT_SECRET_MAIN "SECRET_MAIN"
#define GOOGLE_CLIENT_ID_REMOTING "ID_REMOTING"
#define GOOGLE_CLIENT_SECRET_REMOTING "SECRET_REMOTING"
#define GOOGLE_CLIENT_ID_REMOTING_HOST "ID_REMOTING_HOST"
#define GOOGLE_CLIENT_SECRET_REMOTING_HOST "SECRET_REMOTING_HOST"
#include "google_apis/default_api_keys-inc.cc"
} // namespace override_all_keys_setters
TEST_F(GoogleAPIKeysTest, OverrideAllKeysUsingSetters) {
google_apis::ApiKeyCache api_key_cache(
override_all_keys_setters::GetDefaultApiKeysFromDefinedValues());
auto scoped_override =
google_apis::SetScopedApiKeyCacheForTesting(&api_key_cache);
std::string api_key("setter-API_KEY");
std::string client_id("setter-CLIENT_ID");
std::string client_secret("setter-CLIENT_SECRET");
google_apis::InitializeAndOverrideAPIKeyAndOAuthClient(api_key, client_id,
client_secret);
EXPECT_TRUE(google_apis::HasAPIKeyConfigured());
EXPECT_TRUE(google_apis::HasOAuthClientConfigured());
EXPECT_EQ(api_key, google_apis::GetAPIKey(::version_info::Channel::STABLE));
EXPECT_EQ(api_key, google_apis::GetAPIKey());
EXPECT_EQ(client_id,
google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN));
EXPECT_EQ(client_secret,
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN));
EXPECT_EQ(client_id,
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING));
EXPECT_EQ(client_secret,
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING));
EXPECT_EQ(client_id,
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST));
EXPECT_EQ(client_secret, google_apis::GetOAuth2ClientSecret(
google_apis::CLIENT_REMOTING_HOST));
}
#endif // BUILDFLAG(SUPPORT_EXTERNAL_GOOGLE_API_KEY)
// Override all keys using both preprocessor defines and gaia config.
// Config should win.
namespace override_all_keys_config {
// We start every test by creating a clean environment for the
// preprocessor defines used in define_baked_in_api_keys-inc.cc
#undef GOOGLE_API_KEY
#undef GOOGLE_CLIENT_ID_MAIN
#undef GOOGLE_CLIENT_SECRET_MAIN
#undef GOOGLE_CLIENT_ID_REMOTING
#undef GOOGLE_CLIENT_SECRET_REMOTING
#undef GOOGLE_CLIENT_ID_REMOTING_HOST
#undef GOOGLE_CLIENT_SECRET_REMOTING_HOST
#undef GOOGLE_DEFAULT_CLIENT_ID
#undef GOOGLE_DEFAULT_CLIENT_SECRET
#define GOOGLE_API_KEY "API_KEY"
#define GOOGLE_CLIENT_ID_MAIN "ID_MAIN"
#define GOOGLE_CLIENT_SECRET_MAIN "SECRET_MAIN"
#define GOOGLE_CLIENT_ID_REMOTING "ID_REMOTING"
#define GOOGLE_CLIENT_SECRET_REMOTING "SECRET_REMOTING"
#define GOOGLE_CLIENT_ID_REMOTING_HOST "ID_REMOTING_HOST"
#define GOOGLE_CLIENT_SECRET_REMOTING_HOST "SECRET_REMOTING_HOST"
#include "google_apis/default_api_keys-inc.cc"
} // namespace override_all_keys_config
TEST_F(GoogleAPIKeysTest, OverrideAllKeysUsingConfig) {
auto command_line = std::make_unique<base::test::ScopedCommandLine>();
command_line->GetProcessCommandLine()->AppendSwitchPath(
"gaia-config", GetTestFilePath("api_keys.json"));
GaiaConfig::ResetInstanceForTesting();
google_apis::ApiKeyCache api_key_cache(
override_all_keys_config::GetDefaultApiKeysFromDefinedValues());
auto scoped_override =
google_apis::SetScopedApiKeyCacheForTesting(&api_key_cache);
EXPECT_TRUE(google_apis::HasAPIKeyConfigured());
EXPECT_TRUE(google_apis::HasOAuthClientConfigured());
EXPECT_EQ("config-API_KEY",
google_apis::GetAPIKey(version_info::Channel::STABLE));
EXPECT_EQ("config-API_KEY", google_apis::GetAPIKey());
EXPECT_EQ("config-ID_MAIN",
google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN));
EXPECT_EQ("config-SECRET_MAIN",
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN));
EXPECT_EQ("config-ID_REMOTING",
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING));
EXPECT_EQ("config-SECRET_REMOTING",
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING));
EXPECT_EQ("config-ID_REMOTING_HOST",
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING_HOST));
EXPECT_EQ(
"config-SECRET_REMOTING_HOST",
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING_HOST));
// It's important to reset the global config state for other tests running in
// the same process.
command_line.reset();
GaiaConfig::ResetInstanceForTesting();
}
什么猫好看 审美疲劳是什么意思 心肌酶是什么 郑板桥擅长画什么 减肥可以吃什么
皮癣用什么药膏 熟普属于什么茶 什么是安全感 什么驱蚊效果最好 有因必有果什么意思
古代地龙是什么 头七是什么意思 排骨和什么一起炖好吃 梦见蝉是什么意思 靶向治疗是什么
必修是什么意思 腺病毒阳性是什么意思 肚子里有虫子会有什么症状 白油是什么 jewelry什么意思
胸小是什么原因hcv7jop6ns4r.cn 万艾可是什么药hcv8jop2ns4r.cn 独苗是什么意思dayuxmw.com 脂肪球是什么意思hcv8jop0ns6r.cn 口腔溃疡吃什么药好得快hcv8jop0ns7r.cn
先自度其足的度是什么意思onlinewuye.com 就请你给我多一点点时间是什么歌cj623037.com 9月14日是什么星座kuyehao.com 抗核抗体阳性说明什么cl108k.com 空窗期是什么意思bjhyzcsm.com
唐僧原名叫什么hcv8jop7ns9r.cn 牙齿发白是什么原因hcv8jop9ns2r.cn ctc是什么hcv7jop7ns0r.cn 调侃是什么意思hcv8jop5ns3r.cn 手指甲没有月牙是什么原因hcv9jop6ns2r.cn
上厕所出血是什么原因wuhaiwuya.com 本虚标实是什么意思hcv8jop1ns6r.cn 谷氨酸钠是什么添加剂hcv7jop9ns6r.cn 金银花什么时候采摘最好hcv7jop6ns9r.cn 女性睾酮高意味着什么tiangongnft.com
百度