Add Universign timestamp API query

This commit is contained in:
Nicolas Bouilleaud 2019-06-06 10:47:51 +02:00
parent e16cb731c5
commit dace9a53d3
6 changed files with 102 additions and 0 deletions

40
app/lib/universign/api.rb Normal file
View file

@ -0,0 +1,40 @@
class Universign::API
## Universign Timestamp POST API
# Official documentation is at https://help.universign.com/hc/fr/articles/360000898965-Guide-d-intégration-horodatage
def self.ensure_properly_configured!
if userpwd.blank?
raise StandardError, 'Universign API is not properly configured'
end
end
def self.timestamp(data)
ensure_properly_configured!
response = Typhoeus.post(
UNIVERSIGN_API_URL,
userpwd: userpwd,
body: body(data)
)
if response.success?
response.body
else
raise StandardError, "Universign timestamp query failed: #{response.status_message}"
end
end
private
def self.body(data)
{
'hashAlgo': 'SHA256',
'withCert': 'true',
'hashValue': data
}
end
def self.userpwd
Rails.application.secrets.universign[:userpwd]
end
end

View file

@ -66,3 +66,6 @@ TRUSTED_NETWORKS=""
SKYLIGHT_AUTHENTICATION_KEY=""
LOGRAGE_ENABLED="disabled"
UNIVERSIGN_API_URL=""
UNIVERSIGN_USERPWD=""

View file

@ -7,6 +7,7 @@ API_GEO_SANDBOX_URL = ENV.fetch("API_GEO_SANDBOX_URL", "https://sandbox.geo.api.
HELPSCOUT_API_URL = ENV.fetch("HELPSCOUT_API_URL", "https://api.helpscout.net/v2")
PIPEDRIVE_API_URL = ENV.fetch("PIPEDRIVE_API_URL", "https://api.pipedrive.com/v1")
SENDINBLUE_API_URL = ENV.fetch("SENDINBLUE_API_URL", "https://in-automate.sendinblue.com/api/v2")
UNIVERSIGN_API_URL = ENV.fetch("UNIVERSIGN_API_URL", "https://ws.universign.eu/tsa/post/")
# Internal URLs
FOG_BASE_URL = "https://static.demarches-simplifiees.fr"

View file

@ -64,6 +64,8 @@ defaults: &defaults
crisp:
enabled: <%= ENV['CRISP_ENABLED'] == 'enabled' %>
client_key: <%= ENV['CRISP_CLIENT_KEY'] %>
universign:
userpwd: <%= ENV['UNIVERSIGN_USERPWD'] %>
@ -90,6 +92,8 @@ test:
token_endpoint: https://bidon.com/endpoint
userinfo_endpoint: https://bidon.com/endpoint
logout_endpoint: https://bidon.com/endpoint
universign:
userpwd: 'fake:fake'
# Do not keep production secrets in the repository,
# instead read values from the environment.

43
spec/fixtures/cassettes/universign.yml vendored Normal file
View file

@ -0,0 +1,43 @@
---
http_interactions:
- request:
method: post
uri: https://ws.universign.eu/tsa/post/
body:
encoding: UTF-8
string: hashAlgo=SHA256&hashValue=d28d6c7742c6c77025a104b81750ce8dc5f7dba2d01d9b5f4cad828f02b2324b&withCert=true
headers:
User-Agent:
- demarches-simplifiees.fr
Expect:
- ''
Authorization:
- Basic cmllbiBpY2kK=
response:
status:
code: 200
message: OK
headers:
Date:
- Fri, 17 May 2019 10:05:12 GMT
Server:
- Apache
Cache-Control:
- no-cache
Pragma:
- no-cache
Content-Type:
- application/octet-stream
Set-Cookie:
- CGSESSIONID=A3D72C1B0D07C073CFE68597B3FBF1B6E639C351;Path=/;Version=0
X-Ua-Compatible:
- IE=Edge
Transfer-Encoding:
- chunked
body:
encoding: ASCII-8BIT
string: !binary |-
MIIHvAYJKoZIhvcNAQcCoIIHrTCCB6kCAQMxDzANBglghkgBZQMEAgEFADCBxwYLKoZIhvcNAQkQAQSggbcEgbQwgbECAQEGBCoDBAUwMTANBglghkgBZQMEAgEFAAQg0o1sd0LGx3AloQS4F1DOjcX326LQHZtfTK2CjwKyMksCFQCGAZpWDFVXaMOe1wHG3iVRUofhGxgTMjAxOTA1MTcxMDA1MTIuNTUyWjADgAEBAQH/oD+kPTA7MQswCQYDVQQGEwJGUjESMBAGA1UEChMJQ3J5cHRvbG9nMRgwFgYDVQQDEw9UZXN0IFRTQSAtIFRVIDWgggReMIIEWjCCA0KgAwIBAgIUdG+qwQPj0VPrIVMSA2dAelI+Cf8wDQYJKoZIhvcNAQELBQAwQzELMAkGA1UEBhMCRlIxEjAQBgNVBAoTCUNyeXB0b2xvZzEgMB4GA1UEAxMXVGVzdCBVbml2ZXJzaWduIENB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IbUiMKn1G5E4muyafMTFfdpQ==
http_version:
recorded_at: Fri, 17 May 2019 10:05:12 GMT
recorded_with: VCR 4.0.0

View file

@ -0,0 +1,11 @@
require 'spec_helper'
describe Universign::API do
describe '.request_timestamp', vcr: { cassette_name: 'universign' } do
subject { described_class.timestamp(digest) }
let(:digest) { Digest::SHA256.hexdigest("CECI EST UN HASH") }
it { is_expected.not_to be_nil }
end
end