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

Side by Side Diff: chrome/browser/local_discovery/privetv3_session_unittest.cc

Issue 880373004: Implement of privet/v3/auth after pairing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patches
Patch Set: Fri Jan 30 02:24:45 PST 2015 Created 5 years, 10 months 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
« no previous file with comments | « chrome/browser/local_discovery/privetv3_session.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/local_discovery/privetv3_session.h" 5 #include "chrome/browser/local_discovery/privetv3_session.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/local_discovery/privet_http.h" 9 #include "chrome/browser/local_discovery/privet_http.h"
10 #include "content/public/test/test_utils.h" 10 #include "content/public/test/test_utils.h"
11 #include "crypto/hmac.h" 11 #include "crypto/hmac.h"
12 #include "crypto/p224_spake.h" 12 #include "crypto/p224_spake.h"
13 #include "net/url_request/test_url_fetcher_factory.h" 13 #include "net/url_request/test_url_fetcher_factory.h"
14 #include "net/url_request/url_request_test_util.h" 14 #include "net/url_request/url_request_test_util.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace local_discovery { 18 namespace local_discovery {
19 19
20 namespace { 20 namespace {
21 21
22 using testing::InSequence;
22 using testing::Invoke; 23 using testing::Invoke;
23 using testing::SaveArg; 24 using testing::SaveArg;
24 using testing::StrictMock; 25 using testing::StrictMock;
25 using testing::_; 26 using testing::_;
26 27
27 using PairingType = PrivetV3Session::PairingType; 28 using PairingType = PrivetV3Session::PairingType;
28 using Result = PrivetV3Session::Result; 29 using Result = PrivetV3Session::Result;
29 30
30 const char kInfoResponse[] = 31 const char kInfoResponse[] =
31 "{\"version\":\"3.0\"," 32 "{\"version\":\"3.0\","
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 base::StringPrintf( 176 base::StringPrintf(
176 "{\"deviceCommitment\":\"%s\",\"sessionId\":\"testId\"}", 177 "{\"deviceCommitment\":\"%s\",\"sessionId\":\"testId\"}",
177 device_commitment.c_str()), 178 device_commitment.c_str()),
178 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 179 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
179 })); 180 }));
180 session_.StartPairing(PairingType::PAIRING_TYPE_EMBEDDEDCODE, 181 session_.StartPairing(PairingType::PAIRING_TYPE_EMBEDDEDCODE,
181 base::Bind(&PrivetV3SessionTest::OnPairingStarted, 182 base::Bind(&PrivetV3SessionTest::OnPairingStarted,
182 base::Unretained(this))); 183 base::Unretained(this)));
183 base::RunLoop().RunUntilIdle(); 184 base::RunLoop().RunUntilIdle();
184 185
186 EXPECT_TRUE(session_.fingerprint_.empty());
187 EXPECT_EQ("Privet anonymous", session_.privet_auth_token_);
188
185 EXPECT_CALL(*this, OnCodeConfirmed(Result::STATUS_SUCCESS)).Times(1); 189 EXPECT_CALL(*this, OnCodeConfirmed(Result::STATUS_SUCCESS)).Times(1);
190 InSequence in_sequence;
186 EXPECT_CALL(*this, OnPostData(_)) 191 EXPECT_CALL(*this, OnPostData(_))
187 .WillOnce( 192 .WillOnce(
188 testing::Invoke([this, &spake](const base::DictionaryValue& data) { 193 testing::Invoke([this, &spake](const base::DictionaryValue& data) {
189 std::string commitment_base64; 194 std::string commitment_base64;
190 EXPECT_TRUE(data.GetString("clientCommitment", &commitment_base64)); 195 EXPECT_TRUE(data.GetString("clientCommitment", &commitment_base64));
191 std::string commitment; 196 std::string commitment;
192 EXPECT_TRUE(base::Base64Decode(commitment_base64, &commitment)); 197 EXPECT_TRUE(base::Base64Decode(commitment_base64, &commitment));
193 198
194 std::string session_id; 199 std::string session_id;
195 EXPECT_TRUE(data.GetString("sessionId", &session_id)); 200 EXPECT_TRUE(data.GetString("sessionId", &session_id));
(...skipping 17 matching lines...) Expand all
213 std::string signature_base64; 218 std::string signature_base64;
214 base::Base64Encode(signature, &signature_base64); 219 base::Base64Encode(signature, &signature_base64);
215 220
216 fetcher_factory_.SetFakeResponse( 221 fetcher_factory_.SetFakeResponse(
217 GURL("http://host/privet/v3/pairing/confirm"), 222 GURL("http://host/privet/v3/pairing/confirm"),
218 base::StringPrintf( 223 base::StringPrintf(
219 "{\"certFingerprint\":\"%s\",\"certSignature\":\"%s\"}", 224 "{\"certFingerprint\":\"%s\",\"certSignature\":\"%s\"}",
220 fingerprint_base64.c_str(), signature_base64.c_str()), 225 fingerprint_base64.c_str(), signature_base64.c_str()),
221 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 226 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
222 })); 227 }));
228 EXPECT_CALL(*this, OnPostData(_))
229 .WillOnce(
230 testing::Invoke([this, &spake](const base::DictionaryValue& data) {
231 std::string access_token_base64;
232 EXPECT_TRUE(data.GetString("authCode", &access_token_base64));
233 std::string access_token;
234 EXPECT_TRUE(base::Base64Decode(access_token_base64, &access_token));
235
236 crypto::HMAC hmac(crypto::HMAC::SHA256);
237 const std::string& key = spake.GetUnverifiedKey();
238 EXPECT_TRUE(hmac.Init(key));
239 EXPECT_TRUE(hmac.Verify("testId", access_token));
240
241 fetcher_factory_.SetFakeResponse(
242 GURL("http://host/privet/v3/auth"),
243 "{\"accessToken\":\"567\",\"tokenType\":\"testType\","
244 "\"scope\":\"owner\"}",
245 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
246 }));
223 session_.ConfirmCode("testPin", 247 session_.ConfirmCode("testPin",
224 base::Bind(&PrivetV3SessionTest::OnCodeConfirmed, 248 base::Bind(&PrivetV3SessionTest::OnCodeConfirmed,
225 base::Unretained(this))); 249 base::Unretained(this)));
226 base::RunLoop().RunUntilIdle(); 250 base::RunLoop().RunUntilIdle();
251
252 EXPECT_FALSE(session_.fingerprint_.empty());
253 EXPECT_EQ("testType 567", session_.privet_auth_token_);
227 } 254 }
228 255
229 // TODO(vitalybuka): replace PrivetHTTPClient with regular URL fetcher and 256 // TODO(vitalybuka): replace PrivetHTTPClient with regular URL fetcher and
230 // implement SendMessage test. 257 // implement SendMessage test.
231 258
232 } // namespace local_discovery 259 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/privetv3_session.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698