summaryrefslogtreecommitdiffstats
path: root/google_apis/google_api_keys_unittest.cc
blob: e8891793e79f3472c7f89c71d73a3f0bff760ecc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Unit tests for implementation of google_api_keys namespace.
//
// 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.h"

#include "build/build_config.h"
#include "google_apis/gaia/gaia_switches.h"
#include "testing/gtest/include/gtest/gtest.h"

// The Win builders fail (with a linker crash) when trying to link
// unit_tests, and the Android builders complain about multiply
// defined symbols (likely they don't do name decoration as well as
// the Mac and Linux linkers).  Therefore these tests are only built
// and run on Mac and Linux, which should provide plenty of coverage
// since there are no platform-specific bits in this code.
#if defined(OS_LINUX) || defined(OS_MACOSX)

// We need to include everything included by google_api_keys.cc once
// at global scope so that things like STL and classes from base don't
// get defined when we re-include the google_api_keys.cc file
// below. We used to include that file in its entirety here, but that
// can cause problems if the linker decides the version of symbols
// from that file included here is the "right" version.
#include <string>
#include "base/command_line.h"
#include "base/environment.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/stringize_macros.h"

// This is the default baked-in value for OAuth IDs and secrets.
static const char kDummyToken[] = "dummytoken";

struct EnvironmentCache {
 public:
  EnvironmentCache() : variable_name(NULL), was_set(false) {}

  const char* variable_name;
  bool was_set;
  std::string value;
};

class GoogleAPIKeysTest : public testing::Test {
 public:
  GoogleAPIKeysTest() : env_(base::Environment::Create()) {
    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_CLOUD_PRINT";
    env_cache_[4].variable_name = "GOOGLE_CLIENT_SECRET_CLOUD_PRINT";
    env_cache_[5].variable_name = "GOOGLE_CLIENT_ID_REMOTING";
    env_cache_[6].variable_name = "GOOGLE_CLIENT_SECRET_REMOTING";
    env_cache_[7].variable_name = "GOOGLE_CLIENT_ID_REMOTING_HOST";
    env_cache_[8].variable_name = "GOOGLE_CLIENT_SECRET_REMOTING_HOST";
    env_cache_[9].variable_name = "GOOGLE_DEFAULT_CLIENT_ID";
    env_cache_[10].variable_name = "GOOGLE_DEFAULT_CLIENT_SECRET";
  }

  void SetUp() override {
    // Unset all environment variables that can affect these tests,
    // for the duration of the tests.
    for (size_t i = 0; i < arraysize(env_cache_); ++i) {
      EnvironmentCache& cache = env_cache_[i];
      cache.was_set = env_->HasVar(cache.variable_name);
      cache.value.clear();
      if (cache.was_set) {
        env_->GetVar(cache.variable_name, &cache.value);
        env_->UnSetVar(cache.variable_name);
      }
    }
  }

  void TearDown() override {
    // Restore environment.
    for (size_t i = 0; i < arraysize(env_cache_); ++i) {
      EnvironmentCache& cache = env_cache_[i];
      if (cache.was_set) {
        env_->SetVar(cache.variable_name, cache.value);
      }
    }
  }

 private:
  scoped_ptr<base::Environment> env_;

  // Why 3?  It is for GOOGLE_API_KEY, GOOGLE_DEFAULT_CLIENT_ID and
  // GOOGLE_DEFAULT_CLIENT_SECRET.
  //
  // Why 2 times CLIENT_NUM_ITEMS?  This is the number of different
  // clients in the OAuth2Client enumeration, and for each of these we
  // have both an ID and a secret.
  EnvironmentCache env_cache_[3 + 2 * google_apis::CLIENT_NUM_ITEMS];
};

