This source file includes following definitions.
- MatchDomainUserAfterSplit
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "base/basictypes.h"
#include "net/base/net_errors.h"
#include "net/http/http_auth_challenge_tokenizer.h"
#include "net/http/http_auth_sspi_win.h"
#include "net/http/mock_sspi_library_win.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
namespace {
void MatchDomainUserAfterSplit(const std::wstring& combined,
const std::wstring& expected_domain,
const std::wstring& expected_user) {
std::wstring actual_domain;
std::wstring actual_user;
SplitDomainAndUser(combined, &actual_domain, &actual_user);
EXPECT_EQ(expected_domain, actual_domain);
EXPECT_EQ(expected_user, actual_user);
}
const ULONG kMaxTokenLength = 100;
}
TEST(HttpAuthSSPITest, SplitUserAndDomain) {
MatchDomainUserAfterSplit(L"foobar", L"", L"foobar");
MatchDomainUserAfterSplit(L"FOO\\bar", L"FOO", L"bar");
}
TEST(HttpAuthSSPITest, DetermineMaxTokenLength_Normal) {
SecPkgInfoW package_info;
memset(&package_info, 0x0, sizeof(package_info));
package_info.cbMaxToken = 1337;
MockSSPILibrary mock_library;
mock_library.ExpectQuerySecurityPackageInfo(L"NTLM", SEC_E_OK, &package_info);
ULONG max_token_length = kMaxTokenLength;
int rv = DetermineMaxTokenLength(&mock_library, L"NTLM", &max_token_length);
EXPECT_EQ(OK, rv);
EXPECT_EQ(1337, max_token_length);
}
TEST(HttpAuthSSPITest, DetermineMaxTokenLength_InvalidPackage) {
MockSSPILibrary mock_library;
mock_library.ExpectQuerySecurityPackageInfo(L"Foo", SEC_E_SECPKG_NOT_FOUND,
NULL);
ULONG max_token_length = kMaxTokenLength;
int rv = DetermineMaxTokenLength(&mock_library, L"Foo", &max_token_length);
EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv);
EXPECT_EQ(100, max_token_length);
}
TEST(HttpAuthSSPITest, ParseChallenge_FirstRound) {
MockSSPILibrary mock_library;
HttpAuthSSPI auth_sspi(&mock_library, "Negotiate",
NEGOSSP_NAME, kMaxTokenLength);
std::string challenge_text = "Negotiate";
HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
challenge_text.end());
EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
auth_sspi.ParseChallenge(&challenge));
}
TEST(HttpAuthSSPITest, ParseChallenge_TwoRounds) {
MockSSPILibrary mock_library;
HttpAuthSSPI auth_sspi(&mock_library, "Negotiate",
NEGOSSP_NAME, kMaxTokenLength);
std::string first_challenge_text = "Negotiate";
HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
first_challenge_text.end());
EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
auth_sspi.ParseChallenge(&first_challenge));
std::string auth_token;
EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com",
&auth_token));
std::string second_challenge_text = "Negotiate Zm9vYmFy";
HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
second_challenge_text.end());
EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
auth_sspi.ParseChallenge(&second_challenge));
}
TEST(HttpAuthSSPITest, ParseChallenge_UnexpectedTokenFirstRound) {
MockSSPILibrary mock_library;
HttpAuthSSPI auth_sspi(&mock_library, "Negotiate",
NEGOSSP_NAME, kMaxTokenLength);
std::string challenge_text = "Negotiate Zm9vYmFy";
HttpAuthChallengeTokenizer challenge(challenge_text.begin(),
challenge_text.end());
EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID,
auth_sspi.ParseChallenge(&challenge));
}
TEST(HttpAuthSSPITest, ParseChallenge_MissingTokenSecondRound) {
MockSSPILibrary mock_library;
HttpAuthSSPI auth_sspi(&mock_library, "Negotiate",
NEGOSSP_NAME, kMaxTokenLength);
std::string first_challenge_text = "Negotiate";
HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
first_challenge_text.end());
EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
auth_sspi.ParseChallenge(&first_challenge));
std::string auth_token;
EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com",
&auth_token));
std::string second_challenge_text = "Negotiate";
HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
second_challenge_text.end());
EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT,
auth_sspi.ParseChallenge(&second_challenge));
}
TEST(HttpAuthSSPITest, ParseChallenge_NonBase64EncodedToken) {
MockSSPILibrary mock_library;
HttpAuthSSPI auth_sspi(&mock_library, "Negotiate",
NEGOSSP_NAME, kMaxTokenLength);
std::string first_challenge_text = "Negotiate";
HttpAuthChallengeTokenizer first_challenge(first_challenge_text.begin(),
first_challenge_text.end());
EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_ACCEPT,
auth_sspi.ParseChallenge(&first_challenge));
std::string auth_token;
EXPECT_EQ(OK, auth_sspi.GenerateAuthToken(NULL, "HTTP/intranet.google.com",
&auth_token));
std::string second_challenge_text = "Negotiate =happyjoy=";
HttpAuthChallengeTokenizer second_challenge(second_challenge_text.begin(),
second_challenge_text.end());
EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_INVALID,
auth_sspi.ParseChallenge(&second_challenge));
}
}