MCPcopy Create free account
hub / github.com/aria2/aria2 / testHttpBasicAuth

Method testHttpBasicAuth

test/HttpServerTest.cc:43–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41} // namespace
42
43void HttpServerTest::testHttpBasicAuth()
44{
45 SocketCore server;
46 server.bind(0);
47 server.beginListen();
48 server.setBlockingMode();
49
50 {
51 // Default is no auth
52 auto req = performHttpRequest(
53 server, "GET / HTTP/1.1\r\nUser-Agent: aria2-test\r\n\r\n");
54 CPPUNIT_ASSERT(req->authenticate());
55 }
56
57 {
58 // Empty user-name and password should come out as no auth.
59 auto req = performHttpRequest(
60 server, "GET / HTTP/1.1\r\nUser-Agent: aria2-test\r\n\r\n");
61 req->setUsernamePassword("", "");
62 CPPUNIT_ASSERT(req->authenticate());
63 }
64
65 {
66 // Empty user-name but set password should also come out as no auth.
67 auto req = performHttpRequest(
68 server, "GET / HTTP/1.1\r\nUser-Agent: aria2-test\r\n\r\n");
69 req->setUsernamePassword("", "pass");
70 CPPUNIT_ASSERT(req->authenticate());
71 }
72
73 {
74 // Client provided credentials should be ignored when there is no auth.
75 auto req = performHttpRequest(server, "GET / HTTP/1.1\r\nUser-Agent: "
76 "aria2-test\r\nAuthorization: Basic "
77 "dXNlcjpwYXNz\r\n\r\n");
78 req->setUsernamePassword("", "pass");
79 CPPUNIT_ASSERT(req->authenticate());
80 }
81
82 {
83 // Correct client provided credentials should match.
84 auto req = performHttpRequest(server, "GET / HTTP/1.1\r\nUser-Agent: "
85 "aria2-test\r\nAuthorization: Basic "
86 "dXNlcjpwYXNz\r\n\r\n");
87 req->setUsernamePassword("user", "pass");
88 CPPUNIT_ASSERT(req->authenticate());
89 }
90
91 {
92 // Correct client provided credentials should match (2).
93 // Embedded nulls
94 auto req = performHttpRequest(
95 server, "GET / HTTP/1.1\r\nUser-Agent: aria2-test\r\nAuthorization: "
96 "Basic dXNlcgBudWxsOnBhc3MAbnVsbA==\r\n\r\n");
97 req->setUsernamePassword(std::string("user\0null", 9),
98 std::string("pass\0null", 9));
99 CPPUNIT_ASSERT(req->authenticate());
100 }

Callers

nothing calls this directly

Calls 6

performHttpRequestFunction · 0.85
beginListenMethod · 0.80
setBlockingModeMethod · 0.80
authenticateMethod · 0.80
setUsernamePasswordMethod · 0.80
bindMethod · 0.45

Tested by

no test coverage detected