platform/test/trust_proxy_test.dart

36 lines
1,001 B
Dart
Raw Normal View History

2017-01-14 00:45:35 +00:00
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';
2019-04-20 14:53:52 +00:00
verifyProxy(RequestContext req, ResponseContext res) =>
req.container.has<ForwardedClient>() ? 'Yep' : 'Nope';
2017-01-14 00:45:35 +00:00
main() {
Angel app;
TestClient client;
setUp(() async {
2019-04-20 14:53:52 +00:00
app = Angel()
..chain([trustProxy('127.*.*.*')]).get('/hello', verifyProxy)
..chain([trustProxy('1.2.3.4')]).get('/foo', verifyProxy);
2017-01-14 00:45:35 +00:00
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'));
});
}