| 1 |
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 |
/* |
| 3 |
* GLibProxyResolver tests |
| 4 |
* |
| 5 |
* Copyright © 2011-2013, 2022 Red Hat, Inc. |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2.1 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General |
| 18 |
* Public License along with this library; if not, see |
| 19 |
* <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <gio/gio.h> |
| 23 |
|
| 24 |
#include "common.c" |
| 25 |
|
| 26 |
/* These tests use subprocesses in order to get a new GEnvironmentProxyResolver |
| 27 |
* for each test. Using a new subprocess also adds a veneer of thread safety to |
| 28 |
* our use of setenv()/unsetenv(). |
| 29 |
*/ |
| 30 |
|
| 31 |
static void |
| 32 |
test_proxy_uri (void) |
| 33 |
{ |
| 34 |
if (!g_test_subprocess ()) |
| 35 |
{ |
| 36 |
g_test_trap_subprocess (NULL, 0, 0); |
| 37 |
g_test_trap_assert_passed (); |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
g_setenv ("http_proxy", "http://proxy.example.com:8080", TRUE); |
| 42 |
g_setenv ("https_proxy", "http://proxy-s.example.com:7070", TRUE); |
| 43 |
g_setenv ("ftp_proxy", "ftp://proxy-f.example.com:6060", TRUE); |
| 44 |
|
| 45 |
test_proxy_uri_common (); |
| 46 |
} |
| 47 |
|
| 48 |
static void |
| 49 |
test_proxy_socks (void) |
| 50 |
{ |
| 51 |
if (!g_test_subprocess ()) |
| 52 |
{ |
| 53 |
g_test_trap_subprocess (NULL, 0, 0); |
| 54 |
g_test_trap_assert_passed (); |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
g_setenv ("http_proxy", "socks://proxy.example.com:1234", TRUE); |
| 59 |
g_setenv ("no_proxy", "127.0.0.1", TRUE); |
| 60 |
|
| 61 |
test_proxy_socks_common (); |
| 62 |
} |
| 63 |
|
| 64 |
static void |
| 65 |
test_proxy_ignore (void) |
| 66 |
{ |
| 67 |
gchar *no_proxy; |
| 68 |
|
| 69 |
if (!g_test_subprocess ()) |
| 70 |
{ |
| 71 |
g_test_trap_subprocess (NULL, 0, 0); |
| 72 |
g_test_trap_assert_passed (); |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
no_proxy = g_strjoinv (",", (gchar **)ignore_hosts); |
| 77 |
|
| 78 |
g_setenv ("http_proxy", "http://localhost:8080", TRUE); |
| 79 |
g_setenv ("no_proxy", no_proxy, TRUE); |
| 80 |
g_free (no_proxy); |
| 81 |
|
| 82 |
test_proxy_ignore_common (); |
| 83 |
} |
| 84 |
|
| 85 |
int |
| 86 |
main (int argc, |
| 87 |
char *argv[]) |
| 88 |
{ |
| 89 |
/* Unset variables that would make libproxy try to use gconf or ksettings */ |
| 90 |
g_unsetenv ("GNOME_DESKTOP_SESSION_ID"); |
| 91 |
g_unsetenv ("DESKTOP_SESSION"); |
| 92 |
g_unsetenv ("KDE_FULL_SESSION"); |
| 93 |
|
| 94 |
/* Unset variables that libproxy would look at if it were smarter, and which |
| 95 |
* it might possibly look at in the future. Just covering our bases. */ |
| 96 |
g_unsetenv ("XDG_CURRENT_DESKTOP"); |
| 97 |
|
| 98 |
/* Unset static proxy settings */ |
| 99 |
g_unsetenv ("http_proxy"); |
| 100 |
g_unsetenv ("HTTP_PROXY"); |
| 101 |
g_unsetenv ("https_proxy"); |
| 102 |
g_unsetenv ("HTTPS_PROXY"); |
| 103 |
g_unsetenv ("ftp_proxy"); |
| 104 |
g_unsetenv ("FTP_PROXY"); |
| 105 |
g_unsetenv ("no_proxy"); |
| 106 |
g_unsetenv ("NO_PROXY"); |
| 107 |
|
| 108 |
g_test_init (&argc, &argv, NULL); |
| 109 |
|
| 110 |
g_test_add_func ("/proxy/environment/uri", test_proxy_uri); |
| 111 |
g_test_add_func ("/proxy/environment/socks", test_proxy_socks); |
| 112 |
g_test_add_func ("/proxy/environment/ignore", test_proxy_ignore); |
| 113 |
|
| 114 |
return g_test_run(); |
| 115 |
} |