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

Side by Side Diff: net/http/http_mac_signature_unittest.cc

Issue 6969075: MAC Cookies (patch 5 of N) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_mac_signature.cc ('k') | net/url_request/url_request_http_job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "net/http/http_mac_signature.h" 6 #include "net/http/http_mac_signature.h"
7 7
8 namespace net { 8 namespace net {
9 9
10 TEST(HttpMacSignatureTest, BogusAddStateInfo) { 10 TEST(HttpMacSignatureTest, BogusAddStateInfo) {
11 HttpMacSignature signature; 11 HttpMacSignature signature;
12 EXPECT_FALSE(signature.AddStateInfo("exciting-id", 12 EXPECT_FALSE(signature.AddStateInfo("exciting-id",
13 base::Time::Now(),
13 "the-mac-key", 14 "the-mac-key",
14 "bogus-hmac-algorithm")); 15 "bogus-hmac-algorithm"));
15 EXPECT_FALSE(signature.AddStateInfo("", 16 EXPECT_FALSE(signature.AddStateInfo("",
17 base::Time::Now(),
16 "the-mac-key", 18 "the-mac-key",
17 "hmac-sha-1")); 19 "hmac-sha-1"));
18 EXPECT_FALSE(signature.AddStateInfo("exciting-id", 20 EXPECT_FALSE(signature.AddStateInfo("exciting-id",
21 base::Time(),
22 "the-mac-key",
23 "hmac-sha-1"));
24 EXPECT_FALSE(signature.AddStateInfo("exciting-id",
25 base::Time::Now(),
Randy Smith (Not in Mondays) 2011/05/16 20:06:46 Just for my curiosity, why the extra test for this
abarth-chromium 2011/05/16 20:13:15 Oh, I added a branch in the implementation. This
19 "", 26 "",
20 "hmac-sha-1")); 27 "hmac-sha-1"));
21 EXPECT_FALSE(signature.AddStateInfo("exciting-id", 28 EXPECT_FALSE(signature.AddStateInfo("exciting-id",
29 base::Time::Now(),
22 "the-mac-key", 30 "the-mac-key",
23 "")); 31 ""));
24 } 32 }
25 33
26 TEST(HttpMacSignatureTest, BogusAddHttpInfo) { 34 TEST(HttpMacSignatureTest, BogusAddHttpInfo) {
27 HttpMacSignature signature; 35 HttpMacSignature signature;
28 EXPECT_FALSE(signature.AddHttpInfo("GET", "/requested", "example.com", 0)); 36 EXPECT_FALSE(signature.AddHttpInfo("GET", "/requested", "example.com", 0));
29 EXPECT_FALSE(signature.AddHttpInfo( 37 EXPECT_FALSE(signature.AddHttpInfo(
30 "GET", "/requested", "example.com", 29088983)); 38 "GET", "/requested", "example.com", 29088983));
31 EXPECT_FALSE(signature.AddHttpInfo("", "/requested", "example.com", 80)); 39 EXPECT_FALSE(signature.AddHttpInfo("", "/requested", "example.com", 80));
32 EXPECT_FALSE(signature.AddHttpInfo("GET", "", "example.com", 80)); 40 EXPECT_FALSE(signature.AddHttpInfo("GET", "", "example.com", 80));
33 EXPECT_FALSE(signature.AddHttpInfo("GET", "/requested", "", 80)); 41 EXPECT_FALSE(signature.AddHttpInfo("GET", "/requested", "", 80));
34 } 42 }
35 43
36 TEST(HttpMacSignatureTest, GenerateHeaderString) { 44 TEST(HttpMacSignatureTest, GenerateHeaderString) {
37 HttpMacSignature signature; 45 HttpMacSignature signature;
38 EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf", 46 EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf",
47 base::Time::Now(),
39 "adiMf03j0f3nOenc003r", 48 "adiMf03j0f3nOenc003r",
40 "hmac-sha-1")); 49 "hmac-sha-1"));
41 EXPECT_TRUE(signature.AddHttpInfo("GeT", 50 EXPECT_TRUE(signature.AddHttpInfo("GeT",
42 "/pAth?to=%22enlightenment%22&dest=magic", 51 "/pAth?to=%22enlightenment%22&dest=magic",
43 "eXaMple.com", 52 "eXaMple.com",
44 80)); 53 80));
45 54
46 std::string timestamp = "239034"; 55 std::string age = "239034";
47 std::string nonce = "mn4302j0n+32r2/f3r="; 56 std::string nonce = "mn4302j0n+32r2/f3r=";
48 57
49 EXPECT_EQ("MAC id=\"dfoi30j0qnf\", " 58 EXPECT_EQ("MAC id=\"dfoi30j0qnf\", "
50 "nonce=\"239034:mn4302j0n+32r2/f3r=\", " 59 "nonce=\"239034:mn4302j0n+32r2/f3r=\", "
51 "mac=\"GrkHtPKzB1m1dCHfa7OCWOw6EQ==\"", 60 "mac=\"GrkHtPKzB1m1dCHfa7OCWOw6EQ==\"",
52 signature.GenerateHeaderString(timestamp, nonce)); 61 signature.GenerateHeaderString(age, nonce));
53 } 62 }
54 63
55 64
56 TEST(HttpMacSignatureTest, GenerateNormalizedRequest) { 65 TEST(HttpMacSignatureTest, GenerateNormalizedRequest) {
57 HttpMacSignature signature; 66 HttpMacSignature signature;
58 EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf", 67 EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf",
68 base::Time::Now(),
59 "adiMf03j0f3nOenc003r", 69 "adiMf03j0f3nOenc003r",
60 "hmac-sha-1")); 70 "hmac-sha-1"));
61 EXPECT_TRUE(signature.AddHttpInfo("GeT", 71 EXPECT_TRUE(signature.AddHttpInfo("GeT",
62 "/pAth?to=%22enlightenment%22&dest=magic", 72 "/pAth?to=%22enlightenment%22&dest=magic",
63 "eXaMple.com", 73 "eXaMple.com",
64 80)); 74 80));
65 75
66 std::string timestamp = "239034"; 76 std::string age = "239034";
67 std::string nonce = "mn4302j0n+32r2/f3r="; 77 std::string nonce = "mn4302j0n+32r2/f3r=";
68 78
69 EXPECT_EQ("239034:mn4302j0n+32r2/f3r=\n" 79 EXPECT_EQ("239034:mn4302j0n+32r2/f3r=\n"
70 "GET\n" 80 "GET\n"
71 "/pAth?to=%22enlightenment%22&dest=magic\n" 81 "/pAth?to=%22enlightenment%22&dest=magic\n"
72 "example.com\n" 82 "example.com\n"
73 "80\n" 83 "80\n"
74 "\n" 84 "\n"
75 "\n", 85 "\n",
76 signature.GenerateNormalizedRequest(timestamp, nonce)); 86 signature.GenerateNormalizedRequest(age, nonce));
77 } 87 }
78 88
79 TEST(HttpMacSignatureTest, GenerateMAC) { 89 TEST(HttpMacSignatureTest, GenerateMAC) {
80 HttpMacSignature signature; 90 HttpMacSignature signature;
81 EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf", 91 EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf",
92 base::Time::Now(),
82 "adiMf03j0f3nOenc003r", 93 "adiMf03j0f3nOenc003r",
83 "hmac-sha-1")); 94 "hmac-sha-1"));
84 EXPECT_TRUE(signature.AddHttpInfo("GeT", 95 EXPECT_TRUE(signature.AddHttpInfo("GeT",
85 "/pAth?to=%22enlightenment%22&dest=magic", 96 "/pAth?to=%22enlightenment%22&dest=magic",
86 "eXaMple.com", 97 "eXaMple.com",
87 80)); 98 80));
88 99
89 std::string timestamp = "239034"; 100 std::string age = "239034";
90 std::string nonce = "mn4302j0n+32r2/f3r="; 101 std::string nonce = "mn4302j0n+32r2/f3r=";
91 102
92 EXPECT_EQ("GrkHtPKzB1m1dCHfa7OCWOw6EQ==", 103 EXPECT_EQ("GrkHtPKzB1m1dCHfa7OCWOw6EQ==",
93 signature.GenerateMAC(timestamp, nonce)); 104 signature.GenerateMAC(age, nonce));
94 } 105 }
95 } 106 }
OLDNEW
« no previous file with comments | « net/http/http_mac_signature.cc ('k') | net/url_request/url_request_http_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698