-
Notifications
You must be signed in to change notification settings - Fork 73
/
run-tests.py
executable file
·81 lines (73 loc) · 2.83 KB
/
run-tests.py
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
#!/usr/bin/env python
"""
run-tests - test oauth implementations in various languages
Language specific tester scripts take the following arguments:
consumer key
consumer secret
url
parameters (url encoded)
token
token secret
method
realm
timestamp
nonce
and return the resulting Authorization header value.
"""
import urllib, subprocess, time, random
testers = [('PHP', ['php', './tester.php']),
('Python', ['python', './tester.py']),
('Python3', ['python3', './tester.py']),
('Ruby', ['ruby', './tester.rb']),
('Ruby 1.9', ['ruby-1.9', './tester.rb']),
('Node.js', ['node', './tester.node']),
('Java', ['java', '-classpath', '../java/classes:.', 'Tester'])]
def test(consumer,
url,
params,
token = None,
method = 'POST',
realm = None,
timestamp = None,
nonce = None):
args = [consumer[0], consumer[1],
url, urllib.urlencode(params),
token[0] if token is not None else '',
token[1] if token is not None else '',
method,
realm if realm is not None else '',
timestamp if timestamp is not None else str(int(time.time())),
nonce if nonce is not None else str(random.randint(0, 1000000))]
results = []
for language, command in testers:
try:
results.append((language, subprocess.check_output(command + args)))
except Exception as e:
results.append((language, 'Error encountered: %s' % repr(e)))
if len(set(result for language, result in results)) > 1:
print 'ERROR:'
print '%s %s' % (method, url)
print '%r' % params
print 'consumer=%r token=%r' % (consumer, token)
print 'realm=%r' % realm
for language, result in results:
print '%10s %s' % (language, result)
else:
print 'OK'
test(('a','b'), 'http://www.example.com/', {})
test(('a','b'), 'Http://www.example.com/', {})
test(('a','b'), 'http://www.EXAMPLE.com/', {})
test(('a','b'), 'http://www.example.com/~test/', {})
test(('a','b'), 'http://www.example.com/'+urllib.quote(u'fran\xe7ais'.encode('UTF-8')), {})
test(('a','b'), 'http://www.example.com/', {'test':'thing', 'other':'test'})
test(('a','b'), 'http://www.example.com/', {'extras':'-*,names', 'foo':'-._~%+&=I what'})
test(('a','b'), 'http://www.example.com/', {'test':'thing', 'TEST':'foo'})
test(('a','b'), 'http://www.example.com/', {'language':u'Fran\xe7ais'.encode('UTF-8')})
test(('a','b'), 'http://www.example.com/', {},
token=('to','ken'))
test(('a','b'), 'http://www.example.com/', {'test':'thing', 'other':'test'},
token=('to','ken'))
test(('a','b'), 'https://www.example.com/', {'test':'thing', 'other':'test'},
token=('to','ken'))
test(('a','b'), 'http://www.example.com/', {'oauth_callback':'https://www.example.com/my/callback'})
test(('a','b'), 'http://www.example.com/?foo=bar', {'test':'thing', 'other':'test'})