#if defined(GOOGLE_CHROME_BUILD) || 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 google_api_keys.cc
#undef DUMMY_API_TOKEN
#undef GOOGLE_API_KEY
#undef GOOGLE_CLIENT_ID_MAIN
#undef GOOGLE_CLIENT_SECRET_MAIN
#undef GOOGLE_CLIENT_ID_CLOUD_PRINT
#undef GOOGLE_CLIENT_SECRET_CLOUD_PRINT
#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_
#include "google_apis/google_api_keys.cc"

}  // namespace official_build

TEST_F(GoogleAPIKeysTest, OfficialKeys) {
  namespace testcase = official_build::google_apis;

  EXPECT_TRUE(testcase::HasKeysConfigured());

  std::string api_key = testcase::g_api_key_cache.Get().api_key();
  std::string id_main = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_MAIN);
  std::string secret_main = testcase::g_api_key_cache.Get().GetClientSecret(
      testcase::CLIENT_MAIN);
  std::string id_cloud_print =
      testcase::g_api_key_cache.Get().GetClientID(
          testcase::CLIENT_CLOUD_PRINT);
  std::string secret_cloud_print =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::CLIENT_CLOUD_PRINT);
  std::string id_remoting = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_REMOTING);
  std::string secret_remoting =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::CLIENT_REMOTING);
  std::string id_remoting_host = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_REMOTING_HOST);
  std::string secret_remoting_host =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::CLIENT_REMOTING_HOST);

  EXPECT_NE(0u, api_key.size());
  EXPECT_NE(DUMMY_API_TOKEN, api_key);
  EXPECT_NE("bogus api_key", api_key);
  EXPECT_NE(kDummyToken, api_key);

  EXPECT_NE(0u, id_main.size());
  EXPECT_NE(DUMMY_API_TOKEN, id_main);
  EXPECT_NE("bogus client_id_main", id_main);
  EXPECT_NE(kDummyToken, id_main);

  EXPECT_NE(0u, secret_main.size());
  EXPECT_NE(DUMMY_API_TOKEN, secret_main);
  EXPECT_NE(kDummyToken, secret_main);

  EXPECT_NE(0u, id_cloud_print.size());
  EXPECT_NE(DUMMY_API_TOKEN, id_cloud_print);
  EXPECT_NE(kDummyToken, id_cloud_print);

  EXPECT_NE(0u, secret_cloud_print.size());
  EXPECT_NE(DUMMY_API_TOKEN, secret_cloud_print);
  EXPECT_NE(kDummyToken, secret_cloud_print);

  EXPECT_NE(0u, id_remoting.size());
  EXPECT_NE(DUMMY_API_TOKEN, id_remoting);
  EXPECT_NE(kDummyToken, id_remoting);

  EXPECT_NE(0u, secret_remoting.size());
  EXPECT_NE(DUMMY_API_TOKEN, secret_remoting);
  EXPECT_NE(kDummyToken, secret_remoting);

  EXPECT_NE(0u, id_remoting_host.size());
  EXPECT_NE(DUMMY_API_TOKEN, id_remoting_host);
  EXPECT_NE(kDummyToken, id_remoting_host);

  EXPECT_NE(0u, secret_remoting_host.size());
  EXPECT_NE(DUMMY_API_TOKEN, secret_remoting_host);
  EXPECT_NE(kDummyToken, secret_remoting_host);
}
#endif  // defined(GOOGLE_CHROME_BUILD) || 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 GOOGLE_CHROME_BUILD
#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 google_api_keys.cc
#undef DUMMY_API_TOKEN
#undef GOOGLE_API_KEY
#undef GOOGLE_CLIENT_ID_MAIN
#undef GOOGLE_CLIENT_SECRET_MAIN
#undef GOOGLE_CLIENT_ID_CLOUD_PRINT
#undef GOOGLE_CLIENT_SECRET_CLOUD_PRINT
#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

// 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_
#include "google_apis/google_api_keys.cc"

}  // namespace default_keys

