Merge pull request #5804 from betagouv/dev

2020-12-14-01
This commit is contained in:
LeSim 2020-12-14 21:42:32 +01:00 committed by GitHub
commit 4e5c1c08b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 37 deletions

1
.gitignore vendored
View file

@ -27,6 +27,7 @@ yarn-debug.log*
.yarn-integrity .yarn-integrity
/.vscode /.vscode
/.idea /.idea
/public/assets
/public/packs /public/packs
/public/packs-test /public/packs-test
/node_modules /node_modules

View file

@ -92,25 +92,27 @@ class BillSignature < ApplicationRecord
end end
def read_signature def read_signature
if attachment_changes['signature'] read_attachment('signature')
io = io_for_changes(attachment_changes['signature'])
io.read if io.present?
elsif signature.attached?
signature.download
end
end end
def read_serialized def read_serialized
if attachment_changes['serialized'] read_attachment('serialized')
io = io_for_changes(attachment_changes['serialized']) end
io.read if io.present?
private
def read_attachment(attachment)
if attachment_changes[attachment]
io = io_for_changes(attachment_changes[attachment])
if io.present?
io.rewind
io.read
end
elsif serialized.attached? elsif serialized.attached?
serialized.download serialized.download
end end
end end
private
def io_for_changes(attachment_changes) def io_for_changes(attachment_changes)
attachable = attachment_changes.attachable attachable = attachment_changes.attachable
case attachable case attachable

View file

@ -568,7 +568,7 @@ class Procedure < ApplicationRecord
if logo.attached? if logo.attached?
Rails.application.routes.url_helpers.url_for(logo) Rails.application.routes.url_helpers.url_for(logo)
else else
ActionController::Base.helpers.image_url("republique-francaise-logo.svg") ActionController::Base.helpers.image_url(PROCEDURE_DEFAULT_LOGO_SRC)
end end
end end

View file

@ -19,7 +19,7 @@
%h2.header-section Informations de contact %h2.header-section Informations de contact
%p.explication %p.explication
Votre démarche sera hébergée par demarche-simplifiees.fr mais nous ne pouvons pas assurer le support des démarches. Et malgré la dématérialisation, les usagers se poseront parfois des questions légitimes sur le processus administratif. Votre démarche sera hébergée par #{APPLICATION_NAME} mais nous ne pouvons pas assurer le support des démarches. Et malgré la dématérialisation, les usagers se poseront parfois des questions légitimes sur le processus administratif.
%br %br
Il est donc important que les usagers puissent vous contacter s'ils ont des questions sur votre démarche. Il est donc important que les usagers puissent vous contacter s'ils ont des questions sur votre démarche.
%br %br

View file

@ -41,5 +41,8 @@ APPLICATION_BASE_URL="https://www.demarches-simplifiees.fr"
# Personnalisation d'instance - Logo dans l'entête des emails ---> à placer dans "app/assets/images" # Personnalisation d'instance - Logo dans l'entête des emails ---> à placer dans "app/assets/images"
# MAILER_LOGO_SRC="mailer/instructeur_mailer/logo.png" # MAILER_LOGO_SRC="mailer/instructeur_mailer/logo.png"
# Personnalisation d'instance - Logo par défaut d'une procédure ---> à placer dans "app/assets/images"
# PROCEDURE_DEFAULT_LOGO_SRC="republique-francaise-logo.svg"
# Personnalisation d'instance - fichier utilisé pour poser un filigrane sur les pièces d'identité # Personnalisation d'instance - fichier utilisé pour poser un filigrane sur les pièces d'identité
# WATERMARK_FILE="" # WATERMARK_FILE=""

View file

@ -11,3 +11,6 @@ HEADER_LOGO_HEIGHT = ENV.fetch("HEADER_LOGO_HEIGHT", "56")
# Mailer logo # Mailer logo
MAILER_LOGO_SRC = ENV.fetch("MAILER_LOGO_SRC", "mailer/instructeur_mailer/logo.png") MAILER_LOGO_SRC = ENV.fetch("MAILER_LOGO_SRC", "mailer/instructeur_mailer/logo.png")
# Default logo of a procedure
PROCEDURE_DEFAULT_LOGO_SRC = ENV.fetch("PROCEDURE_DEFAULT_LOGO_SRC", "republique-francaise-logo.svg")

View file

@ -72,48 +72,41 @@ RSpec.describe BillSignature, type: :model do
end end
describe 'check_signature_contents' do describe 'check_signature_contents' do
let(:signature) { File.open('spec/fixtures/files/bill_signature/signature.der') }
let(:signature_date) { DateTime.parse('2019-04-30 15:30:20') }
let(:signature_digest) { Digest::SHA256.hexdigest('CECI EST UN BLOB') }
let(:current_date) { Time.zone.now }
before do before do
bill_signature.signature.attach(io: StringIO.new(signature), filename: 'file') if signature.present? Timecop.freeze(current_date)
allow(ASN1::Timestamp).to receive(:signature_time).and_return(signature_time) bill_signature.signature.attach(io: signature, filename: 'file') if signature.present?
allow(ASN1::Timestamp).to receive(:signed_digest).and_return(signed_digest) bill_signature.digest = signature_digest
bill_signature.digest = digest
bill_signature.valid? bill_signature.valid?
Timecop.return
end end
context 'when the signature is correct' do subject { bill_signature.errors.details[:signature] }
let(:signature) { 'signature' }
let(:signature_time) { 1.day.ago }
let(:digest) { 'abcd' }
let(:signed_digest) { 'abcd' }
it { expect(bill_signature.errors.details[:signature]).to be_empty } context 'when the signature is correct' do
it { is_expected.to be_empty }
end end
context 'when the signature isnt set' do context 'when the signature isnt set' do
let(:signature) { nil } let(:signature) { nil }
let(:signature_time) { 1.day.ago }
let(:digest) { 'abcd' }
let(:signed_digest) { 'abcd' }
it { expect(bill_signature.errors.details[:signature]).to eq [error: :blank] } it { is_expected.to eq [error: :blank] }
end end
context 'when the signature time is in the future' do context 'when the signature time is in the future' do
let(:signature) { 'signature' } let(:current_date) { signature_date - 1.day }
let(:signature_time) { 1.day.from_now }
let(:digest) { 'abcd' }
let(:signed_digest) { 'abcd' }
it { expect(bill_signature.errors.details[:signature]).to eq [error: :invalid_date] } it { is_expected.to eq [error: :invalid_date] }
end end
context 'when the signature doesnt match the digest' do context 'when the signature doesnt match the digest' do
let(:signature) { 'signature' } let(:signature_digest) { 'dcba' }
let(:signature_time) { 1.day.ago }
let(:digest) { 'abcd' }
let(:signed_digest) { 'dcba' }
it { expect(bill_signature.errors.details[:signature]).to eq [error: :invalid] } it { is_expected.to eq [error: :invalid] }
end end
end end
end end