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

Side by Side Diff: chrome/browser/net/spdyproxy/http_auth_handler_spdyproxy_unittest.cc

Issue 10913238: SPDY proxy authentication support. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Formatting fixups. Created 8 years, 2 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "chrome/browser/net/spdyproxy/http_auth_handler_spdyproxy.h"
6
7 #include <string>
8
9 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h"
13 #include "net/base/net_errors.h"
14 #include "net/http/http_request_info.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace {
18
19 const char kValidOrigin[] = "https://www.proxy.com/";
20 const char kValidChallenge[] = "SpdyProxy realm=\"SpdyProxy\", "
21 "ps=\"1-2-3-4\"";
22
23 } // namespace
24
25 namespace spdyproxy {
26
27 using net::ERR_INVALID_RESPONSE;
28 using net::ERR_UNSUPPORTED_AUTH_SCHEME;
29 using net::OK;
30 using net::AuthCredentials;
31 using net::BoundNetLog;
32 using net::CompletionCallback;
33 using net::Error;
34 using net::HttpAuth;
35 using net::HttpAuthHandler;
36 using net::HttpRequestInfo;
37
38 TEST(HttpAuthHandlerSpdyProxyTest, GenerateAuthToken) {
39 // Verifies that challenge parsing is expected as described in individual
40 // cases below.
41 static const struct {
42 Error err1, err2;
43 const char* origin;
44 const char* challenge;
45 const char* username;
46 const char* sid;
47 const char* expected_credentials;
48 } tests[] = {
49 // A well-formed challenge where a sid is provided produces a valid
50 // response header echoing the sid and ps token.
51 { OK, OK,
52 kValidOrigin,
53 kValidChallenge,
54 "",
55 "sid-string",
56 "SpdyProxy ps=\"1-2-3-4\", sid=\"sid-string\"",},
57
58 // A non-SSL origin returns ERR_UNSUPPORTED_AUTH_SCHEME.
59 { ERR_UNSUPPORTED_AUTH_SCHEME, OK,
60 "http://www.proxy.com/", "", "", "", "",},
61
62 // An SSL origin not matching the authorized origin returns
63 // ERR_UNSUPPORTED_AUTH_SCHEME.
64 { ERR_UNSUPPORTED_AUTH_SCHEME, OK,
65 "https://www.unconfigured.com/", "", "", "", "",},
66
67 // Absent ps token yields ERR_INVALID_RESPONSE.
68 { ERR_INVALID_RESPONSE, OK,
69 kValidOrigin, "SpdyProxy realm=\"SpdyProxy\"", "", "", "",},
70 };
71 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
72 GURL origin(tests[i].origin);
73 GURL authorized_origin(kValidOrigin);
74 HttpAuthHandlerSpdyProxy::Factory factory(authorized_origin);
75 scoped_ptr<HttpAuthHandler> spdyproxy;
76 EXPECT_EQ(tests[i].err1, factory.CreateAuthHandlerFromString(
77 tests[i].challenge, HttpAuth::AUTH_PROXY, origin, BoundNetLog(),
78 &spdyproxy));
79 if (tests[i].err1 != OK) {
80 continue;
81 }
82 AuthCredentials credentials(ASCIIToUTF16(tests[i].username),
83 ASCIIToUTF16(tests[i].sid));
84 HttpRequestInfo request_info;
85 std::string auth_token;
86 int rv = spdyproxy->GenerateAuthToken(&credentials, &request_info,
87 CompletionCallback(), &auth_token);
88 EXPECT_EQ(tests[i].err2, rv);
89 if (tests[i].err2 != OK) {
90 continue;
91 }
92 EXPECT_STREQ(tests[i].expected_credentials, auth_token.c_str());
93 }
94 }
95
96 TEST(HttpAuthHandlerSpdyProxyTest, NonProxyAuthTypeFails) {
97 // Verifies that an authorization request fails if requested by an ordinary
98 // site. (i.e., HttpAuth::AUTH_SERVER)
99 GURL origin(kValidOrigin);
100 GURL accepted_origin(kValidOrigin);
101 HttpAuthHandlerSpdyProxy::Factory factory(accepted_origin);
102 scoped_ptr<HttpAuthHandler> spdyproxy;
103 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, factory.CreateAuthHandlerFromString(
104 kValidChallenge, HttpAuth::AUTH_SERVER, origin,
105 BoundNetLog(), &spdyproxy));
106 }
107
108 TEST(HttpAuthHandlerSpdyProxyTest, HandleAnotherChallenge) {
109 // Verifies that any repeat challenge is treated as a failure.
110 GURL origin(kValidOrigin);
111 GURL accepted_origin(kValidOrigin);
112 HttpAuthHandlerSpdyProxy::Factory factory(accepted_origin);
113 scoped_ptr<HttpAuthHandler> spdyproxy;
114 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString(
115 kValidChallenge, HttpAuth::AUTH_PROXY, origin,
116 BoundNetLog(), &spdyproxy));
117 std::string challenge(kValidChallenge);
118 HttpAuth::ChallengeTokenizer tok(challenge.begin(),
119 challenge.end());
120 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT,
121 spdyproxy->HandleAnotherChallenge(&tok));
122 }
123
124 TEST(HttpAuthHandlerSpdyProxyTest, ParseChallenge) {
125 // Verifies that various challenge strings are parsed appropriately as
126 // described below.
127 static const struct {
128 const char* challenge;
129 int expected_rv;
130 const char* expected_ps;
131 const char* expected_realm;
132 } tests[] = {
133 // Absent parameters fails.
134 { "SpdyProxy", ERR_INVALID_RESPONSE, "", "", },
135
136 // Empty parameters fails.
137 { "SpdyProxy ps=\"\"", ERR_INVALID_RESPONSE, "", "", },
138
139 // Valid challenge parses successfully.
140 { kValidChallenge, OK, "1-2-3-4", "SpdyProxy", },
141 };
142 GURL origin(kValidOrigin);
143 GURL accepted_origin(kValidOrigin);
144 HttpAuthHandlerSpdyProxy::Factory factory(accepted_origin);
145 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
146 std::string challenge = tests[i].challenge;
147 scoped_ptr<HttpAuthHandler> spdyproxy;
148 int rv = factory.CreateAuthHandlerFromString(
149 challenge, HttpAuth::AUTH_PROXY, origin, BoundNetLog(), &spdyproxy);
150 EXPECT_EQ(tests[i].expected_rv, rv);
151 if (rv == OK) {
152 EXPECT_EQ(tests[i].expected_realm, spdyproxy->realm());
153 HttpAuthHandlerSpdyProxy* as_spdyproxy =
154 static_cast<HttpAuthHandlerSpdyProxy*>(spdyproxy.get());
155 EXPECT_EQ(tests[i].expected_ps,
156 as_spdyproxy->ps_token_);
157 }
158 }
159 }
160
161 } // namespace spdyproxy
OLDNEW
« no previous file with comments | « chrome/browser/net/spdyproxy/http_auth_handler_spdyproxy.cc ('k') | chrome/browser/password_manager/password_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698