Tester page now ready for acquire_cred, first pass of init_sec_context
[gssweb.git] / chrome / test / test.html
1 <html>
2   <head>
3     <title>GSSApi Tester Application</title>
4
5     <!-- Latest compiled and minified CSS -->
6     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
7
8     <!-- Optional theme -->
9     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
10
11   </head>
12   <body>
13   <div class="container-fluid">
14     <div class="row">
15       <div class="col-xs-4">
16         <!-- left column -->
17         <h2>GSS Import Name</h2>
18         <div class="form-group">
19           <label for="import_name_name">Name:</label>
20           <input name="import_name_name"
21                  id="import_name_name"
22                  value="HTTP@localhost.localdomain" />
23         </div>
24         <div class="form-group">
25           <label for="import_name_mech">Mechanism:</label>
26           <input name="import_name_mech"
27                  id="import_name_mech"
28                  value="{1 2 840 113554 1 2 1 4 }" />
29         </div>
30         <button id="import_name">gss_import_name</button>
31         <div id='import_response' style="overflow: auto;"></div>
32       </div>
33
34
35       <div class="col-xs-4">
36         <!-- middle column -->
37         <h2>GSS Acquire Cred</h2>
38         <div class="form-group">
39           <label for="acquire_cred_desired_name">Desired name:</label>
40           <select name="acquire_cred_desired_name" class="gss_name">
41           </select>
42         </div>
43
44         <div class="form-group">
45           <label for="acquire_cred_cred_usage">Cred Usage:</label>
46           <select name="acquire_cred_cred_usage">
47             <option value="GSS_C_INITIATE">GSS_C_INITIATE</option>
48             <option value="GSS_C_ACCEPT">GSS_C_ACCEPT</option>
49             <option value="GSS_C_BOTH">GSS_C_BOTH</option>
50           </select>
51         </div>
52
53         <div class="form-group">
54           <label for="acquire_cred_time_req">
55             Requested lifetime in seconds (0 for default 2 hours):
56           </label>
57           <input name="acquire_cred_time_req"
58                  id="acquire_cred_time_req"
59                  value="0"/>
60         </div>
61
62         <div class="form-group">
63           <label for="acquire_cred_desired_mechs">
64             Desired mechanisms (comma separated, blank for default):
65           </label>
66           <input name="acquire_cred_desired_mechs"
67                  id="acquire_cred_desired_mechs"
68                  value=""/>
69         </div>
70
71         <button id="acquire_cred">gss_acquire_cred</button>
72         <div id="acquire_response" style="overflow: auto;"></div>
73
74       </div>
75
76
77       <div class="col-xs-4">
78         <!-- right column -->
79         <h2>GSS Init Sec Context</h2>
80         <div class="form-group">
81           <label for="init_sec_context_target_name">Target name:</label>
82           <select name="init_sec_context_target_name"
83                   id="init_sec_context_target_name"
84                   class="gss_name">
85           </select>
86         </div>
87
88         <div class="form-group">
89           <label for="init_sec_context_context_handle">Context handle:</label>
90           <input name="init_sec_context_context_handle"
91                  id="init_sec_context_context_handle"/>
92         </div>
93
94         <div class="form-group">
95           <label for="init_sec_context_input_token">Input token:</label>
96           <input name="init_sec_context_input_token"
97                  id="init_sec_context_input_token"/>
98         </div>
99
100         <div class="form-group">
101           <label for="init_sec_context_mech_type">
102             Mechanism type (blank for default):
103           </label>
104           <input name="init_sec_context_mech_type"
105                  id="init_sec_context_mech_type"/>
106         </div>
107
108         <div class="form-group">
109           <label for="init_sec_context_time_req">
110             Requested lifetime in seconds (0 for default 2 hours):
111           </label>
112           <input name="init_sec_context_time_req"
113                  id="init_sec_context_time_req" value="0" />
114         </div>
115
116         <div class="form-group">
117           <label for="init_sec_context_req_flags">
118             Request flags (0 unless you know what you're doing):
119           </label>
120           <input name="init_sec_context_req_flags" 
121                  id="init_sec_context_req_flags" value="0" />
122         </div>
123
124         <button id="init_sec_context">gss_init_sec_context</button>
125         <div id="init_sec_context_response" style="overflow: auto;"></div>
126
127       </div> 
128    </div>
129
130     <div class="row">
131       <div class="col-xs-12">
132         <div class="form-group">
133           <label for="authenticate_server_path">Server Path:</label>
134           <input name="authenticate_server_path" 
135                  id="authenticate_server_path" 
136                  value="/gss" />
137         </div>
138
139         <button id="authenticate">authenticate</button>
140         <div id='authenticate_response' style="overflow: auto;"></div>
141       </div>
142     </div>
143
144   </div>
145   
146    <!-- Scripts! ------------------------------------------------------------------------------>
147    <!-- Required JQuery -->
148    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
149
150    <!-- Latest compiled and minified JavaScript -->
151    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
152
153    <!-- GSS Web script -->
154    <script src="navigator.gssweb.js"></script>
155
156     <script language="javascript">
157       var gss;
158       var gssweb;
159
160       function report(msg, elemId) {
161         var element = $(elemId);
162         element.prepend('<p>' + msg + '</p>');
163       }
164
165       function doImportName() {
166         gss = gss || new navigator.gss_eap({
167           appTag: "TestApp"
168         });
169         gss.error = function(major, minor, errMsg, appTag) 
170         {
171           report("Error", '#import_response');
172           report("Major: " + major + "; Minor: " + minor, '#import_response');
173           report("<blockquote>" + errMsg + "</blockquote>", '#import_response');
174           report("appTag: " + appTag, '#import_response');
175         };
176         gss.import_name({
177           name:      document.getElementById('import_name_name').value,
178           name_type: document.getElementById('import_name_mech').value,
179           success:   function(data, appTag) {
180                        report("GSS imported name: " + data.gss_name, '#import_response');
181                        report("appTag: " + appTag, '#import_response');
182                        newOption = $('<option></option>');
183                        newOption.attr('value', data.gss_name);
184                        newOption.append(document.getElementById('import_name_name').value);
185                        $('.gss_name').append(newOption);
186                      }
187         });
188       } // doImportName
189
190       function doAcquireCred() {
191         gss = gss || new navigator.gss_eap({
192           appTag: "TestApp"
193         });
194         gss.error = function(major, minor, errMsg, appTag) 
195         {
196           report("Error", '#acquire_response');
197           report("Major: " + major + "; Minor: " + minor, '#acquire_response');
198           report("<blockquote>" + errMsg + "</blockquote>", '#acquire_response');
199           report("appTag: " + appTag, '#acquire_response');
200         };        
201
202         var params = {
203           desired_name: document.getElementById('import_name_name').value,
204           cred_usage: document.getElementById('import_name_name').value
205         };
206         if (document.getElementById("acquire_cred_time_req").value > 0)
207         {
208           params.time_req = document.getElementById("acquire_cred_time_req").value;
209         }
210         if ("" != document.getElementById("acquire_cred_desired_mechs").value)
211         {
212           params.desired_mechs = 
213             document.getElementById("acquire_cred_desired_mechs").value;
214         }
215         
216         gss.acquire_cred(params);
217       }
218
219       /********************************************************
220        *  Call the init_sec_context routine
221        ********************************************************/
222       function doInitSecContext() {
223         gss = gss || new navigator.gss_eap({
224           appTag: "TestApp",
225           success: function(data, appTag) {
226             $('#init_sec_context_context_handle').attr("value",
227                                                        data.context_handle);
228             report("Output token: " + data.output_token,
229                    '#init_sec_context_response');
230           }
231         });
232         gss.error = function(major, minor, errMsg, appTag) 
233         {
234           report("Error",
235                  '#init_sec_context_response');
236           report("Major: " + major + "; Minor: " + minor, 
237                  '#init_sec_context_response');
238           report("<blockquote>" + errMsg + "</blockquote>",
239                  '#init_sec_context_response');
240           report("appTag: " + appTag,
241                  '#init_sec_context_response');
242         };        
243
244         var params = {
245           target_name: document.getElementById('init_sec_context_target_name').value
246         };
247         gss.init_sec_context(params);
248       }
249
250       function doAuthenticate() {
251         gssweb = gssweb || new navigator.gssweb({
252           serverPath: "/gss",
253           appTag:     "Authentication Test",
254           error:      function(errMsg) {
255                         report(errMsg, '#authenticate_response');
256                       },
257           success:    function(appData, contentType, appTag) {
258                         report(contentType, '#authenticate_response');
259                         report("Content-Type:", '#authenticate_response');
260                         report(appData, '#authenticate_response');
261                         report("Found app data:", '#authenticate_response');
262                         report("Success!", '#authenticate_response');
263                       }
264         });
265         gssweb.authenticate();
266       } // doAuthenticate
267       
268       document.addEventListener('DOMContentLoaded', function () {
269         <!-- Listen for the import name button click -->
270         document.getElementById('import_name').addEventListener(
271           'click', doImportName
272         );
273
274         <!-- Listen for the acquire cred button click -->
275         document.getElementById('acquire_cred').addEventListener(
276           'click', doAcquireCred
277         );
278
279         <!-- Listen for the import name button click -->
280         document.getElementById('init_sec_context').addEventListener(
281           'click', doInitSecContext
282         );
283
284
285         <!-- Listen for the authenticate button click -->
286         document.getElementById('authenticate').addEventListener(
287           'click', doAuthenticate
288         );
289
290       });
291
292     </script>
293
294   </body>
295 </html>