TEST_F(GoogleAPIKeysTest, DefaultKeys) {
  namespace testcase = default_keys::google_apis;

  EXPECT_FALSE(testcase::HasKeysConfigured());

  std::string api_key = testcase::g_api_key_cache.Get().api_key();
  std::string id_main = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_MAIN);
  std::string secret_main = testcase::g_api_key_cache.Get().GetClientSecret(
      testcase::CLIENT_MAIN);
  std::string id_cloud_print =
      testcase::g_api_key_cache.Get().GetClientID(
          testcase::CLIENT_CLOUD_PRINT);
  std::string secret_cloud_print =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::CLIENT_CLOUD_PRINT);
  std::string id_remoting = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_REMOTING);
  std::string secret_remoting =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::CLIENT_REMOTING);
  std::string id_remoting_host = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_REMOTING_HOST);
  std::string secret_remoting_host =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::CLIENT_REMOTING_HOST);

  EXPECT_EQ(kDummyToken, api_key);
  EXPECT_EQ(kDummyToken, id_main);
  EXPECT_EQ(kDummyToken, secret_main);
  EXPECT_EQ(kDummyToken, id_cloud_print);
  EXPECT_EQ(kDummyToken, secret_cloud_print);
  EXPECT_EQ(kDummyToken, id_remoting);
  EXPECT_EQ(kDummyToken, secret_remoting);
  EXPECT_EQ(kDummyToken, id_remoting_host);
  EXPECT_EQ(kDummyToken, 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 google_api_keys.cc
#undef DUMMY_API_TOKEN
#undef GOOGLE_API_KEY
#undef GOOGLE_CLIENT_ID_MAIN
#undef GOOGLE_CLIENT_SECRET_MAIN
#undef GOOGLE_CLIENT_ID_CLOUD_PRINT
#undef GOOGLE_CLIENT_SECRET_CLOUD_PRINT
#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"

// 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_
#include "google_apis/google_api_keys.cc"

}  // namespace override_some_keys

TEST_F(GoogleAPIKeysTest, OverrideSomeKeys) {
  namespace testcase = override_some_keys::google_apis;

  EXPECT_FALSE(testcase::HasKeysConfigured());

  std::string api_key = testcase::g_api_key_cache.Get().api_key();
  std::string id_main = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_MAIN);
  std::string secret_main = testcase::g_api_key_cache.Get().GetClientSecret(
      testcase::CLIENT_MAIN);
  std::string id_cloud_print =
      testcase::g_api_key_cache.Get().GetClientID(
          testcase::CLIENT_CLOUD_PRINT);
  std::string secret_cloud_print =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::CLIENT_CLOUD_PRINT);
  std::string id_remoting = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_REMOTING);
  std::string secret_remoting =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::CLIENT_REMOTING);
  std::string id_remoting_host = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_REMOTING_HOST);
  std::string secret_remoting_host =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::CLIENT_REMOTING_HOST);

  EXPECT_EQ("API_KEY override", api_key);
  EXPECT_EQ(kDummyToken, id_main);
  EXPECT_EQ(kDummyToken, secret_main);
  EXPECT_EQ(kDummyToken, id_cloud_print);
  EXPECT_EQ(kDummyToken, secret_cloud_print);
  EXPECT_EQ("CLIENT_ID_REMOTING override", id_remoting);
  EXPECT_EQ(kDummyToken, secret_remoting);
  EXPECT_EQ(kDummyToken, id_remoting_host);
  EXPECT_EQ(kDummyToken, 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 google_api_keys.cc
#undef DUMMY_API_TOKEN
#undef GOOGLE_API_KEY
#undef GOOGLE_CLIENT_ID_MAIN
#undef GOOGLE_CLIENT_SECRET_MAIN
#undef GOOGLE_CLIENT_ID_CLOUD_PRINT
#undef GOOGLE_CLIENT_SECRET_CLOUD_PRINT
#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_CLOUD_PRINT "ID_CLOUD_PRINT"
#define GOOGLE_CLIENT_SECRET_CLOUD_PRINT "SECRET_CLOUD_PRINT"
#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"

// 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_
#include "google_apis/google_api_keys.cc"

}  // namespace override_all_keys

