-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathurltest.cgi
More file actions
executable file
·120 lines (100 loc) · 3.12 KB
/
Copy pathurltest.cgi
File metadata and controls
executable file
·120 lines (100 loc) · 3.12 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/ruby
require 'wunderbar/script'
require 'ruby2js/filter/functions'
require 'ruby2js/filter/jquery'
_html do
_base.base! href: ''
_script src: "//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"
_p.status! 'Loading'
_pre.results!
_a.a! style: 'display: none'
_script_ do
url = null
# polyfill URL interface for older browsers
begin
new URL(location.href)
rescue => e
docbase = document.getElementById('base')
a = document.getElementById('a')
def this.URL(url, base)
docbase.setAttribute('href', base)
a.setAttribute('href', url)
return a
end
end
def runTests(testdata, settests)
constructor_results = []
for i in 0...testdata.length
results = {
input: testdata[i].input,
base: testdata[i].base
}
begin
url = URL.new(results.input, results.base)
rescue => error
results.exception = error.message
url = {href: results.input, protocol: ':'}
end
%w(
href protocol username password hostname port pathname search hash
).forEach do |property|
begin
results[property] = url[property]
rescue => error
results["#{property}-exception"] = error.message
end
end
constructor_results << results
end
for attr in settests
tests = settests[attr]
for i in 0...tests.length
url = URL.new(tests[i].url)
begin
url[attr] = tests[i].value
rescue => e
tests[i].tests['exception'] = (e.message || e.toString())
url = {protocol: ':'}
end
for prop in tests[i].tests
next if prop == 'exception'
begin
tests[i].tests[prop] = url[prop]
rescue => e
tests[i].tests.delete(prop)
tests[i].tests[prop + '_exception'] = (e.message || e.toString())
end
end
end
end
return {constructor: constructor_results, setters: settests}
end
~'#status'.text('Downloading test data')
$$.getJSON('urltestdata.json') do |testdata|
$$.getJSON('urlsettest.json') do |settests|
~'#status'.text('Running tests')
results = runTests(testdata, settests)
~'#status'.text('Posting results')
$$.post('', results: JSON.stringify(results, null, 2)) do |response|
results = {
useragent: response.useragent,
constructor: results.constructor,
setters: results.setters
}
~'#status'.text("Test complete, ticket: #{response.ticket}")
~'#results'.text(JSON.stringify(results, null, 2))
end
end
end
end
end
_json do
ticket = Digest::MD5.
hexdigest "#{ENV['HTTP_USER_AGENT']}:#{ENV['REMOTE_ADDR']}:#{Time.now}"
File.open("useragent-results/#{ticket}", 'w') do |file|
results = {useragent: ENV['HTTP_USER_AGENT']}.merge(JSON.parse(@results))
file.puts JSON.pretty_generate(results)
end
_useragent ENV['HTTP_USER_AGENT']
_ticket ticket
end