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 "the-mac-key", |
| 14 "bogus-hmac-algorithm", |
| 15 "the-issuer")); |
| 16 EXPECT_FALSE(signature.AddStateInfo("", |
| 17 "the-mac-key", |
| 18 "hmac-sha-1", |
| 19 "the-issuer")); |
| 20 EXPECT_FALSE(signature.AddStateInfo("exciting-id", |
| 21 "", |
| 22 "hmac-sha-1", |
| 23 "the-issuer")); |
| 24 EXPECT_FALSE(signature.AddStateInfo("exciting-id", |
| 25 "the-mac-key", |
| 26 "", |
| 27 "the-issuer")); |
| 28 EXPECT_FALSE(signature.AddStateInfo("exciting-id", |
| 29 "the-mac-key", |
| 30 "hmac-sha-1", |
| 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 "adiMf03j0f3nOenc003r", |
| 48 "hmac-sha-1", |
| 49 "login.eXampLe.com:443")); |
| 50 EXPECT_TRUE(signature.AddHttpInfo("GeT", |
| 51 "/pAth?to=%22enlightenment%22&dest=magic", |
| 52 "eXaMple.com", |
| 53 80)); |
| 54 |
| 55 std::string timestamp = "239034"; |
| 56 std::string nonce = "mn4302j0n+32r2/f3r="; |
| 57 |
| 58 EXPECT_EQ("MAC id=\"dfoi30j0qnf\", " |
| 59 "issuer=\"login.eXampLe.com:443\", " |
| 60 "timestamp=\"239034\", " |
| 61 "nonce=\"mn4302j0n+32r2/f3r=\", " |
| 62 "mac=\"zQWLNI5eHOfY5/wCJ6yzZ8bXDw==\"", |
| 63 signature.GenerateHeaderString(timestamp, nonce)); |
| 64 } |
| 65 |
| 66 |
| 67 TEST(HttpMacSignatureTest, GenerateNormalizedRequest) { |
| 68 HttpMacSignature signature; |
| 69 EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf", |
| 70 "adiMf03j0f3nOenc003r", |
| 71 "hmac-sha-1", |
| 72 "login.eXampLe.com:443")); |
| 73 EXPECT_TRUE(signature.AddHttpInfo("GeT", |
| 74 "/pAth?to=%22enlightenment%22&dest=magic", |
| 75 "eXaMple.com", |
| 76 80)); |
| 77 |
| 78 std::string timestamp = "239034"; |
| 79 std::string nonce = "mn4302j0n+32r2/f3r="; |
| 80 |
| 81 EXPECT_EQ("dfoi30j0qnf\n" |
| 82 "login.eXampLe.com:443\n" |
| 83 "239034\n" |
| 84 "mn4302j0n+32r2/f3r=\n" |
| 85 "GET\n" |
| 86 "/pAth?to=%22enlightenment%22&dest=magic\n" |
| 87 "example.com\n" |
| 88 "80\n", |
| 89 signature.GenerateNormalizedRequest(timestamp, nonce)); |
| 90 } |
| 91 |
| 92 TEST(HttpMacSignatureTest, GenerateMAC) { |
| 93 HttpMacSignature signature; |
| 94 EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf", |
| 95 "adiMf03j0f3nOenc003r", |
| 96 "hmac-sha-1", |
| 97 "login.eXampLe.com:443")); |
| 98 EXPECT_TRUE(signature.AddHttpInfo("GeT", |
| 99 "/pAth?to=%22enlightenment%22&dest=magic", |
| 100 "eXaMple.com", |
| 101 80)); |
| 102 |
| 103 std::string timestamp = "239034"; |
| 104 std::string nonce = "mn4302j0n+32r2/f3r="; |
| 105 |
| 106 EXPECT_EQ("zQWLNI5eHOfY5/wCJ6yzZ8bXDw==", |
| 107 signature.GenerateMAC(timestamp, nonce)); |
| 108 } |
| 109 } |
OLD | NEW |