@@ -238,3 +238,59 @@ TEST_CASE("QueryString") {
238238 REQUIRE (p2->values ()[0 ] == " value2" );
239239 }
240240}
241+
242+ TEST_CASE (" mask_authentication" ) {
243+ SECTION (" no authentication" ) {
244+ std::string url (" http://192.168.1.1" );
245+ std::string result = mask_authentication (url);
246+ REQUIRE (url == result);
247+ }
248+ SECTION (" has username no password has scheme" ) {
249+ std::string url (" http://username@192.168.1.1" );
250+ std::string result = mask_authentication (url);
251+ REQUIRE (result == " http://********@192.168.1.1" );
252+ }
253+ SECTION (" has username no password no scheme" ) {
254+ std::string url (" username@192.168.1.1" );
255+ std::string result = mask_authentication (url);
256+ REQUIRE (result == " ********@192.168.1.1" );
257+ }
258+ SECTION (" has username has password no scheme" ) {
259+ std::string url (" username:password@192.168.1.1" );
260+ std::string result = mask_authentication (url);
261+ REQUIRE (result == " ********:********@192.168.1.1" );
262+ }
263+ SECTION (" has username has password has scheme" ) {
264+ std::string url (" http://username:password@192.168.1.1" );
265+ std::string result = mask_authentication (url);
266+ REQUIRE (result == " http://********:********@192.168.1.1" );
267+ }
268+ }
269+
270+ TEST_CASE (" remove_authentication" ) {
271+ SECTION (" no authentication" ) {
272+ std::string url (" http://192.168.1.1" );
273+ std::string result = remove_authentication (url);
274+ REQUIRE (url == result);
275+ }
276+ SECTION (" has username no password has scheme" ) {
277+ std::string url (" http://username@192.168.1.1" );
278+ std::string result = remove_authentication (url);
279+ REQUIRE (result == " http://192.168.1.1" );
280+ }
281+ SECTION (" has username no password no scheme" ) {
282+ std::string url (" username@192.168.1.1" );
283+ std::string result = remove_authentication (url);
284+ REQUIRE (result == " 192.168.1.1" );
285+ }
286+ SECTION (" has username has password no scheme" ) {
287+ std::string url (" username:password@192.168.1.1" );
288+ std::string result = remove_authentication (url);
289+ REQUIRE (result == " 192.168.1.1" );
290+ }
291+ SECTION (" has username has password has scheme" ) {
292+ std::string url (" http://username:password@192.168.1.1" );
293+ std::string result = remove_authentication (url);
294+ REQUIRE (result == " http://192.168.1.1" );
295+ }
296+ }
0 commit comments