| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import "package:crypto/crypto.dart"; | 5 import "package:crypto/crypto.dart"; |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 import 'dart:convert'; | 10 import 'dart:convert'; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 password = request.uri.path.substring(1, 6); | 35 password = request.uri.path.substring(1, 6); |
| 36 } | 36 } |
| 37 if (passwordChanged) password = "${password}1"; | 37 if (passwordChanged) password = "${password}1"; |
| 38 if (request.headers[HttpHeaders.AUTHORIZATION] != null) { | 38 if (request.headers[HttpHeaders.AUTHORIZATION] != null) { |
| 39 Expect.equals(1, request.headers[HttpHeaders.AUTHORIZATION].length); | 39 Expect.equals(1, request.headers[HttpHeaders.AUTHORIZATION].length); |
| 40 String authorization = | 40 String authorization = |
| 41 request.headers[HttpHeaders.AUTHORIZATION][0]; | 41 request.headers[HttpHeaders.AUTHORIZATION][0]; |
| 42 List<String> tokens = authorization.split(" "); | 42 List<String> tokens = authorization.split(" "); |
| 43 Expect.equals("Basic", tokens[0]); | 43 Expect.equals("Basic", tokens[0]); |
| 44 String auth = | 44 String auth = |
| 45 CryptoUtils.bytesToBase64(UTF8.encode("$username:$password")); | 45 BASE64.encode(UTF8.encode("$username:$password")); |
| 46 if (passwordChanged && auth != tokens[1]) { | 46 if (passwordChanged && auth != tokens[1]) { |
| 47 response.statusCode = HttpStatus.UNAUTHORIZED; | 47 response.statusCode = HttpStatus.UNAUTHORIZED; |
| 48 response.headers.set(HttpHeaders.WWW_AUTHENTICATE, | 48 response.headers.set(HttpHeaders.WWW_AUTHENTICATE, |
| 49 "Basic, realm=realm"); | 49 "Basic, realm=realm"); |
| 50 } else { | 50 } else { |
| 51 Expect.equals(auth, tokens[1]); | 51 Expect.equals(auth, tokens[1]); |
| 52 } | 52 } |
| 53 } else { | 53 } else { |
| 54 response.statusCode = HttpStatus.UNAUTHORIZED; | 54 response.statusCode = HttpStatus.UNAUTHORIZED; |
| 55 response.headers.set(HttpHeaders.WWW_AUTHENTICATE, | 55 response.headers.set(HttpHeaders.WWW_AUTHENTICATE, |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 main() { | 259 main() { |
| 260 testUrlUserInfo(); | 260 testUrlUserInfo(); |
| 261 testBasicNoCredentials(); | 261 testBasicNoCredentials(); |
| 262 testBasicCredentials(); | 262 testBasicCredentials(); |
| 263 testBasicAuthenticateCallback(); | 263 testBasicAuthenticateCallback(); |
| 264 // These teste are not normally run. They can be used for locally | 264 // These teste are not normally run. They can be used for locally |
| 265 // testing with another web server (e.g. Apache). | 265 // testing with another web server (e.g. Apache). |
| 266 //testLocalServerBasic(); | 266 //testLocalServerBasic(); |
| 267 //testLocalServerDigest(); | 267 //testLocalServerDigest(); |
| 268 } | 268 } |
| OLD | NEW |