OLD | NEW |
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) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 "adiMf03j0f3nOenc003r", | 48 "adiMf03j0f3nOenc003r", |
49 "hmac-sha-1")); | 49 "hmac-sha-1")); |
50 EXPECT_TRUE(signature.AddHttpInfo("GeT", | 50 EXPECT_TRUE(signature.AddHttpInfo("GeT", |
51 "/pAth?to=%22enlightenment%22&dest=magic", | 51 "/pAth?to=%22enlightenment%22&dest=magic", |
52 "eXaMple.com", | 52 "eXaMple.com", |
53 80)); | 53 80)); |
54 | 54 |
55 std::string age = "239034"; | 55 std::string age = "239034"; |
56 std::string nonce = "mn4302j0n+32r2/f3r="; | 56 std::string nonce = "mn4302j0n+32r2/f3r="; |
57 | 57 |
| 58 std::string header_string; |
| 59 EXPECT_TRUE(signature.GenerateHeaderString(age, nonce, &header_string)); |
58 EXPECT_EQ("MAC id=\"dfoi30j0qnf\", " | 60 EXPECT_EQ("MAC id=\"dfoi30j0qnf\", " |
59 "nonce=\"239034:mn4302j0n+32r2/f3r=\", " | 61 "nonce=\"239034:mn4302j0n+32r2/f3r=\", " |
60 "mac=\"GrkHtPKzB1m1dCHfa7OCWOw6EQ==\"", | 62 "mac=\"GrkHtPKzB1m1dCHfa7OCWOw6EQ==\"", |
61 signature.GenerateHeaderString(age, nonce)); | 63 header_string); |
62 } | 64 } |
63 | 65 |
64 | 66 |
65 TEST(HttpMacSignatureTest, GenerateNormalizedRequest) { | 67 TEST(HttpMacSignatureTest, GenerateNormalizedRequest) { |
66 HttpMacSignature signature; | 68 HttpMacSignature signature; |
67 EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf", | 69 EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf", |
68 base::Time::Now(), | 70 base::Time::Now(), |
69 "adiMf03j0f3nOenc003r", | 71 "adiMf03j0f3nOenc003r", |
70 "hmac-sha-1")); | 72 "hmac-sha-1")); |
71 EXPECT_TRUE(signature.AddHttpInfo("GeT", | 73 EXPECT_TRUE(signature.AddHttpInfo("GeT", |
(...skipping 21 matching lines...) Expand all Loading... |
93 "adiMf03j0f3nOenc003r", | 95 "adiMf03j0f3nOenc003r", |
94 "hmac-sha-1")); | 96 "hmac-sha-1")); |
95 EXPECT_TRUE(signature.AddHttpInfo("GeT", | 97 EXPECT_TRUE(signature.AddHttpInfo("GeT", |
96 "/pAth?to=%22enlightenment%22&dest=magic", | 98 "/pAth?to=%22enlightenment%22&dest=magic", |
97 "eXaMple.com", | 99 "eXaMple.com", |
98 80)); | 100 80)); |
99 | 101 |
100 std::string age = "239034"; | 102 std::string age = "239034"; |
101 std::string nonce = "mn4302j0n+32r2/f3r="; | 103 std::string nonce = "mn4302j0n+32r2/f3r="; |
102 | 104 |
103 EXPECT_EQ("GrkHtPKzB1m1dCHfa7OCWOw6EQ==", | 105 std::string mac; |
104 signature.GenerateMAC(age, nonce)); | 106 EXPECT_TRUE(signature.GenerateMAC(age, nonce, &mac)); |
| 107 EXPECT_EQ("GrkHtPKzB1m1dCHfa7OCWOw6EQ==", mac); |
105 } | 108 } |
106 } | 109 } |
OLD | NEW |