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

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

Issue 2466273002: Revert of Support different Google attestation (Privacy CA) servers. (Closed)
Patch Set: 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"
7 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
8 #include "chrome/browser/chromeos/attestation/attestation_ca_client.h" 7 #include "chrome/browser/chromeos/attestation/attestation_ca_client.h"
9 #include "chromeos/chromeos_switches.h"
10 #include "content/public/test/test_browser_thread.h" 8 #include "content/public/test/test_browser_thread.h"
11 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
12 #include "net/http/http_status_code.h" 10 #include "net/http/http_status_code.h"
13 #include "net/url_request/test_url_fetcher_factory.h" 11 #include "net/url_request/test_url_fetcher_factory.h"
14 #include "net/url_request/url_fetcher.h" 12 #include "net/url_request/url_fetcher.h"
15 #include "net/url_request/url_request_status.h" 13 #include "net/url_request/url_request_status.h"
16 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
17 15
18 namespace chromeos { 16 namespace chromeos {
19 namespace attestation { 17 namespace attestation {
20 18
21 class AttestationCAClientTest : public ::testing::Test { 19 class AttestationCAClientTest : public ::testing::Test {
22 public: 20 public:
23 AttestationCAClientTest() 21 AttestationCAClientTest()
24 : io_thread_(content::BrowserThread::IO, &message_loop_), 22 : io_thread_(content::BrowserThread::IO, &message_loop_),
25 num_invocations_(0), 23 num_invocations_(0),
26 result_(false) { 24 result_(false) {
27 } 25 }
28 26
29 ~AttestationCAClientTest() override {} 27 ~AttestationCAClientTest() override {}
30 28
31 void DataCallback(bool result, const std::string& data) { 29 void DataCallback (bool result, const std::string& data) {
32 ++num_invocations_; 30 ++num_invocations_;
33 result_ = result; 31 result_ = result;
34 data_ = data; 32 data_ = data;
35 } 33 }
36 34
37 void DeleteClientDataCallback(AttestationCAClient* client, 35 void DeleteClientDataCallback (AttestationCAClient* client,
38 bool result, 36 bool result,
39 const std::string& data) { 37 const std::string& data) {
40 delete client; 38 delete client;
41 DataCallback(result, data); 39 DataCallback(result, data);
42 } 40 }
43 41
44 protected: 42 protected:
45 void SendResponse(net::Error error, int response_code) { 43 void SendResponse(net::Error error, int response_code) {
46 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 44 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
47 CHECK(fetcher); 45 CHECK(fetcher);
48 fetcher->set_status(net::URLRequestStatus::FromError(error)); 46 fetcher->set_status(net::URLRequestStatus::FromError(error));
49 fetcher->set_response_code(response_code); 47 fetcher->set_response_code(response_code);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 base::Bind(&AttestationCAClientTest::DeleteClientDataCallback, 118 base::Bind(&AttestationCAClientTest::DeleteClientDataCallback,
121 base::Unretained(this), 119 base::Unretained(this),
122 client)); 120 client));
123 SendResponse(net::OK, net::HTTP_OK); 121 SendResponse(net::OK, net::HTTP_OK);
124 122
125 EXPECT_EQ(1, num_invocations_); 123 EXPECT_EQ(1, num_invocations_);
126 EXPECT_TRUE(result_); 124 EXPECT_TRUE(result_);
127 EXPECT_EQ("certificate_response", data_); 125 EXPECT_EQ("certificate_response", data_);
128 } 126 }
129 127
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
185 } // namespace attestation 128 } // namespace attestation
186 } // namespace chromeos 129 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/attestation/attestation_ca_client.cc ('k') | chromeos/attestation/attestation_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698