summaryrefslogtreecommitdiff
path: root/spec/models/grafana_integration_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/grafana_integration_spec.rb')
-rw-r--r--spec/models/grafana_integration_spec.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/spec/models/grafana_integration_spec.rb b/spec/models/grafana_integration_spec.rb
index 615865e17b9..662e8b1dd61 100644
--- a/spec/models/grafana_integration_spec.rb
+++ b/spec/models/grafana_integration_spec.rb
@@ -9,7 +9,7 @@ describe GrafanaIntegration do
describe 'validations' do
it { is_expected.to validate_presence_of(:project) }
- it { is_expected.to validate_presence_of(:token) }
+ it { is_expected.to validate_presence_of(:encrypted_token) }
it 'disallows invalid urls for grafana_url' do
unsafe_url = %{https://replaceme.com/'><script>alert(document.cookie)</script>}
@@ -66,4 +66,24 @@ describe GrafanaIntegration do
end
end
end
+
+ describe 'attribute encryption' do
+ subject(:grafana_integration) { create(:grafana_integration, token: 'super-secret') }
+
+ context 'token' do
+ it 'encrypts original value into encrypted_token attribute' do
+ expect(grafana_integration.encrypted_token).not_to be_nil
+ end
+
+ it 'locks access to raw value in private method', :aggregate_failures do
+ expect { grafana_integration.token }.to raise_error(NoMethodError, /private method .token. called/)
+ expect(grafana_integration.send(:token)).to eql('super-secret')
+ end
+
+ it 'prevents overriding token value with its encrypted or masked version', :aggregate_failures do
+ expect { grafana_integration.update(token: grafana_integration.encrypted_token) }.not_to change { grafana_integration.reload.send(:token) }
+ expect { grafana_integration.update(token: grafana_integration.masked_token) }.not_to change { grafana_integration.reload.send(:token) }
+ end
+ end
+ end
end