Skip to content

Commit 7ed3501

Browse files
committed
Test for basic auth fail
1 parent c507fc9 commit 7ed3501

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/integ/authentication.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class user_pass_resource : public httpserver::http_resource
5050
public:
5151
const httpserver::http_response render_GET(const httpserver::http_request& req)
5252
{
53+
if (req.get_user() != "myuser" || req.get_pass() != "mypass")
54+
{
55+
return httpserver::http_response_builder("FAIL").basic_auth_fail_response("test@example.com");
56+
}
5357
return httpserver::http_response_builder(req.get_user() + " " + req.get_pass(), 200, "text/plain").string_response();
5458
}
5559
};
@@ -109,6 +113,31 @@ LT_BEGIN_AUTO_TEST(authentication_suite, base_auth)
109113
ws.stop();
110114
LT_END_AUTO_TEST(base_auth)
111115

116+
LT_BEGIN_AUTO_TEST(authentication_suite, base_auth_fail)
117+
webserver ws = create_webserver(8080);
118+
119+
user_pass_resource* user_pass = new user_pass_resource();
120+
ws.register_resource("base", user_pass);
121+
ws.start(false);
122+
123+
curl_global_init(CURL_GLOBAL_ALL);
124+
std::string s;
125+
CURL *curl = curl_easy_init();
126+
CURLcode res;
127+
curl_easy_setopt(curl, CURLOPT_USERNAME, "myuser");
128+
curl_easy_setopt(curl, CURLOPT_PASSWORD, "wrongpass");
129+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/base");
130+
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
131+
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
132+
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
133+
res = curl_easy_perform(curl);
134+
LT_ASSERT_EQ(res, 0);
135+
LT_CHECK_EQ(s, "FAIL");
136+
curl_easy_cleanup(curl);
137+
138+
ws.stop();
139+
LT_END_AUTO_TEST(base_auth_fail)
140+
112141
LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth)
113142
webserver ws = create_webserver(8080)
114143
.digest_auth_random("myrandom")

0 commit comments

Comments
 (0)