From 76d464e9dd11085d1b03d41d05699c2d0ce46ab0 Mon Sep 17 00:00:00 2001 From: HTWKalender Team Date: Fri, 20 Sep 2024 04:25:57 -0400 Subject: [PATCH] Content Security Policy for iFrame embedding --- .../initializers/content_security_policy.rb | 2 +- lib/cabal_adapter.rb | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 lib/cabal_adapter.rb diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 87ea9938..0d3e90d8 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -71,7 +71,7 @@ Rails.application.configure do # The `child_src` directive is only a fallback for browsers not supporting `worker_src`. policy.child_src :self, :blob policy.form_action :self - policy.frame_ancestors :none + policy.frame_ancestors :self, 'https://*.htwk-leipzig.de' policy.frame_src :none policy.manifest_src :none diff --git a/lib/cabal_adapter.rb b/lib/cabal_adapter.rb new file mode 100644 index 00000000..41b220f6 --- /dev/null +++ b/lib/cabal_adapter.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class CabalAdapter < TestingFrameworkAdapter + # Regular expressions to extract the number of test suites, test cases, and their status + COUNT_REGEXP = /(\d+) of \d+ test suites \((\d+) of \d+ test cases\)/ + PASS_REGEXP = /passed/ + FAIL_REGEXP = /failed/ + + def self.framework_name + 'Haskell Cabal' + end + + # Parse the output from Cabal test suite + def parse_output(output) + # Extract the total count of test suites and test cases + count_match = output[:stdout].scan(COUNT_REGEXP).last + test_cases_count = count_match&.last&.to_i || 0 + + # Check if the test suite passed or failed + passed = output[:stdout] =~ PASS_REGEXP + failed = output[:stdout] =~ FAIL_REGEXP + + if passed + {count: test_cases_count, passed: test_cases_count} + elsif failed + {count: test_cases_count, failed: test_cases_count} + else + {count: test_cases_count, passed: 0, failed: 0} + end + end +end