Repository: kudu Updated Branches: refs/heads/master 3b6ab6449 -> ca2704c7d
KUDU-1914 Add positive .htpasswd test case This commit adds a test to check if a proper user/password pair allows a user to connect successfully to a Web UI with .htpasswd support enabled. Change-Id: Ia743ed41b9d68f9beb94c607e18613d0530526be Reviewed-on: http://gerrit.cloudera.org:8080/7026 Tested-by: Kudu Jenkins Reviewed-by: Todd Lipcon <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/7f91a119 Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/7f91a119 Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/7f91a119 Branch: refs/heads/master Commit: 7f91a11939e0e09bd02de2c1ac0ce4bce218f3d9 Parents: 3b6ab64 Author: Sam Okrent <[email protected]> Authored: Tue May 30 18:16:58 2017 -0700 Committer: Todd Lipcon <[email protected]> Committed: Wed May 31 18:31:54 2017 +0000 ---------------------------------------------------------------------- src/kudu/security/test/test_pass.cc | 6 +++--- src/kudu/security/test/test_pass.h | 4 ++++ src/kudu/server/webserver-test.cc | 8 +++++++- src/kudu/util/curl_util.cc | 2 ++ 4 files changed, 16 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kudu/blob/7f91a119/src/kudu/security/test/test_pass.cc ---------------------------------------------------------------------- diff --git a/src/kudu/security/test/test_pass.cc b/src/kudu/security/test/test_pass.cc index 9a0ab46..f99ab3c 100644 --- a/src/kudu/security/test/test_pass.cc +++ b/src/kudu/security/test/test_pass.cc @@ -28,9 +28,9 @@ namespace security { Status CreateTestHTPasswd(const string& dir, string* passwd_file) { - // In the format of user:realm:digest. Digest is generated bases on - // password 'test'. - const char *kHTPasswd = "test:0.0.0.0:e4c02fbc8e89377a942ffc6b1bc3a566"; + // In the format of user:realm:digest. Digest is generated based on + // user/password pair in kTestAuthString + const char *kHTPasswd = "test:mydomain.com:8b6f595afb3c037b7bd79b89d9576d06"; *passwd_file = JoinPathSegments(dir, "test.passwd"); RETURN_NOT_OK(WriteStringToFile(Env::Default(), kHTPasswd, *passwd_file)); return Status::OK(); http://git-wip-us.apache.org/repos/asf/kudu/blob/7f91a119/src/kudu/security/test/test_pass.h ---------------------------------------------------------------------- diff --git a/src/kudu/security/test/test_pass.h b/src/kudu/security/test/test_pass.h index c0974d0..5f730fe 100644 --- a/src/kudu/security/test/test_pass.h +++ b/src/kudu/security/test/test_pass.h @@ -24,6 +24,10 @@ namespace kudu { namespace security { +// Username and password for HTTP authentication, corresponding to +// .htpasswd created by CreateTestHTPasswd() +const std::string kTestAuthString = "test:test"; + // Creates .htpasswd for HTTP basic authentication in the format // of 'user:realm:digest', returning the path in '*passwd_file'. Status CreateTestHTPasswd(const std::string &dir, http://git-wip-us.apache.org/repos/asf/kudu/blob/7f91a119/src/kudu/server/webserver-test.cc ---------------------------------------------------------------------- diff --git a/src/kudu/server/webserver-test.cc b/src/kudu/server/webserver-test.cc index 8a2c541..c29c9aa 100644 --- a/src/kudu/server/webserver-test.cc +++ b/src/kudu/server/webserver-test.cc @@ -111,12 +111,18 @@ class PasswdWebserverTest : public WebserverTest { // Send a HTTP request with no username and password. It should reject // the request as the .htpasswd is presented to webserver. -TEST_F(PasswdWebserverTest, TestPasswd) { +TEST_F(PasswdWebserverTest, TestPasswdMissing) { Status status = curl_.FetchURL(strings::Substitute("http://$0/", addr_.ToString()), &buf_); ASSERT_EQ("Remote error: HTTP 401", status.ToString()); } +TEST_F(PasswdWebserverTest, TestPasswdPresent) { + string auth_url = strings::Substitute("http://$0@$1/", security::kTestAuthString, + addr_.ToString()); + ASSERT_OK(curl_.FetchURL(auth_url, &buf_)); +} + TEST_F(WebserverTest, TestIndexPage) { curl_.set_return_headers(true); ASSERT_OK(curl_.FetchURL(strings::Substitute("http://$0/", addr_.ToString()), http://git-wip-us.apache.org/repos/asf/kudu/blob/7f91a119/src/kudu/util/curl_util.cc ---------------------------------------------------------------------- diff --git a/src/kudu/util/curl_util.cc b/src/kudu/util/curl_util.cc index 6211834..3e8e591 100644 --- a/src/kudu/util/curl_util.cc +++ b/src/kudu/util/curl_util.cc @@ -89,6 +89,8 @@ Status EasyCurl::DoRequest(const std::string& url, post_data->c_str()))); } + RETURN_NOT_OK(TranslateError(curl_easy_setopt(curl_, CURLOPT_HTTPAUTH, CURLAUTH_ANY))); + RETURN_NOT_OK(TranslateError(curl_easy_perform(curl_))); long rc; // NOLINT(runtime/int) curl wants a long RETURN_NOT_OK(TranslateError(curl_easy_getinfo(curl_, CURLINFO_RESPONSE_CODE, &rc)));
