-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenid.test.assoc.xml
116 lines (95 loc) · 3.72 KB
/
openid.test.assoc.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Erik Eldridge</author>
<description>Unit tests for openid.assoc.xml</description>
<sampleQuery>select * from {table}</sampleQuery>
<documentationURL>http://wiki.github.com/ydn/yql-openid-support/</documentationURL>
</meta>
<bindings>
<select>
<inputs></inputs>
<execute><![CDATA[
//credit: http://javascript.crockford.com/remedial.html
if(!String.prototype.supplant){String.prototype.supplant=function(o){return this.replace(/{([^{}]*)}/g,function(a,b){var r=o[b];return typeof r==='string'||typeof r==='number'?r:a;});};}if(!String.prototype.trim){String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"");};}
var tableUri = 'http://github.com/yql/yql-tables/raw/master/openid/openid.assoc.xml';
//cases
//ref: http://openid.net/specs/openid-authentication-2_0.html#normalization_example
testCases = [
function(){
var output = {
'name': 'invalid uri structure'
};
var query = 'use "{tableUri}" as table; select * from table where uri="{uri}"'.supplant({
tableUri: tableUri,
uri: 'open.login.yahooapis.com/openid/op/auth'
});
var results = y.query( query ).results;
//tests
if ( results.success ) {
output['fail'] = 'table should return an error for invalid uri';
return output;
}
var validAssoc = results.success['mac_key'] && results.success['assoc_handle'];
if ( !validAssoc ) {
output['fail'] = 'assoc should have mac_key, assoc_handle, etc defined';
return output;
}
//pass if no tests fail
output['pass'] = ''
return output;
}(),
function(){
var output = {
'name': 'valid uri, valid assoc'
};
var query = 'use "{tableUri}" as table; select * from table where uri="{uri}"'.supplant({
tableUri: tableUri,
uri: 'https://open.login.yahooapis.com/openid/op/auth'
});
var results = y.query( query ).results;
//tests
if ( results.error ) {
output['fail'] = 'table should return success for a valid uri';
return output;
}
var valid = results.success['ns']
&& results.success['assoc_handle'] && results.success['session_type']
&& results.success['assoc_type'] && results.success['expires_in'];
if ( !valid ) {
output['fail'] = 'valid assoc from y! should have elements defined in the spec (ns, assoc_handle, etc)';
return output;
}
//pass if no tests fail
output['pass'] = ''
return output;
}(),
function(){
var output = {
//https://open.login.yahooapis.com is a valid uri syntax, and will return 200, but not an assoc
'name': 'valid uri syntax, 200 response, but invalid response format'
};
var query = 'use "{tableUri}" as table; select * from table where uri="{uri}"'.supplant({
tableUri: tableUri,
uri: 'https://open.login.yahooapis.com'
});
var results = y.query( query ).results;
//tests
if ( results.success ) {
output['fail'] = 'table should return error for invalid response format';
return output;
}
if ( -1 === results.error.indexOf( 'invalid response returned' ) ) {
output['fail'] = "error message should specify 'invalid response returned', instead it's: "+results.error;
return output;
}
//pass if no tests fail
output['pass'] = ''
return output;
}()
];
response.object = { "case": testCases };
]]></execute>
</select>
</bindings>
</table>