File: pac

package info (click to toggle)
libproxy 0.5.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 728 kB
  • sloc: ansic: 3,455; sh: 228; python: 128; makefile: 37; cs: 18; perl: 6
file content (65 lines) | stat: -rwxr-xr-x 1,480 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Copyright 2020 Simon McVittie
# SPDX-License-Identifier: LGPL-2.1+

set -eux
set -o pipefail

#export PX_DEBUG=1

reset () {
    unset XDG_CURRENT_DESKTOP
    unset FTP_PROXY
    unset GSETTINGS_BACKEND
    unset HTTPS_PROXY
    unset HTTP_PROXY
    unset KDE_FULL_SESSION
    unset NO_PROXY
    unset ftp_proxy
    unset http_proxy
    unset https_proxy
    unset no_proxy
}

reset
export XDG_CURRENT_DESKTOP=GNOME
export GSETTINGS_BACKEND=keyfile
export XDG_CONFIG_HOME="$AUTOPKGTEST_TMP/config"
mkdir -p "$XDG_CONFIG_HOME/glib-2.0/settings"

escaped_autopkgtest_tmp="$(
    ( cd "$AUTOPKGTEST_TMP" && pwd ) | perl -pe '
        use bytes; chomp; s#([^-._~A-Za-z0-9/])#sprintf("%%%02X", ord($1))#ge;
    '
)"

cat > "$XDG_CONFIG_HOME/glib-2.0/settings/keyfile" <<EOF
[system/proxy]
autoconfig-url='file://$escaped_autopkgtest_tmp/pac.js'
ignore-hosts=[]
mode='auto'
use-same-proxy=false
EOF

cat > "$AUTOPKGTEST_TMP/pac.js" <<EOF
function FindProxyForURL(url, host) {
    if (host == "noproxy.example.com") {
        return "DIRECT";
    }

    if (url == "http://special.example.com") {
        return "PROXY specialproxy.example.net";
    }

    return "PROXY proxy.example.net; DIRECT";
}
EOF

answer="$(proxy http://example.com)"
test "${answer}" = "http://proxy.example.net direct://"

answer="$(proxy http://special.example.com)"
test "${answer}" = "http://specialproxy.example.net"

answer="$(proxy http://noproxy.example.com)"
test "${answer}" = direct://