From f6a45d4504ccac73cae325f21e46c696cc47b95d Mon Sep 17 00:00:00 2001 From: zvon Date: Fri, 17 Apr 2020 22:35:59 +0200 Subject: [PATCH] Added test that check exception throw in userHome --- Makefile | 2 +- tests/test.cpp | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 747a552..58b39b6 100644 --- a/Makefile +++ b/Makefile @@ -192,4 +192,4 @@ test.out: tests/test.cpp functions.cpp unix/network.cpp progress.cpp\ .PHONY: check check: test.out - ./test.out + sudo ./test.out diff --git a/tests/test.cpp b/tests/test.cpp index 04126e7..bf6a0ca 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -3,7 +3,7 @@ #include "../functions.hpp" #include -TEST_CASE( "urlencode" ) { +TEST_CASE( "encodeUrl" ) { std::string url1 = "http://google.com"; std::string url1_expected = "http%3A%2F%2Fgoogle.com"; REQUIRE( encodeUrl( url1 ) == url1_expected ); @@ -14,9 +14,19 @@ TEST_CASE( "urlencode" ) { } TEST_CASE( "userHome" ) { - auto home = userHome(); - std::string command = "/bin/bash -c \"if [ \"${HOME}\" == \""; - command += home; - command += "\" ] ; then exit 0 ; else exit 1 ; fi\""; - REQUIRE( system( command.c_str() ) == 0 ); + SECTION( "correct usage" ) { + auto home = userHome(); + std::string command = "/bin/bash -c \"if [ \"${HOME}\" == \""; + command += home; + command += "\" ] ; then exit 0 ; else exit 1 ; fi\""; + REQUIRE( system( command.c_str() ) == 0 ); + } + + SECTION( "exception with non existing user" ) { + setresgid( 1025, 1025, 1025 ); + setresuid( 1025, 1025, 1025 ); + REQUIRE_THROWS_WITH( + userHome(), Catch::Matchers::Contains( "User with uid" ) && + Catch::Matchers::Contains( "doesn't exist!" ) ); + } }