demarches-normaliennes/spec/services/bill_signature_service_spec.rb
Martin a4d6692bc6 accessibilite(pages-authentification): evolutions des pages de connexion/creation de compte pour respecter le DSFR et supporter une meilleure accessibilite
Update app/components/dsfr/input_component/input_component.html.haml

Co-authored-by: Colin Darie <colin@darie.eu>
2023-01-03 16:26:05 +01:00

82 lines
2.5 KiB
Ruby
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

describe BillSignatureService do
describe ".grouped_unsigned_operation_until" do
subject { BillSignatureService.grouped_unsigned_operation_until(date).length }
let(:date) { Time.zone.now.beginning_of_day }
context "when operations of several days need to be signed" do
before do
create :dossier_operation_log, executed_at: 3.days.ago
create :dossier_operation_log, executed_at: 2.days.ago
create :dossier_operation_log, executed_at: 1.day.ago
end
it { is_expected.to eq 3 }
end
context "when operations on a single day need to be signed" do
before do
create :dossier_operation_log, executed_at: 1.day.ago
create :dossier_operation_log, executed_at: 1.day.ago
end
it { is_expected.to eq 1 }
end
context "when there are no operations to be signed" do
before do
create :dossier_operation_log, created_at: 1.day.ago, bill_signature: build(:bill_signature, :with_signature, :with_serialized)
create :dossier_operation_log, created_at: 1.day.from_now
end
it { is_expected.to eq 0 }
end
end
describe ".sign_operations" do
let(:date) { Date.today }
let(:operations_hash) { [['1', 'hash1'], ['2', 'hash2']] }
let(:operations) do
operations_hash
.map { |id, digest| DossierOperationLog.new(id:, digest:, operation: 'accepter') }
end
let(:timestamp) { File.read('spec/fixtures/files/bill_signature/signature.der') }
subject { BillSignatureService.sign_operations(operations, date) }
before do
DossierOperationLog.where(id: [1, 2]).destroy_all
expect(Certigna::API).to receive(:timestamp).and_return(timestamp)
end
context "when everything is fine" do
it do
expect { subject }.not_to raise_error
expect(BillSignature.count).to eq(1)
end
end
context "when the digest does not match with the pre recorded timestamp token" do
let(:operations_hash) { [['1', 'hash1'], ['2', 'hash3']] }
it do
expect { subject }.to raise_error(/La validation a échoué : Le champ « signature » ne correspond pas à lempreinte/)
expect(BillSignature.count).to eq(0)
end
end
context "when the timestamp token cannot be verified by openssl" do
let(:timestamp) do
File.read('spec/fixtures/files/bill_signature/signature.der').tap { |s| s[-1] = 'd' }
end
it do
expect { subject }.to raise_error(/openssl verification failed/)
expect(BillSignature.count).to eq(0)
end
end
end
end