| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "testing/gtest/include/gtest/gtest.h" | |
| 6 #include "net/http/http_mac_signature.h" | |
| 7 | |
| 8 namespace net { | |
| 9 | |
| 10 TEST(HttpMacSignatureTest, BogusAddStateInfo) { | |
| 11 HttpMacSignature signature; | |
| 12 EXPECT_FALSE(signature.AddStateInfo("exciting-id", | |
| 13 base::Time::Now(), | |
| 14 "the-mac-key", | |
| 15 "bogus-hmac-algorithm")); | |
| 16 EXPECT_FALSE(signature.AddStateInfo("", | |
| 17 base::Time::Now(), | |
| 18 "the-mac-key", | |
| 19 "hmac-sha-1")); | |
| 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(), | |
| 26 "", | |
| 27 "hmac-sha-1")); | |
| 28 EXPECT_FALSE(signature.AddStateInfo("exciting-id", | |
| 29 base::Time::Now(), | |
| 30 "the-mac-key", | |
| 31 "")); | |
| 32 } | |
| 33 | |
| 34 TEST(HttpMacSignatureTest, BogusAddHttpInfo) { | |
| 35 HttpMacSignature signature; | |
| 36 EXPECT_FALSE(signature.AddHttpInfo("GET", "/requested", "example.com", 0)); | |
| 37 EXPECT_FALSE(signature.AddHttpInfo( | |
| 38 "GET", "/requested", "example.com", 29088983)); | |
| 39 EXPECT_FALSE(signature.AddHttpInfo("", "/requested", "example.com", 80)); | |
| 40 EXPECT_FALSE(signature.AddHttpInfo("GET", "", "example.com", 80)); | |
| 41 EXPECT_FALSE(signature.AddHttpInfo("GET", "/requested", "", 80)); | |
| 42 } | |
| 43 | |
| 44 TEST(HttpMacSignatureTest, GenerateHeaderString) { | |
| 45 HttpMacSignature signature; | |
| 46 EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf", | |
| 47 base::Time::Now(), | |
| 48 "adiMf03j0f3nOenc003r", | |
| 49 "hmac-sha-1")); | |
| 50 EXPECT_TRUE(signature.AddHttpInfo("GeT", | |
| 51 "/pAth?to=%22enlightenment%22&dest=magic", | |
| 52 "eXaMple.com", | |
| 53 80)); | |
| 54 | |
| 55 std::string age = "239034"; | |
| 56 std::string nonce = "mn4302j0n+32r2/f3r="; | |
| 57 | |
| 58 std::string header_string; | |
| 59 EXPECT_TRUE(signature.GenerateHeaderString(age, nonce, &header_string)); | |
| 60 EXPECT_EQ("MAC id=\"dfoi30j0qnf\", " | |
| 61 "nonce=\"239034:mn4302j0n+32r2/f3r=\", " | |
| 62 "mac=\"GrkHtPKzB1m1dCHfa7OCWOw6Ecw=\"", | |
| 63 header_string); | |
| 64 } | |
| 65 | |
| 66 | |
| 67 TEST(HttpMacSignatureTest, GenerateNormalizedRequest) { | |
| 68 HttpMacSignature signature; | |
| 69 EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf", | |
| 70 base::Time::Now(), | |
| 71 "adiMf03j0f3nOenc003r", | |
| 72 "hmac-sha-1")); | |
| 73 EXPECT_TRUE(signature.AddHttpInfo("GeT", | |
| 74 "/pAth?to=%22enlightenment%22&dest=magic", | |
| 75 "eXaMple.com", | |
| 76 80)); | |
| 77 | |
| 78 std::string age = "239034"; | |
| 79 std::string nonce = "mn4302j0n+32r2/f3r="; | |
| 80 | |
| 81 EXPECT_EQ("239034:mn4302j0n+32r2/f3r=\n" | |
| 82 "GET\n" | |
| 83 "/pAth?to=%22enlightenment%22&dest=magic\n" | |
| 84 "example.com\n" | |
| 85 "80\n" | |
| 86 "\n" | |
| 87 "\n", | |
| 88 signature.GenerateNormalizedRequest(age, nonce)); | |
| 89 } | |
| 90 | |
| 91 TEST(HttpMacSignatureTest, GenerateMAC) { | |
| 92 HttpMacSignature signature; | |
| 93 EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf", | |
| 94 base::Time::Now(), | |
| 95 "adiMf03j0f3nOenc003r", | |
| 96 "hmac-sha-1")); | |
| 97 EXPECT_TRUE(signature.AddHttpInfo("GeT", | |
| 98 "/pAth?to=%22enlightenment%22&dest=magic", | |
| 99 "eXaMple.com", | |
| 100 80)); | |
| 101 | |
| 102 std::string age = "239034"; | |
| 103 std::string nonce = "mn4302j0n+32r2/f3r="; | |
| 104 | |
| 105 std::string mac; | |
| 106 EXPECT_TRUE(signature.GenerateMAC(age, nonce, &mac)); | |
| 107 EXPECT_EQ("GrkHtPKzB1m1dCHfa7OCWOw6Ecw=", mac); | |
| 108 } | |
| 109 } | |
| OLD | NEW |