platform/test/trust_proxy_test.dart
thosakwe 75a96a4bab +2
2017-01-13 19:45:35 -05:00

35 lines
987 B
Dart

import 'package:angel_framework/angel_framework.dart';
import 'package:angel_security/angel_security.dart';
import 'package:angel_test/angel_test.dart';
import 'package:test/test.dart';
verifyProxy(RequestContext req) =>
req.injections.containsKey(ForwardedClient) ? 'Yep' : 'Nope';
main() {
Angel app;
TestClient client;
setUp(() async {
app = new Angel()
..chain(trustProxy('127.*.*.*')).get('/hello', verifyProxy)
..chain(trustProxy('1.2.3.4')).get('/foo', verifyProxy);
client = await connectTo(app);
});
tearDown(() => client.close());
test('wildcard', () async {
var response =
await client.get('/hello', headers: {'X-Forwarded-Host': 'foo'});
print(response.body);
expect(response.body, contains('Yep'));
});
test('exclude unknown', () async {
var response =
await client.get('/foo', headers: {'X-Forwarded-Host': 'foo'});
print(response.body);
expect(response.body, contains('Nope'));
});
}