From ec7bff58c19a9df410f9fa170084a25c30445787 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Fri, 22 Dec 2017 08:39:21 -0500 Subject: [PATCH] 1.1.0 --- .idea/libraries/Dart_Packages.xml | 24 ++++++++++++++ .idea/runConfigurations/tests_in_security.xml | 8 +++++ pubspec.yaml | 27 ++++++++-------- test/pretty_logging.dart | 32 +++++++++++++++++++ test/sanitize_test.dart | 6 ++-- test/throttle_test.dart | 12 +++++-- 6 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 .idea/runConfigurations/tests_in_security.xml create mode 100644 test/pretty_logging.dart diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml index ceaa2758..de4f5535 100644 --- a/.idea/libraries/Dart_Packages.xml +++ b/.idea/libraries/Dart_Packages.xml @@ -135,6 +135,13 @@ + + + + + + @@ -345,6 +352,13 @@ + + + + + + @@ -471,6 +485,13 @@ + + + + + + @@ -514,6 +535,7 @@ + @@ -544,6 +566,7 @@ + @@ -562,6 +585,7 @@ + diff --git a/.idea/runConfigurations/tests_in_security.xml b/.idea/runConfigurations/tests_in_security.xml new file mode 100644 index 00000000..85440c0d --- /dev/null +++ b/.idea/runConfigurations/tests_in_security.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 0fb1e30d..eb7fd777 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,14 +1,15 @@ -name: angel_security -version: 1.1.0 -description: Angel middleware designed to enhance application security by patching common Web security holes. -author: Tobe O -environment: +author: "Tobe O " +description: "Angel middleware designed to enhance application security by patching common Web security holes." +homepage: "https://github.com/angel-dart/security" +name: "angel_security" +version: "1.1.0" +dependencies: + angel_framework: "^1.1.0" +dev_dependencies: + angel_auth: "^1.1.0" + angel_test: "^1.1.0" + angel_validate: "^1.0.0" + console: "^2.2.4" + test: "^0.12.0" +environment: sdk: ">=1.19.0" -homepage: https://github.com/angel-dart/security -dependencies: - angel_framework: ^1.1.0 -dev_dependencies: - angel_auth: ^1.1.0 - angel_validate: ^1.0.0 - angel_test: ^1.1.0 - test: ^0.12.0 \ No newline at end of file diff --git a/test/pretty_logging.dart b/test/pretty_logging.dart new file mode 100644 index 00000000..ceeabe80 --- /dev/null +++ b/test/pretty_logging.dart @@ -0,0 +1,32 @@ +import 'package:console/console.dart'; +import 'package:logging/logging.dart'; + +/// Prints the contents of a [LogRecord] with pretty colors. +prettyLog(LogRecord record) async { + var pen = new TextPen(); + chooseLogColor(pen.reset(), record.level); + pen(record.toString()); + + if (record.error != null) + pen(record.error.toString()); + if (record.stackTrace != null) + pen(record.stackTrace.toString()); + + pen(); +} + +/// Chooses a color based on the logger [level]. +void chooseLogColor(TextPen pen, Level level) { + if (level == Level.SHOUT) + pen.darkRed(); + else if (level == Level.SEVERE) + pen.red(); + else if (level == Level.WARNING) + pen.yellow(); + else if (level == Level.INFO) + pen.magenta(); + else if (level == Level.FINER) + pen.blue(); + else if (level == Level.FINEST) + pen.darkBlue(); +} diff --git a/test/sanitize_test.dart b/test/sanitize_test.dart index c9878c19..f4361f61 100644 --- a/test/sanitize_test.dart +++ b/test/sanitize_test.dart @@ -1,11 +1,12 @@ import 'dart:io'; -import 'package:angel_diagnostics/angel_diagnostics.dart'; import 'package:angel_framework/angel_framework.dart'; import 'package:angel_security/angel_security.dart'; import 'package:angel_test/angel_test.dart'; import 'package:angel_validate/server.dart'; +import 'package:logging/logging.dart'; import 'package:matcher/matcher.dart'; import 'package:test/test.dart'; +import 'pretty_logging.dart'; final Validator untrustedSchema = new Validator({'html*': isString}); @@ -45,7 +46,8 @@ main() async { '''); }); - await app.configure(logRequests(new File('log.txt'))); + app.logger = new Logger.detached('angel_security') + ..onRecord.listen(prettyLog); client = await connectTo(app); }); diff --git a/test/throttle_test.dart b/test/throttle_test.dart index 7da3ba26..14c10580 100644 --- a/test/throttle_test.dart +++ b/test/throttle_test.dart @@ -25,12 +25,16 @@ main() { test('once per hour', () async { // First request within the hour is fine - var response = await client.get('/once-per-hour'); + var response = await client.get('/once-per-hour', headers: { + 'accept': 'application/json', + }); print(response.body); expect(response, hasBody('"OK"')); // Second request within an hour? No no no! - response = await client.get('/once-per-hour'); + response = await client.get('/once-per-hour', headers: { + 'accept': 'application/json', + }); print(response.body); expect(response, isAngelHttpException(statusCode: 429)); }); @@ -54,7 +58,9 @@ main() { expect(response, hasBody('"OK"')); // Fourth request within a minute? No no no! - response = await client.get('/thrice-per-minute'); + response = await client.get('/thrice-per-minute', headers: { + 'accept': 'application/json', + }); print(response.body); expect(response, isAngelHttpException(statusCode: 429)); });