diff --git a/features/plugins.feature b/features/plugins.feature new file mode 100644 index 00000000..4e6d9d86 --- /dev/null +++ b/features/plugins.feature @@ -0,0 +1,34 @@ +Feature: Configuring and using plugins + As a hacker + I want to specify my own plugins that can modify Jekyll's behaviour + + Scenario: Add a gem-based plugin + Given I have an "index.html" file that contains "Whatever" + And I have a configuration file with "gems" set to "[jekyll_test_plugin]" + When I run jekyll build + Then the _site directory should exist + And I should see "Whatever" in "_site/index.html" + And I should see "this is a test" in "_site/test.txt" + + Scenario: Add an empty whitelist to restrict all gems + Given I have an "index.html" file that contains "Whatever" + And I have a configuration file with: + | key | value | + | gems | [jekyll_test_plugin] | + | whitelist | [] | + When I run jekyll build --safe + Then the _site directory should exist + And I should see "Whatever" in "_site/index.html" + And the "_site/test.txt" file should not exist + + Scenario: Add a whitelist to restrict some gems but allow others + Given I have an "index.html" file that contains "Whatever" + And I have a configuration file with: + | key | value | + | gems | [jekyll_test_plugin, jekyll_test_plugin_malicious] | + | whitelist | [jekyll_test_plugin] | + When I run jekyll build --safe + Then the _site directory should exist + And I should see "Whatever" in "_site/index.html" + And the "_site/test.txt" file should exist + And I should see "this is a test" in "_site/test.txt" \ No newline at end of file diff --git a/features/site_configuration.feature b/features/site_configuration.feature index 8aaa9e1d..1d067f0c 100644 --- a/features/site_configuration.feature +++ b/features/site_configuration.feature @@ -243,37 +243,6 @@ Feature: Site configuration And I should see "Post Layout:

content for entry1.

" in "_site/2007/12/31/entry1.html" And I should see "Post Layout:

content for entry2.

" in "_site/2020/01/31/entry2.html" - Scenario: Add a gem-based plugin - Given I have an "index.html" file that contains "Whatever" - And I have a configuration file with "gems" set to "[jekyll_test_plugin]" - When I run jekyll build - Then the _site directory should exist - And I should see "Whatever" in "_site/index.html" - And I should see "this is a test" in "_site/test.txt" - - Scenario: Add an empty whitelist to restrict all gems - Given I have an "index.html" file that contains "Whatever" - And I have a configuration file with: - | key | value | - | gems | [jekyll_test_plugin] | - | whitelist | [] | - When I run jekyll build --safe - Then the _site directory should exist - And I should see "Whatever" in "_site/index.html" - And the "_site/test.txt" file should not exist - - Scenario: Add a whitelist to restrict some gems but allow others - Given I have an "index.html" file that contains "Whatever" - And I have a configuration file with: - | key | value | - | gems | [jekyll_test_plugin, jekyll_test_plugin_malicious] | - | whitelist | [jekyll_test_plugin] | - When I run jekyll build --safe - Then the _site directory should exist - And I should see "Whatever" in "_site/index.html" - And the "_site/test.txt" file should exist - And I should see "this is a test" in "_site/test.txt" - Scenario: arbitrary file reads via layouts Given I have an "index.html" page with layout "page" that contains "FOO" And I have a "_config.yml" file that contains "layouts: '../../../../../../../../../../../../../../usr/include'" diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 8be4ea2f..b75379f5 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -146,6 +146,13 @@ When /^I run jekyll(.*)$/ do |args| end end +When /^I run bundle(.*)$/ do |args| + status = run_bundle(args) + if args.include?("--verbose") || ENV['DEBUG'] + puts jekyll_run_output + end +end + When /^I change "(.*)" to contain "(.*)"$/ do |file, text| File.open(file, 'a') do |f| f.write(text) diff --git a/features/support/env.rb b/features/support/env.rb index 996c79ba..8bb0274d 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -21,11 +21,19 @@ def jekyll_run_output File.read(jekyll_output_file) if File.file?(jekyll_output_file) end +def run_bundle(args) + child = run_in_shell('bundle', *args.strip.split(' ')) +end + def run_jekyll(args) - child = POSIX::Spawn::Child.new JEKYLL_PATH, *args.strip.split(' '), "--trace", :out => [JEKYLL_COMMAND_OUTPUT_FILE, "w"] + child = run_in_shell(JEKYLL_PATH, *args.strip.split(' '), "--trace") child.status.exitstatus == 0 end +def run_in_shell(args, options) + POSIX::Spawn::Child.new *args, :out => [JEKYLL_COMMAND_OUTPUT_FILE, "w"]) +end + def slug(title) if title title.downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')