Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: chrome/browser/chromeos/attestation/attestation_ca_client_unittest.cc

Issue 2448213007: Support different Google attestation (Privacy CA) servers. (Closed)
Patch Set: Up to date w/ master. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h"
6 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
7 #include "chrome/browser/chromeos/attestation/attestation_ca_client.h" 8 #include "chrome/browser/chromeos/attestation/attestation_ca_client.h"
9 #include "chromeos/chromeos_switches.h"
8 #include "content/public/test/test_browser_thread.h" 10 #include "content/public/test/test_browser_thread.h"
9 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
10 #include "net/http/http_status_code.h" 12 #include "net/http/http_status_code.h"
11 #include "net/url_request/test_url_fetcher_factory.h" 13 #include "net/url_request/test_url_fetcher_factory.h"
12 #include "net/url_request/url_fetcher.h" 14 #include "net/url_request/url_fetcher.h"
13 #include "net/url_request/url_request_status.h" 15 #include "net/url_request/url_request_status.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 namespace chromeos { 18 namespace chromeos {
17 namespace attestation { 19 namespace attestation {
18 20
19 class AttestationCAClientTest : public ::testing::Test { 21 class AttestationCAClientTest : public ::testing::Test {
20 public: 22 public:
21 AttestationCAClientTest() 23 AttestationCAClientTest()
22 : io_thread_(content::BrowserThread::IO, &message_loop_), 24 : io_thread_(content::BrowserThread::IO, &message_loop_),
23 num_invocations_(0), 25 num_invocations_(0),
24 result_(false) { 26 result_(false) {
25 } 27 }
26 28
27 ~AttestationCAClientTest() override {} 29 ~AttestationCAClientTest() override {}
28 30
29 void DataCallback (bool result, const std::string& data) { 31 void DataCallback(bool result, const std::string& data) {
30 ++num_invocations_; 32 ++num_invocations_;
31 result_ = result; 33 result_ = result;
32 data_ = data; 34 data_ = data;
33 } 35 }
34 36
35 void DeleteClientDataCallback (AttestationCAClient* client, 37 void DeleteClientDataCallback(AttestationCAClient* client,
36 bool result, 38 bool result,
37 const std::string& data) { 39 const std::string& data) {
38 delete client; 40 delete client;
39 DataCallback(result, data); 41 DataCallback(result, data);
40 } 42 }
41 43
42 protected: 44 protected:
43 void SendResponse(net::Error error, int response_code) { 45 void SendResponse(net::Error error, int response_code) {
44 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 46 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
45 CHECK(fetcher); 47 CHECK(fetcher);
46 fetcher->set_status(net::URLRequestStatus::FromError(error)); 48 fetcher->set_status(net::URLRequestStatus::FromError(error));
47 fetcher->set_response_code(response_code); 49 fetcher->set_response_code(response_code);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 base::Bind(&AttestationCAClientTest::DeleteClientDataCallback, 120 base::Bind(&AttestationCAClientTest::DeleteClientDataCallback,
119 base::Unretained(this), 121 base::Unretained(this),
120 client)); 122 client));
121 SendResponse(net::OK, net::HTTP_OK); 123 SendResponse(net::OK, net::HTTP_OK);
122 124
123 EXPECT_EQ(1, num_invocations_); 125 EXPECT_EQ(1, num_invocations_);
124 EXPECT_TRUE(result_); 126 EXPECT_TRUE(result_);
125 EXPECT_EQ("certificate_response", data_); 127 EXPECT_EQ("certificate_response", data_);
126 } 128 }
127 129
130 class AttestationCAClientAttestationServerTest
131 : public AttestationCAClientTest {};
132
133 TEST_F(AttestationCAClientAttestationServerTest, DefaultEnrollRequest) {
134 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
135 chromeos::switches::kAttestationServer, "default");
136 AttestationCAClient client;
137 client.SendEnrollRequest("enroll",
138 base::Bind(&AttestationCAClientTest::DataCallback,
139 base::Unretained(this)));
140 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
141 CHECK(fetcher);
142 EXPECT_EQ(GURL("https://chromeos-ca.gstatic.com/enroll"),
143 fetcher->GetOriginalURL());
144 }
145
146 TEST_F(AttestationCAClientAttestationServerTest, DefaultCertificateRequest) {
147 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
148 chromeos::switches::kAttestationServer, "default");
149 AttestationCAClient client;
150 client.SendCertificateRequest(
151 "certificate", base::Bind(&AttestationCAClientTest::DataCallback,
152 base::Unretained(this)));
153 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
154 CHECK(fetcher);
155 EXPECT_EQ(GURL("https://chromeos-ca.gstatic.com/sign"),
156 fetcher->GetOriginalURL());
157 }
158
159 TEST_F(AttestationCAClientAttestationServerTest, TestEnrollRequest) {
160 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
161 chromeos::switches::kAttestationServer, "test");
162 AttestationCAClient client;
163 client.SendEnrollRequest("enroll",
164 base::Bind(&AttestationCAClientTest::DataCallback,
165 base::Unretained(this)));
166 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
167 CHECK(fetcher);
168 EXPECT_EQ(GURL("https://asbestos-qa.corp.google.com/enroll"),
169 fetcher->GetOriginalURL());
170 }
171
172 TEST_F(AttestationCAClientAttestationServerTest, TestCertificateRequest) {
173 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
174 chromeos::switches::kAttestationServer, "test");
175 AttestationCAClient client;
176 client.SendCertificateRequest(
177 "certificate", base::Bind(&AttestationCAClientTest::DataCallback,
178 base::Unretained(this)));
179 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
180 CHECK(fetcher);
181 EXPECT_EQ(GURL("https://asbestos-qa.corp.google.com/sign"),
182 fetcher->GetOriginalURL());
183 }
184
128 } // namespace attestation 185 } // namespace attestation
129 } // namespace chromeos 186 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698