spec/unit/helpers/global_helpers_spec.rb in gooddata-0.6.51 vs spec/unit/helpers/global_helpers_spec.rb in gooddata-0.6.52
- old
+ new
@@ -108,10 +108,23 @@
"d" => { "b" => { "c" => "a", "e" => { "f" => "g", "w" => "z" }, "foo" => "bar" } },
"gd_encoded_hidden_params" => nil
)
end
+ context 'when hidden parameters contain an invalid json' do
+ let(:invalid_json) { '{"password": "precious_secret"' }
+ let(:params) do
+ { GoodData::Helpers::ENCODED_HIDDEN_PARAMS_KEY.to_s => invalid_json }
+ end
+
+ it 'hides secrets in the error message' do
+ expect { GoodData::Helpers.decode_params(params) }.to raise_error(JSON::ParserError) do |e|
+ expect(e.message).not_to include('precious_secret')
+ end
+ end
+ end
+
it 'should encode reference parameters in gd_encoded_params' do
params = {
'x' => 'y',
'ads_password' => 'ads_123',
'my_password' => 'login_123',
@@ -212,8 +225,24 @@
context 'when error key is empty' do
let(:error_message) { { 'error' => {} } }
it 'returns nil' do
expect(@message).to be_nil
end
+ end
+ end
+
+ describe '.decode_params' do
+ it 'interpolates reference parameters in additional_hidden_params' do
+ params = {
+ 'gd_encoded_hidden_params' => '{ "additional_hidden_params": { "secret": "${my_password}" } }',
+ 'my_password' => "123"
+ }
+ expected_result = {
+ 'gd_encoded_hidden_params' => nil,
+ 'additional_hidden_params' => { 'secret' => '123' },
+ 'my_password' => '123'
+ }
+ result = GoodData::Helpers.decode_params(params, :resolve_reference_params => true)
+ expect(result).to eq(expected_result)
end
end
end