2.0.1
This commit is contained in:
parent
db6f753068
commit
d1f0c3199f
5 changed files with 43 additions and 3 deletions
|
@ -1,5 +1,9 @@
|
||||||
|
# 2.0.1
|
||||||
|
* Update badge.
|
||||||
|
* Handle userInfo + basic auth.
|
||||||
|
|
||||||
# 2.0.0
|
# 2.0.0
|
||||||
Update to work with `client@2`.
|
* Update to work with `client@2`.
|
||||||
|
|
||||||
# 2.0.0-alpha.4
|
# 2.0.0-alpha.4
|
||||||
# 2.0.0-alpha.3
|
# 2.0.0-alpha.3
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# angel_test
|
# angel_test
|
||||||
[![version 1.0.6](https://img.shields.io/badge/pub-1.0.6-brightgreen.svg)](https://pub.dartlang.org/packages/angel_test)
|
[![Pub](https://img.shields.io/pub/v/angel_test.svg)](https://pub.dartlang.org/packages/angel_test)
|
||||||
[![build status](https://travis-ci.org/angel-dart/test.svg)](https://travis-ci.org/angel-dart/test)
|
[![build status](https://travis-ci.org/angel-dart/test.svg)](https://travis-ci.org/angel-dart/test)
|
||||||
|
|
||||||
Testing utility library for the Angel framework.
|
Testing utility library for the Angel framework.
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:angel_client/base_angel_client.dart' as client;
|
import 'package:angel_client/base_angel_client.dart' as client;
|
||||||
import 'package:angel_client/io.dart' as client;
|
import 'package:angel_client/io.dart' as client;
|
||||||
|
@ -80,6 +81,19 @@ class TestClient extends client.BaseAngelClient {
|
||||||
var rq = new MockHttpRequest(request.method, request.url);
|
var rq = new MockHttpRequest(request.method, request.url);
|
||||||
request.headers.forEach(rq.headers.add);
|
request.headers.forEach(rq.headers.add);
|
||||||
|
|
||||||
|
if (request.url.userInfo.isNotEmpty) {
|
||||||
|
// Attempt to send as Basic auth
|
||||||
|
var encoded = base64Url.encode(utf8.encode(request.url.userInfo));
|
||||||
|
rq.headers.add('authorization', 'Basic $encoded');
|
||||||
|
} else if (rq.headers.value('authorization')?.startsWith('Basic ') == true) {
|
||||||
|
var encoded = rq.headers.value('authorization').substring(6);
|
||||||
|
var decoded = utf8.decode(base64Url.decode(encoded));
|
||||||
|
var oldRq = rq;
|
||||||
|
var newRq = new MockHttpRequest(rq.method, rq.uri.replace(userInfo: decoded));
|
||||||
|
oldRq.headers.forEach(newRq.headers.add);
|
||||||
|
rq = newRq;
|
||||||
|
}
|
||||||
|
|
||||||
if (authToken?.isNotEmpty == true)
|
if (authToken?.isNotEmpty == true)
|
||||||
rq.headers.add('authorization', 'Bearer $authToken');
|
rq.headers.add('authorization', 'Bearer $authToken');
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ author: Tobe O <thosakwe@gmail.com>
|
||||||
description: Testing utility library for the Angel framework. Use with package:test.
|
description: Testing utility library for the Angel framework. Use with package:test.
|
||||||
homepage: https://github.com/angel-dart/test.git
|
homepage: https://github.com/angel-dart/test.git
|
||||||
name: angel_test
|
name: angel_test
|
||||||
version: 2.0.0
|
version: 2.0.1
|
||||||
dependencies:
|
dependencies:
|
||||||
angel_client: ^2.0.0
|
angel_client: ^2.0.0
|
||||||
angel_framework: ^2.0.0-alpha
|
angel_framework: ^2.0.0-alpha
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_test/angel_test.dart';
|
import 'package:angel_test/angel_test.dart';
|
||||||
|
@ -12,6 +13,7 @@ main() {
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
app = new Angel()
|
app = new Angel()
|
||||||
..get('/hello', (req, res) => 'Hello')
|
..get('/hello', (req, res) => 'Hello')
|
||||||
|
..get('/user_info', (req, res) => {'u': req.uri.userInfo})
|
||||||
..get(
|
..get(
|
||||||
'/error',
|
'/error',
|
||||||
(req, res) => throw new AngelHttpException.forbidden(message: 'Test')
|
(req, res) => throw new AngelHttpException.forbidden(message: 'Test')
|
||||||
|
@ -83,6 +85,26 @@ main() {
|
||||||
statusCode: 403, message: 'Test', errors: ['foo', 'bar']));
|
statusCode: 403, message: 'Test', errors: ['foo', 'bar']));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('userInfo from Uri', () async {
|
||||||
|
var url = new Uri(userInfo: 'foo:bar', path: '/user_info');
|
||||||
|
print('URL: $url');
|
||||||
|
var res = await client.get(url);
|
||||||
|
print(res.body);
|
||||||
|
var m = json.decode(res.body) as Map;
|
||||||
|
expect(m, {'u': 'foo:bar'});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('userInfo from Basic auth header', () async {
|
||||||
|
var url = new Uri(path: '/user_info');
|
||||||
|
print('URL: $url');
|
||||||
|
var res = await client.get(url, headers: {
|
||||||
|
'authorization': 'Basic ' + (base64Url.encode(utf8.encode('foo:bar')))
|
||||||
|
});
|
||||||
|
print(res.body);
|
||||||
|
var m = json.decode(res.body) as Map;
|
||||||
|
expect(m, {'u': 'foo:bar'});
|
||||||
|
});
|
||||||
|
|
||||||
test('hasBody', () async {
|
test('hasBody', () async {
|
||||||
var res = await client.get('/body');
|
var res = await client.get('/body');
|
||||||
expect(res, hasBody());
|
expect(res, hasBody());
|
||||||
|
|
Loading…
Reference in a new issue