Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / net / http / http_auth_multi_round_parse_unittest.cc
blob1be5ad1f5dcfa84fe7dc0b5c851dd0e3e7d72337
1 // Copyright 2015 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.
5 #include "net/http/http_auth_challenge_tokenizer.h"
6 #include "net/http/http_auth_multi_round_parse.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace net {
11 TEST(HttpAuthHandlerNegotiateParseTest, ParseFirstRoundChallenge) {
12 // The first round should just consist of an unadorned header with the scheme
13 // name.
14 std::string challenge_text = "DummyScheme";
15 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
16 challenge_text.end());
17 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
18 ParseFirstRoundChallenge("dummyscheme", &challenge));
21 TEST(HttpAuthHandlerNegotiateParseTest,
22 ParseFirstNegotiateChallenge_UnexpectedToken) {
23 // If the first round challenge has an additional authentication token, it
24 // should be treated as an invalid challenge from the server.
25 std::string challenge_text = "Negotiate Zm9vYmFy";
26 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
27 challenge_text.end());
28 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID,
29 ParseFirstRoundChallenge("negotiate", &challenge));
32 TEST(HttpAuthHandlerNegotiateParseTest,
33 ParseFirstNegotiateChallenge_BadScheme) {
34 std::string challenge_text = "DummyScheme";
35 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
36 challenge_text.end());
37 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID,
38 ParseFirstRoundChallenge("negotiate", &challenge));
41 TEST(HttpAuthHandlerNegotiateParseTest, ParseLaterRoundChallenge) {
42 // Later rounds should always have a Base64 encoded token.
43 std::string challenge_text = "Negotiate Zm9vYmFy";
44 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
45 challenge_text.end());
46 std::string encoded_token;
47 std::string decoded_token;
48 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
49 ParseLaterRoundChallenge("negotiate", &challenge, &encoded_token,
50 &decoded_token));
51 EXPECT_EQ("Zm9vYmFy", encoded_token);
52 EXPECT_EQ("foobar", decoded_token);
55 TEST(HttpAuthHandlerNegotiateParseTest,
56 ParseAnotherNegotiateChallenge_MissingToken) {
57 std::string challenge_text = "Negotiate";
58 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
59 challenge_text.end());
60 std::string encoded_token;
61 std::string decoded_token;
62 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT,
63 ParseLaterRoundChallenge("negotiate", &challenge, &encoded_token,
64 &decoded_token));
67 TEST(HttpAuthHandlerNegotiateParseTest,
68 ParseAnotherNegotiateChallenge_InvalidToken) {
69 std::string challenge_text = "Negotiate ***";
70 HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
71 challenge_text.end());
72 std::string encoded_token;
73 std::string decoded_token;
74 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID,
75 ParseLaterRoundChallenge("negotiate", &challenge, &encoded_token,
76 &decoded_token));