Sha256: a2672b5dff9711400761ae328a0fbe5a2a5b2a716902ed4d00da3fd50335a0d9

Contents?: true

Size: 1.22 KB

Versions: 40

Compression:

Stored size: 1.22 KB

Contents

require 'test_helper'

module Shipit
  class EnvironmentVariablesTest < ActiveSupport::TestCase
    def setup
      variable_defs = [
        {"name" => "FOO", "title" => "Set to 0 to foo", "default" => 1},
        {"name" => "BAR", "title" => "Set to 1 to bar", "default" => 0},
      ]
      @variable_definitions = variable_defs.map(&VariableDefinition.method(:new))
    end
    test 'empty env returns empty hash' do
      empty = {}
      assert_equal empty, EnvironmentVariables.with(nil).permit(@variable_definitions)
      assert_equal empty, EnvironmentVariables.with({}).permit(@variable_definitions)
    end

    test 'correctly sanitizes env variables' do
      env = {'FOO' => 1, 'BAR' => 1}
      assert_equal env, EnvironmentVariables.with(env).permit(@variable_definitions)
    end

    test 'empty permit raises not permitted error' do
      assert_raises(EnvironmentVariables::NotPermitted) do
        EnvironmentVariables.with('FOO' => 1).permit({})
      end
    end

    test 'throws an exception when a variable is not whitelisted' do
      env = {'UNSAFE_VARIABLE' => 1}
      assert_raises(EnvironmentVariables::NotPermitted) do
        EnvironmentVariables.with(env).permit(@variable_definitions)
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
shipit-engine-0.31.0 test/unit/environment_variables_test.rb
shipit-engine-0.30.0 test/unit/environment_variables_test.rb
shipit-engine-0.29.0 test/unit/environment_variables_test.rb
shipit-engine-0.28.1 test/unit/environment_variables_test.rb
shipit-engine-0.28.0 test/unit/environment_variables_test.rb
shipit-engine-0.27.1 test/unit/environment_variables_test.rb
shipit-engine-0.27.0 test/unit/environment_variables_test.rb
shipit-engine-0.26.0 test/unit/environment_variables_test.rb
shipit-engine-0.25.1 test/unit/environment_variables_test.rb
shipit-engine-0.25.0 test/unit/environment_variables_test.rb
shipit-engine-0.24.0 test/unit/environment_variables_test.rb
shipit-engine-0.23.1 test/unit/environment_variables_test.rb
shipit-engine-0.23.0 test/unit/environment_variables_test.rb
shipit-engine-0.22.0 test/unit/environment_variables_test.rb
shipit-engine-0.21.0 test/unit/environment_variables_test.rb
shipit-engine-0.20.1 test/unit/environment_variables_test.rb
shipit-engine-0.20.0 test/unit/environment_variables_test.rb
shipit-engine-0.19.0 test/unit/environment_variables_test.rb
shipit-engine-0.18.1 test/unit/environment_variables_test.rb
shipit-engine-0.18.0 test/unit/environment_variables_test.rb