2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-09-20 10:14:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Redactable do
|
2019-01-11 19:31:00 -05:00
|
|
|
before do
|
|
|
|
stub_commonmark_sourcepos_disabled
|
|
|
|
end
|
|
|
|
|
2018-09-20 10:14:46 -04:00
|
|
|
shared_examples 'model with redactable field' do
|
|
|
|
it 'redacts unsubscribe token' do
|
|
|
|
model[field] = 'some text /sent_notifications/00000000000000000000000000000000/unsubscribe more text'
|
|
|
|
|
|
|
|
model.save!
|
|
|
|
|
|
|
|
expect(model[field]).to eq 'some text /sent_notifications/REDACTED/unsubscribe more text'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores not hexadecimal tokens' do
|
|
|
|
text = 'some text /sent_notifications/token/unsubscribe more text'
|
|
|
|
model[field] = text
|
|
|
|
|
|
|
|
model.save!
|
|
|
|
|
|
|
|
expect(model[field]).to eq text
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores not matching texts' do
|
|
|
|
text = 'some text /sent_notifications/.*/unsubscribe more text'
|
|
|
|
model[field] = text
|
|
|
|
|
|
|
|
model.save!
|
|
|
|
|
|
|
|
expect(model[field]).to eq text
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redacts the field when saving the model before creating markdown cache' do
|
|
|
|
model[field] = 'some text /sent_notifications/00000000000000000000000000000000/unsubscribe more text'
|
|
|
|
|
|
|
|
model.save!
|
|
|
|
|
|
|
|
expected = 'some text /sent_notifications/REDACTED/unsubscribe more text'
|
|
|
|
expect(model[field]).to eq expected
|
2019-01-11 19:31:00 -05:00
|
|
|
expect(model["#{field}_html"]).to eq "<p dir=\"auto\">#{expected}</p>"
|
2018-09-20 10:14:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when model is an issue' do
|
|
|
|
it_behaves_like 'model with redactable field' do
|
|
|
|
let(:model) { create(:issue) }
|
|
|
|
let(:field) { :description }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when model is a merge request' do
|
|
|
|
it_behaves_like 'model with redactable field' do
|
|
|
|
let(:model) { create(:merge_request) }
|
|
|
|
let(:field) { :description }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when model is a note' do
|
|
|
|
it_behaves_like 'model with redactable field' do
|
|
|
|
let(:model) { create(:note) }
|
|
|
|
let(:field) { :note }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when model is a snippet' do
|
|
|
|
it_behaves_like 'model with redactable field' do
|
|
|
|
let(:model) { create(:snippet) }
|
|
|
|
let(:field) { :description }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|