forked from web-platform-tests/wpt
/
0030-authorize-valid-token.html
167 lines (142 loc) · 6.18 KB
/
0030-authorize-valid-token.html
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE HTML>
<meta charset="utf-8">
<title>
[0030: Status will changed on correct authorization]
</title>
<link rel="help" href="https://www.w3.org/TR/vehicle-information-service/#idl-def-getrequest">
<link rel="stylesheet" type="text/css" href="./style-general.css">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./vehicle-test-config.js"></script>
<script src="./vehicle-test-helper.js"></script>
<!--
==========
Test Assertion:
[0030: Status will changed on correct authorization]
==
When a websocket channel is not privileged and the server receives valid 'authorize' request,
the privileged level (=access control state of the channel) should be changed to higer level.
==========
Test Senario:
1. Open a websocket connection (wsconn1)<br>
2. Execute an action which requires authorization(e.g. set method for door.IsLocked)<br>
And confirm the action fails.
3. Execute Authorize() method with valid token and confirm it succeed.<br>
4. Execute the same action again and confirm the action succeed this time<br>
because privilege level was elevated by Authorize() method.
-->
<div id="test-title">
[0030: Status will changed on correct authorization]
</div>
<div id="scenario">
<br>
1. Open a websocket connection (wsconn1)<br>
2. Execute an action({action} to {data path}) which requires authorization,<br>
and confirm the action fails. (e.g. set method for door.IsLocked)<br>
3. Execute Authorize() method with valid token and confirm it succeed.<br>
4. Execute the same action again and confirm the action succeed this time<br>
because privilege level was elevated by Authorize() method.<br>
<br>
<b>Expected Result:</b><br>
- The {action} to {data path} fails before execution of Authorize() method <br>
- The {action} to {data path} succeeds after execution of Authorize() method <br>
</div>
<div id="result"></div>
<br>
<div id="log"></div>
<script>
// const
var action_method = AUTH_ACCESS_ACTION;
var action_path = AUTH_ACCESS_PATH;
var action_value = AUTH_ACCESS_VALUE;
var valid_token = TOKEN_VALID;
var invalid_token = TOKEN_INVALID;
// phase value
var PH_0_START = 0;
var PH_1_CONN_ESTABLISHED = 1;
var PH_2_TRY_ACTION_SENT = 2;
var PH_3_VALID_AUTH_SENT = 3;
var PH_4_TRY_ACTION_SENT = 4;
var PH_9_FINISH = 9;
var phase = PH_0_START;
var t = async_test("Authorize with invalid token");
var wsconn1 = new WebSocket(VISS_URL, VISS_SUBPROTO);
// Timeout for the case of server doesn't return response
t.step_timeout(function() {
if (phase < PH_1_CONN_ESTABLISHED ) {
// In case that timeout expired before WebSocket connection establish,
// the test should be terminated as failure.
// In case this timeout expired after connection established and move on to next phase,
// the timeout should be ignored.
helper_terminate_failure("Finish by timeout", wsconn1, null);
}
}, TIME_OUT_TIME);
wsconn1.onopen = function() {
addLogMessage("PH0: wsconn1 websocket has been connected!");
phase = PH_1_CONN_ESTABLISHED;
send_targetAction(wsconn1, action_method, action_path, action_value );
phase = PH_2_TRY_ACTION_SENT;
}
wsconn1.onmessage = function(_event) {
var msg = JSON.parse(_event.data);
addLogMessage("----:wsconn1.onmessage : " + _event.data);
if (phase == PH_1_CONN_ESTABLISHED) {
addLogMessage("PH_1: " );
} else if (phase == PH_2_TRY_ACTION_SENT) {
addLogMessage("PH_2: " );
if ( isGetSuccessResponse("", msg) || isSetSuccessResponse("", msg) ) {
addLogMessage("----:wsconn1: TargetAction: Success(= not expected behavior) ");
// This is NOT expected action
wsconn1.ph2_action_res = true;
// If the action is available before Authorize, this test become meaningless. Terminate with failure.
helper_terminate_failure("Even before 'Authorize', the action is accessible. That doesn't meet test's condition. Test Failed.", wsconn1, null);
} else if ( isGetErrorResponse("", msg) || isSetErrorResponse("", msg) ) {
// This is expected action
addLogMessage("----:wsconn1: TargetAction: Error(= expected behavior)");
wsconn1.ph2_action_res = false;
phase = PH_3_VALID_AUTH_SENT;
send_authorize(wsconn1, valid_token);
} else {
addLogMessage("----:wsconn1: Else case " );
helper_terminate_failure("Unexpected behavior. Test Failed.", wsconn1, null);
}
} else if (phase == PH_3_VALID_AUTH_SENT) {
addLogMessage("PH_3: " );
if ( isAuthorizeSuccessResponse("", msg) ) {
addLogMessage("----:Authorize success(= expected behavior)");
wsconn1.ph3_action_res = true;
} else if ( isAuthorizeErrorResponse("", msg) ) {
addLogMessage("----:Authorize error(= not expected behavior)");
wsconn1.ph3_action_res = false;
}
phase = PH_4_TRY_ACTION_SENT;
send_targetAction(wsconn1, action_method, action_path, action_value );
} else if (phase == PH_4_TRY_ACTION_SENT) {
addLogMessage("PH_4: " );
if ( isGetSuccessResponse("", msg) || isSetSuccessResponse("", msg) ) {
// This is expected behavior
addLogMessage("----:TargetActon: Success ");
helper_terminate_success("After VALID 'Authorize', the action become enabled. Test success. ", wsconn1, null);
} else if ( isGetErrorResponse("", msg) || isSetErrorResponse("", msg) ) {
// This is not expected behavior.
addLogMessage("----:TargetActon: Failure ");
helper_terminate_failure("Even after VALID 'Authorize', the action doesn't become enabled. Test failed.", wsconn1, null);
}
}
}
var send_targetAction = function(_ws_conn, _action, _path, _value) {
addLogMessage("----:Execute action:'"+ _action +"' to dataPath:'"+ _path );
var targetActionRequest = createRequestJson( _action, _path, _value)
addLogMessage("----:Request Json : " + targetActionRequest);
_ws_conn.send( targetActionRequest );
}
var send_authorize = function(_ws_conn, _token) {
var reqId = getUniqueReqId();
var tokens = JSON.stringify({"authorization" : _token,
"www-vehicle-device": _token});
var requestJson = '{"action":"authorize","tokens":'+ tokens +' ,"requestId":"'+reqId+'"}';
addLogMessage("----:Request Json : " + requestJson);
_ws_conn.send(requestJson);
}
</script>
</html>