Starts work on https as well as some moving about

I now start the listener in the main.c file rather than proxy given that
I didn't feel proxy was the right place if a normal (non-proxied)
request came in. webserver.{c,h} and proxy.{c,h} had some changes
relating to this.

The config changed slightly - we now create a folder in ~/.config/
called yaip. This is where certificates and so on will be stored along
with the user configuration

I created a helper function to get files inside this directory (it
changes based on xdg_config_home) and updated relevant tests.

In ssl.{c,h} I have started work. If they don't exist, the tool now
creates and stores a key and certificate for the CA that this tool will
need to pretend to be. I still need to write tests for this.
This commit is contained in:
Jonathan Hodgson 2022-01-20 16:53:35 +00:00
parent 6eaad263be
commit bb62ed3b1f
14 changed files with 366 additions and 100 deletions

View file

@ -37,7 +37,7 @@ MunitResult checkConfigDirWithXdg(const MunitParameter params[],
void* user_data_or_fixture){
char directory[] = "/testing/xdg/directory";
setenv( "XDG_CONFIG_HOME",directory, 1 );
munit_assert_string_equal( directory, getConfigDir() );
munit_assert_string_equal( "/testing/xdg/directory/yaip", getConfigDir() );
return MUNIT_OK;
}
@ -46,7 +46,7 @@ MunitResult checkConfigDirWithoutXdg(const MunitParameter params[],
unsetenv( "XDG_CONFIG_HOME" );
char dir[500] = {'\0'};
strcpy( dir, getenv("HOME") );
strcat( dir, "/.config" );
strcat( dir, "/.config/yaip" );
munit_assert_string_equal( dir, getConfigDir() );
return MUNIT_OK;
}
@ -55,14 +55,18 @@ MunitResult checkDefaults(const MunitParameter params[],
void* user_data_or_fixture){
char directory[] = "/testing/xdg/directory";
char file[] = "/testing/xdg/directory/proxy.conf";
char conffile[] = "/testing/xdg/directory/yaip/proxy.conf";
char certfile[] = "/testing/xdg/directory/yaip/cert.pem";
char keyfile[] = "/testing/xdg/directory/yaip/key.pem";
setenv( "XDG_CONFIG_HOME",directory, 1 );
Config *conf = configDefaults();
munit_assert_string_equal(conf->database, "proxy.sqlite");
munit_assert_int(conf->port, ==, 8080);
munit_assert_string_equal(conf->localConfig, "proxy.conf");
munit_assert_string_equal(conf->userConfig, file);
munit_assert_string_equal(conf->userConfig, conffile);
munit_assert_string_equal(conf->certfile, certfile);
munit_assert_string_equal(conf->keyfile, keyfile);
return MUNIT_OK;
}

View file

@ -114,6 +114,7 @@ MunitResult testFirstLineVersions(const MunitParameter params[],
void* user_data_or_fixture){
Request *req;
printf("\nI get here\n");
requestTestFirstLine *line = getLineObj(params);
if ( line->fullLine == NULL ) return MUNIT_ERROR;
req = newRequest();