1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "testing/gtest/include/gtest/gtest.h"
#include "net/http/http_mac_signature.h"
namespace net {
TEST(HttpMacSignatureTest, BogusAddStateInfo) {
HttpMacSignature signature;
EXPECT_FALSE(signature.AddStateInfo("exciting-id",
"the-mac-key",
"bogus-hmac-algorithm",
"the-issuer"));
EXPECT_FALSE(signature.AddStateInfo("",
"the-mac-key",
"hmac-sha-1",
"the-issuer"));
EXPECT_FALSE(signature.AddStateInfo("exciting-id",
"",
"hmac-sha-1",
"the-issuer"));
EXPECT_FALSE(signature.AddStateInfo("exciting-id",
"the-mac-key",
"",
"the-issuer"));
EXPECT_FALSE(signature.AddStateInfo("exciting-id",
"the-mac-key",
"hmac-sha-1",
""));
}
TEST(HttpMacSignatureTest, BogusAddHttpInfo) {
HttpMacSignature signature;
EXPECT_FALSE(signature.AddHttpInfo("GET", "/requested", "example.com", 0));
EXPECT_FALSE(signature.AddHttpInfo(
"GET", "/requested", "example.com", 29088983));
EXPECT_FALSE(signature.AddHttpInfo("", "/requested", "example.com", 80));
EXPECT_FALSE(signature.AddHttpInfo("GET", "", "example.com", 80));
EXPECT_FALSE(signature.AddHttpInfo("GET", "/requested", "", 80));
}
TEST(HttpMacSignatureTest, GenerateHeaderString) {
HttpMacSignature signature;
EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf",
"adiMf03j0f3nOenc003r",
"hmac-sha-1",
"login.eXampLe.com:443"));
EXPECT_TRUE(signature.AddHttpInfo("GeT",
"/pAth?to=%22enlightenment%22&dest=magic",
"eXaMple.com",
80));
std::string timestamp = "239034";
std::string nonce = "mn4302j0n+32r2/f3r=";
EXPECT_EQ("MAC id=\"dfoi30j0qnf\", "
"issuer=\"login.eXampLe.com:443\", "
"timestamp=\"239034\", "
"nonce=\"mn4302j0n+32r2/f3r=\", "
"mac=\"zQWLNI5eHOfY5/wCJ6yzZ8bXDw==\"",
signature.GenerateHeaderString(timestamp, nonce));
}
TEST(HttpMacSignatureTest, GenerateNormalizedRequest) {
HttpMacSignature signature;
EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf",
"adiMf03j0f3nOenc003r",
"hmac-sha-1",
"login.eXampLe.com:443"));
EXPECT_TRUE(signature.AddHttpInfo("GeT",
"/pAth?to=%22enlightenment%22&dest=magic",
"eXaMple.com",
80));
std::string timestamp = "239034";
std::string nonce = "mn4302j0n+32r2/f3r=";
EXPECT_EQ("dfoi30j0qnf\n"
"login.eXampLe.com:443\n"
"239034\n"
"mn4302j0n+32r2/f3r=\n"
"GET\n"
"/pAth?to=%22enlightenment%22&dest=magic\n"
"example.com\n"
"80\n",
signature.GenerateNormalizedRequest(timestamp, nonce));
}
TEST(HttpMacSignatureTest, GenerateMAC) {
HttpMacSignature signature;
EXPECT_TRUE(signature.AddStateInfo("dfoi30j0qnf",
"adiMf03j0f3nOenc003r",
"hmac-sha-1",
"login.eXampLe.com:443"));
EXPECT_TRUE(signature.AddHttpInfo("GeT",
"/pAth?to=%22enlightenment%22&dest=magic",
"eXaMple.com",
80));
std::string timestamp = "239034";
std::string nonce = "mn4302j0n+32r2/f3r=";
EXPECT_EQ("zQWLNI5eHOfY5/wCJ6yzZ8bXDw==",
signature.GenerateMAC(timestamp, nonce));
}
}
|