http_auth_sspi_win_unittest.cc revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 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 "base/basictypes.h"
6#include "net/base/net_errors.h"
7#include "net/http/http_auth_sspi_win.h"
8#include "net/http/mock_sspi_library_win.h"
9#include "testing/gtest/include/gtest/gtest.h"
10
11namespace net {
12
13namespace {
14
15void MatchDomainUserAfterSplit(const std::wstring& combined,
16                               const std::wstring& expected_domain,
17                               const std::wstring& expected_user) {
18  std::wstring actual_domain;
19  std::wstring actual_user;
20  SplitDomainAndUser(combined, &actual_domain, &actual_user);
21  EXPECT_EQ(expected_domain, actual_domain);
22  EXPECT_EQ(expected_user, actual_user);
23}
24
25}  // namespace
26
27TEST(HttpAuthSSPITest, SplitUserAndDomain) {
28  MatchDomainUserAfterSplit(L"foobar", L"", L"foobar");
29  MatchDomainUserAfterSplit(L"FOO\\bar", L"FOO", L"bar");
30}
31
32TEST(HttpAuthSSPITest, DetermineMaxTokenLength_Normal) {
33  SecPkgInfoW package_info;
34  memset(&package_info, 0x0, sizeof(package_info));
35  package_info.cbMaxToken = 1337;
36
37  MockSSPILibrary mock_library;
38  mock_library.ExpectQuerySecurityPackageInfo(L"NTLM", SEC_E_OK, &package_info);
39  ULONG max_token_length = 100;
40  int rv = DetermineMaxTokenLength(&mock_library, L"NTLM", &max_token_length);
41  EXPECT_EQ(OK, rv);
42  EXPECT_EQ(1337, max_token_length);
43}
44
45TEST(HttpAuthSSPITest, DetermineMaxTokenLength_InvalidPackage) {
46  MockSSPILibrary mock_library;
47  mock_library.ExpectQuerySecurityPackageInfo(L"Foo", SEC_E_SECPKG_NOT_FOUND,
48                                              NULL);
49  ULONG max_token_length = 100;
50  int rv = DetermineMaxTokenLength(&mock_library, L"Foo", &max_token_length);
51  EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv);
52  // |DetermineMaxTokenLength()| interface states that |max_token_length| should
53  // not change on failure.
54  EXPECT_EQ(100, max_token_length);
55}
56
57}  // namespace net
58