Added test that check exception throw in userHome
This commit is contained in:
parent
4fe0dd2134
commit
f6a45d4504
2
Makefile
2
Makefile
@ -192,4 +192,4 @@ test.out: tests/test.cpp functions.cpp unix/network.cpp progress.cpp\
|
|||||||
|
|
||||||
.PHONY: check
|
.PHONY: check
|
||||||
check: test.out
|
check: test.out
|
||||||
./test.out
|
sudo ./test.out
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include "../functions.hpp"
|
#include "../functions.hpp"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
TEST_CASE( "urlencode" ) {
|
TEST_CASE( "encodeUrl" ) {
|
||||||
std::string url1 = "http://google.com";
|
std::string url1 = "http://google.com";
|
||||||
std::string url1_expected = "http%3A%2F%2Fgoogle.com";
|
std::string url1_expected = "http%3A%2F%2Fgoogle.com";
|
||||||
REQUIRE( encodeUrl( url1 ) == url1_expected );
|
REQUIRE( encodeUrl( url1 ) == url1_expected );
|
||||||
@ -14,9 +14,19 @@ TEST_CASE( "urlencode" ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "userHome" ) {
|
TEST_CASE( "userHome" ) {
|
||||||
|
SECTION( "correct usage" ) {
|
||||||
auto home = userHome();
|
auto home = userHome();
|
||||||
std::string command = "/bin/bash -c \"if [ \"${HOME}\" == \"";
|
std::string command = "/bin/bash -c \"if [ \"${HOME}\" == \"";
|
||||||
command += home;
|
command += home;
|
||||||
command += "\" ] ; then exit 0 ; else exit 1 ; fi\"";
|
command += "\" ] ; then exit 0 ; else exit 1 ; fi\"";
|
||||||
REQUIRE( system( command.c_str() ) == 0 );
|
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!" ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user