Warning, /frameworks/kio/src/kpac/kpactest.pac is written in an unsupported language. File is not indexed.

0001 /*
0002    A script to test the PAC specification.
0003 
0004    To use this script, select "Use automatic proxy configuration URL:" in the
0005    KDE proxy configuration dialog and run:
0006 
0007    qdbus org.kde.kded5 /modules/proxyscout proxyForUrl http://blah (URL doesn't matter)
0008 
0009    If everything succeeds, the output you get will be http://<your IP>/. If not,
0010    you would get http://<your IP>/<test-result> where <test-result> contains the
0011    tests that "failed". You can lookup the failed test name in the comments below
0012    and file a report in the KDE bug tracking system if you feel the problem is in
0013    the implementation.
0014 */
0015 
0016 function FindProxyForURL( url, host )
0017 {
0018     var result = "PROXY http://" + myIpAddress();
0019 
0020     // plainhost1
0021     if ( !isPlainHostName( "foo" ) )
0022         result += "/plainhost1=failed";
0023     // plainhost2
0024     if ( isPlainHostName( "foo.bar" ) )
0025         result += "/plainhost2=failed";
0026 
0027     // dnsdomain1
0028     if ( !dnsDomainIs( "foo.bar", "bar" ) )
0029         result += "/dnsdomain1=failed";
0030     // dnsdomain2
0031     if ( dnsDomainIs( "foo.baz", "bar" ) )
0032         result += "/dnsdomain2=failed";
0033 
0034     // localordomain1
0035     if ( !localHostOrDomainIs( "foo", "bar" ) )
0036         result += "/localordomain1=failed";
0037     // localordomain2
0038     if ( !localHostOrDomainIs( "foo.bar", "foo.bar" ) )
0039         result += "/localordomain2=failed";
0040     // localordomain3
0041     if ( !localHostOrDomainIs( "foo", "foo.baz" ) )
0042         result += "/localordomain3=failed";
0043     // localordomain4
0044     if ( localHostOrDomainIs( "foo.bar", "foo.baz" ) )
0045         result += "/localordomain4=failed";
0046 
0047     // isresolvable1
0048     // on failure make sure you can resolve www.kde.org correctly :-)
0049     if ( !isResolvable( "www.kde.org" ) ) result += "/isresolvable1=failed";
0050     // isresolvable2
0051     // on failure make sure dummy.invalid doesn't resolve :-)
0052     if ( isResolvable( "dummy.invalid" ) ) result += "/isresolvable2=failed";
0053 
0054     // isinnet1
0055     // on failure check if localhost resolves to 127.0.0.1 as it should
0056     if ( isInNet( "localhost", "1.2.3.4", "255.0.0.0" ) )
0057         result += "/isinnet1=failed";
0058     // isinnet2
0059     if ( isInNet( "1.2.3.4", "1.2.3.5", "255.255.255.255" ) )
0060         result += "/isinnet2=failed";
0061     // isinnet3
0062     if ( !isInNet( "1.2.3.4", "1.2.3.5", "255.255.255.0" ) )
0063         result += "/isinnet3=failed";
0064 
0065     // dnsresolve1
0066     // on failure check if localhost resolves to 127.0.0.1 as it should
0067     if ( dnsResolve( "localhost" ) != "127.0.0.1" )
0068         result += "/dnsresolve1=failed";
0069 
0070     // dnslevels1
0071     if ( dnsDomainLevels( "foo" ) != 0 )
0072         result += "/dnslevels1=failed";
0073     // dnslevels2
0074     if ( dnsDomainLevels( "foo.bar" ) != 1 )
0075         result += "/dnslevels2=failed";
0076     // dnslevels3
0077     if ( dnsDomainLevels( "foo.bar.baz" ) != 2 )
0078         result += "/dnslevels3=failed";
0079 
0080     // shexp1
0081     if ( !shExpMatch( "foobar", "foobar" ) )
0082         result += "/shexp1=failed";
0083     // shexp2
0084     if ( shExpMatch( "FoObAr", "foobar" ) )
0085         result += "/shexp2=failed";
0086     // shexp3
0087     if ( !shExpMatch( "Foobar", "?oobar" ) )
0088         result += "/shexp3=failed";
0089     // shexp4
0090     if ( !shExpMatch( "FoObAr", "*b*" ) )
0091         result += "/shexp4=failed";
0092     // shexp5
0093     if ( shExpMatch( "FoObAr", "*x*" ) )
0094         result += "/shexp5=failed";
0095     // shexp6
0096     if ( shExpMatch( "www.kde.org", "*.kde" ) )
0097         result += "/shexp6=failed";
0098 
0099     var now = new Date;
0100     var days = new Array( "sun", "mon", "tue", "wed", "thu", "fri", "sat" );
0101     var months = new Array( "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" );
0102 
0103     // weekday1
0104     if ( !weekdayRange( "sun", "sat" ) )
0105         result += "/weekday1=failed";
0106     // weekday2
0107     if ( !weekdayRange( "sat", "sun" ) )
0108         result += "/weekday2=failed";
0109     // weekday3
0110     if ( !weekdayRange( days[ now.getDay() ] ) )
0111         result += "/weekday3=failed";
0112     // weekday4
0113     if ( weekdayRange( now.getDay() ? "sun" : "mon" ) )
0114         result += "/weekday4=failed";
0115 
0116     // date1
0117     if ( !dateRange( now.getDate() ) )
0118         result += "/date1=failed";
0119     // date2
0120     if ( !dateRange( now.getDate(), 31 ) )
0121         result += "/date2=failed";
0122     // date3
0123     if ( !dateRange( 1, now.getDate() ) )
0124         result += "/date3=failed";
0125     // date4
0126     if ( dateRange( now.getDay() > 5 ? 1 : 6, now.getDay() > 5 ? 3 : 8 ) )
0127         result += "/date4=failed";
0128     // date5
0129     if ( !dateRange( months[ now.getMonth() ] ) )
0130         result += "/date5=failed";
0131     // date6
0132     if ( !dateRange( months[ now.getMonth() ], "dec" ) )
0133         result += "/date6=failed";
0134     // date7
0135     if ( !dateRange( "dec", months[ now.getMonth() ] ) )
0136         result += "/date7=failed";
0137     // date8
0138     if ( !dateRange( now.getFullYear() ) )
0139         result += "/date8=failed";
0140     // date9
0141     if ( dateRange( now.getFullYear() - 1 ) )
0142         result += "/date9=failed";
0143     // date10
0144     // if this fails, check your clock first :-)
0145     if ( dateRange( 1, "jan", 1990, 31, "dec", 2000 ) )
0146         result += "/date10=failed";
0147     // date11
0148     // if this fails, check your clock first :-)
0149     if ( !dateRange( 1, "jan", 2000, 31, "dec", 3000 ) )
0150         result += "/date11=failed";
0151 
0152     // time1
0153     if ( !timeRange( now.getHours() ) )
0154         result += "/time1=failed";
0155     // time2
0156     if ( !timeRange( now.getHours(), now.getMinutes(), 0, 0 ) )
0157         result += "/time2=failed";
0158     // time3
0159     if ( !timeRange( now.getHours(), now.getMinutes(), now.getSeconds(), 0, 0, 0 ) )
0160         result += "/time3=failed";
0161     // time4
0162     if ( timeRange( now.getHours() > 5 ? 1 : 6, now.getHours() > 5 ? 3 : 8 ) )
0163         result += "/time4=failed";
0164     // time5
0165     if ( now.getHours() == now.getUTCHours() )
0166         result += "/time5=skipped";
0167     else if ( timeRange( now.getUTCHours() ) )
0168         result += "/time5=failed";
0169     // time6
0170     if ( now.getHours() == now.getUTCHours() )
0171         result += "/time6=skipped";
0172     else if ( !timeRange( now.getUTCHours(), "GMT" ) )
0173         result += "/time6=failed";
0174 
0175     return result;
0176 }
0177