diff options
Diffstat (limited to 'spec/models/clusters')
-rw-r--r-- | spec/models/clusters/applications/prometheus_spec.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb index 04e4d261b1c..ecb87910d2d 100644 --- a/spec/models/clusters/applications/prometheus_spec.rb +++ b/spec/models/clusters/applications/prometheus_spec.rb @@ -330,4 +330,46 @@ describe Clusters::Applications::Prometheus do it { is_expected.to be_falsy } end end + + describe 'alert manager token' do + subject { create(:clusters_applications_prometheus) } + + context 'when not set' do + it 'is empty by default' do + expect(subject.alert_manager_token).to be_nil + expect(subject.encrypted_alert_manager_token).to be_nil + expect(subject.encrypted_alert_manager_token_iv).to be_nil + end + + describe '#generate_alert_manager_token!' do + it 'generates a token' do + subject.generate_alert_manager_token! + + expect(subject.alert_manager_token).to match(/\A\h{32}\z/) + end + end + end + + context 'when set' do + let(:token) { SecureRandom.hex } + + before do + subject.update!(alert_manager_token: token) + end + + it 'reads the token' do + expect(subject.alert_manager_token).to eq(token) + expect(subject.encrypted_alert_manager_token).not_to be_nil + expect(subject.encrypted_alert_manager_token_iv).not_to be_nil + end + + describe '#generate_alert_manager_token!' do + it 'does not re-generate the token' do + subject.generate_alert_manager_token! + + expect(subject.alert_manager_token).to eq(token) + end + end + end + end end |