TEST_F(GoogleAPIKeysTest, OverrideAllKeys) {
  namespace testcase = override_all_keys::google_apis;

  EXPECT_TRUE(testcase::HasKeysConfigured());

  std::string api_key = testcase::g_api_key_cache.Get().api_key();
  std::string id_main = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_MAIN);
  std::string secret_main = testcase::g_api_key_cache.Get().GetClientSecret(
      testcase::CLIENT_MAIN);
  std::string id_cloud_print =
      testcase::g_api_key_cache.Get().GetClientID(
          testcase::CLIENT_CLOUD_PRINT);
  std::string secret_cloud_print =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::CLIENT_CLOUD_PRINT);
  std::string id_remoting = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_REMOTING);
  std::string secret_remoting =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::CLIENT_REMOTING);
  std::string id_remoting_host = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_REMOTING_HOST);
  std::string secret_remoting_host =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::CLIENT_REMOTING_HOST);

  EXPECT_EQ("API_KEY", api_key);
  EXPECT_EQ("ID_MAIN", id_main);
  EXPECT_EQ("SECRET_MAIN", secret_main);
  EXPECT_EQ("ID_CLOUD_PRINT", id_cloud_print);
  EXPECT_EQ("SECRET_CLOUD_PRINT", secret_cloud_print);
  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);
}

// 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 google_api_keys.cc
#undef DUMMY_API_TOKEN
#undef GOOGLE_API_KEY
#undef GOOGLE_CLIENT_ID_MAIN
#undef GOOGLE_CLIENT_SECRET_MAIN
#undef GOOGLE_CLIENT_ID_CLOUD_PRINT
#undef GOOGLE_CLIENT_SECRET_CLOUD_PRINT
#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_CLOUD_PRINT "ID_CLOUD_PRINT"
#define GOOGLE_CLIENT_SECRET_CLOUD_PRINT "SECRET_CLOUD_PRINT"
#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"

// 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_
#include "google_apis/google_api_keys.cc"

}  // namespace override_all_keys_env

TEST_F(GoogleAPIKeysTest, OverrideAllKeysUsingEnvironment) {
  namespace testcase = override_all_keys_env::google_apis;

  scoped_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_CLOUD_PRINT", "env-ID_CLOUD_PRINT");
  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_CLOUD_PRINT", "env-SECRET_CLOUD_PRINT");
  env->SetVar("GOOGLE_CLIENT_SECRET_REMOTING", "env-SECRET_REMOTING");
  env->SetVar("GOOGLE_CLIENT_SECRET_REMOTING_HOST", "env-SECRET_REMOTING_HOST");

  EXPECT_TRUE(testcase::HasKeysConfigured());

  // It's important that the first call to Get() only happen after the
  // environment variables have been set.
  std::string api_key = testcase::g_api_key_cache.Get().api_key();
  std::string id_main = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_MAIN);
  std::string secret_main = testcase::g_api_key_cache.Get().GetClientSecret(
      testcase::CLIENT_MAIN);
  std::string id_cloud_print =
      testcase::g_api_key_cache.Get().GetClientID(
          testcase::CLIENT_CLOUD_PRINT);
  std::string secret_cloud_print =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::CLIENT_CLOUD_PRINT);
  std::string id_remoting = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_REMOTING);
  std::string secret_remoting =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::CLIENT_REMOTING);
  std::string id_remoting_host = testcase::g_api_key_cache.Get().GetClientID(
      testcase::CLIENT_REMOTING_HOST);
  std::string secret_remoting_host =
      testcase::g_api_key_cache.Get().GetClientSecret(
          testcase::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_CLOUD_PRINT", id_cloud_print);
  EXPECT_EQ("env-SECRET_CLOUD_PRINT", secret_cloud_print);
  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  // defined(OS_LINUX) || defined(OS_MACOSX)