Skip to content

Commit

Permalink
APPEALS-21595 Concept branch (#263)
Browse files Browse the repository at this point in the history
* Clone doc upload requests to make doc update requests

* Add missing document_version_reference_id

* Fix XML tag

* Update version

* Add requires

* More fixes

* Add init update test

* Bug extermination

* Add updateDocument specs

---------

Co-authored-by: Matthew Thornton <[email protected]>
  • Loading branch information
ThorntonMatthew and ThorntonMatthew authored May 31, 2023
1 parent 43654a0 commit 98b1f9f
Show file tree
Hide file tree
Showing 11 changed files with 350 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Vagrantfile
.DS_Store
spec/fixtures/test_client.*
spec/fixtures/test_server.*
.byebug_history
2 changes: 2 additions & 0 deletions lib/vbms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
require "vbms/requests/get_document_content"
require "vbms/requests/initialize_upload"
require "vbms/requests/upload_document"
require "vbms/requests/initialize_update"
require "vbms/requests/update_document"
require "vbms/requests/list_type_category"

require "vbms/helpers/xml_helper"
Expand Down
53 changes: 53 additions & 0 deletions lib/vbms/requests/initialize_update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

module VBMS
module Requests
# Call this service with metadata to receive a token used in the second call, updateDocument
class InitializeUpdate < BaseRequest
def initialize(content_hash:, document_version_reference_id:, va_receive_date:, subject:)
super()
@content_hash = content_hash
@document_version_reference_id = document_version_reference_id
@va_receive_date = va_receive_date
@subject = subject
end

def name
"initializeUpdate"
end

def endpoint_url(base_url)
"#{base_url}#{VBMS::ENDPOINTS[:efolder_svc_v1][:upload]}"
end

def va_receive_date
@va_receive_date.getlocal("-05:00").strftime("%Y-%m-%d-05:00")
end

def soap_doc
document = VBMS::Requests.soap do |xml|
xml["upload"].initializeUpdate do
xml.documentVersionReferenceId @document_version_reference_id
xml.contentHash @content_hash
xml.vaReceiveDate va_receive_date
end
end

XMLHelper.remove_namespaces(document.at_xpath("//upload:initializeUpdate").children)
document
end

def signed_elements
[["/soapenv:Envelope/soapenv:Body",
{ soapenv: SoapScum::XMLNamespaces::SOAPENV },
"Content"]]
end

def handle_response(doc)
el = doc.at_xpath("//upload:initializeUpdateResponse", VBMS::XML_NAMESPACES).to_xml

OpenStruct.new(updated_document_token: XMLHelper.convert_to_hash(el)[:initialize_update_response][:upload_token])
end
end
end
end
56 changes: 56 additions & 0 deletions lib/vbms/requests/update_document.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

module VBMS
module Requests
# This call operates in a two-phase approach. To update a document,
# call initializeUpdate with metadata to receive a token used in the second call, updateDocument
class UpdateDocument < BaseRequest
def initialize(upload_token:, filepath:)
super()
@upload_token = upload_token
@filepath = filepath
end

def name
"updateDocument"
end

def endpoint_url(base_url)
"#{base_url}#{VBMS::ENDPOINTS[:efolder_svc_v1][:upload]}"
end

def soap_doc
# TODO: convert to using MTOM
content = Base64.encode64(File.read(@filepath))
document = VBMS::Requests.soap do |xml|
xml["upload"].updateDocument do
xml.content content
xml.updateDocumentToken @upload_token
end
end

XMLHelper.remove_namespaces(document.at_xpath("//upload:updateDocument").children)
document
end

# Double encryption must not be used on operations uploadDocument and updateDocument
def signed_elements
[]
end

# TODO: convert to using MTOM
def multipart?
false
end

def multipart_file
@filepath
end

def handle_response(doc)
el = doc.xpath("//upload:updateDocumentResponse", VBMS::XML_NAMESPACES).to_xml
OpenStruct.new(XMLHelper.convert_to_hash(el))
end
end
end
end
2 changes: 1 addition & 1 deletion lib/vbms/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module VBMS

# Current minor release.
# @return [Integer]
MINOR = 2
MINOR = 3

# Current patch level.
# @return [Integer]
Expand Down
8 changes: 8 additions & 0 deletions spec/fixtures/requests/initialize_update.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
</env:Header>
<env:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-208">
<initializeUpdateResponse xmlns="http://service.efolder.vbms.vba.va.gov/eFolderUploadService" xmlns:com="http://vbms.vba.va.gov/cdm/common/v4" xmlns:doc="http://vbms.vba.va.gov/cdm/document/v5" xmlns:efc="http://service.efolder.vbms.vba.va.gov/common" xmlns:efu="http://service.efolder.vbms.vba.va.gov/eFolderUploadService" xmlns:part="http://vbms.vba.va.gov/cdm/participant/v4"><uploadToken xmlns="">{1587FC2D-63FA-40EA-8E59-D99FF790395B}</uploadToken></initializeUpdateResponse>
</env:Body>
</env:Envelope>
14 changes: 14 additions & 0 deletions spec/fixtures/requests/update_document.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
</env:Header>
<env:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-91">
<updateDocumentResponse xmlns="http://service.efolder.vbms.vba.va.gov/eFolderUploadService" xmlns:com="http://vbms.vba.va.gov/cdm/common/v4" xmlns:efc="http://service.efolder.vbms.vba.va.gov/common" xmlns:efu="http://service.efolder.vbms.vba.va.gov/eFolderUploadService" xmlns:part="http://vbms.vba.va.gov/cdm/participant/v4" xmlns:doc="http://vbms.vba.va.gov/cdm/document/v5" newDocumentVersionRefId="{2F1A4BCB-F80F-45BF-82A6-CC9E5DAF3B81}" documentSeriesRefId="{60494099-3440-4624-9BAC-E791589914A0}" mimeType="application/pdf">
<veteranReference xmlns="">
<doc:id fileNumber="784449089"/>
</veteranReference>
<vaReceiveDate xmlns="">2017-03-10-05:00</vaReceiveDate>
<vbmsUploadDate xmlns="">2017-03-10-05:00</vbmsUploadDate>
</updateDocumentResponse>
</env:Body>
</env:Envelope>
74 changes: 74 additions & 0 deletions spec/fixtures/responses/initialize_update.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="EK-A0B3C6A634B2F446FA1489068059885210">
<xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<wsse:SecurityTokenReference>
<ds:X509Data>
<ds:X509IssuerSerial>
<ds:X509IssuerName>CN=Scanning CA,OU=Scanning CA,O=Scanning CA,L=Culpeper,ST=Virginia,C=US</ds:X509IssuerName>
<ds:X509SerialNumber>49</ds:X509SerialNumber>
</ds:X509IssuerSerial>
</ds:X509Data>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
<xenc:CipherData>
<xenc:CipherValue>ETIHUsPt7nIh+1/95yob/Ow4rvmP3ViB4BfxjGAQw+UqIH78KRJV0MIBD9q6OgQzAIbvpzIHyS96FttyG1TTv6oWzSLFupVfjJ8XIH6VsAd5FEBQE2MHc9Ao3MVnD5ASvdNCsRM3+VeJbYjxkmdjJybee1ERZCuvnnj6aoZUzgAiyouNMelCCvooCTmC8GPARUbiRz9zYikrM3XdP+WS8fLe8GVwS0MmjJp2gBL1ecPazfcesiB0c6QBEfNVvx9hj2NBYawYzz2uwEVSTzSqr3HV+i20xKDHJtipru6A0UZ4kkpIUYpUjs+sJnjzi/W5MJ8ET8RHjeYQOYpgPNpW5w==</xenc:CipherValue>
</xenc:CipherData>
<xenc:ReferenceList>
<xenc:DataReference URI="#ED-210"/>
</xenc:ReferenceList>
</xenc:EncryptedKey>
<wsu:Timestamp wsu:Id="TS-207">
<wsu:Created>2017-03-09T14:00:59.877Z</wsu:Created>
<wsu:Expires>2017-03-09T14:05:59.877Z</wsu:Expires>
</wsu:Timestamp>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-209">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="env"/>
</ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<ds:Reference URI="#TS-207">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="wsse env"/>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>mKeauAQiSBL7wEf0521ubjBMfYU=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#id-208">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>D+qMC105Lr3IC9Ll7gjugFKfcxk=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>OMg8PBo/8ykE5txMPV9shkHDvc4IvPTySeEeTemgMgPuOPKw1Wxx7gOx7CGD22bbYNpcnaozEbkW
Hnv9cSNTQhEtRQUYUAb5eby1Ls5gUova9xHGnM4FG+cnZ5ZIwQRyvCFaXJPZFiGs3HXJ6HI/VjyK
5ZZTw0yzrCztkRRsGv3zSHElaiz8fWI98AUdNEO4novgcypeBk8XvoubjvRlaTp8/pfn4nW3KK/o
6W3tgzOOide5eefq5SlzXzGQbKDzXDF9SNJjgBattcVR7hvsRtsUobnq+ZhPexVIJodxEbYK4s0U
qJvKpRLr4RuT5zW0jqCgO+dWwvpzfqZBvfTx4A==</ds:SignatureValue>
<ds:KeyInfo Id="KI-A0B3C6A634B2F446FA1489068059877208">
<wsse:SecurityTokenReference wsu:Id="STR-A0B3C6A634B2F446FA1489068059877209">
<ds:X509Data>
<ds:X509IssuerSerial>
<ds:X509IssuerName>CN=AIDE CA2,OU=CA2,O=AIDE,L=Culpeper,ST=Virginia,C=US</ds:X509IssuerName>
<ds:X509SerialNumber>4</ds:X509SerialNumber>
</ds:X509IssuerSerial>
</ds:X509Data>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature>
</wsse:Security>
</env:Header>
<env:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-208">
<initializeUpdateResponse xmlns="http://service.efolder.vbms.vba.va.gov/eFolderUploadService" xmlns:com="http://vbms.vba.va.gov/cdm/common/v4" xmlns:doc="http://vbms.vba.va.gov/cdm/document/v5" xmlns:efc="http://service.efolder.vbms.vba.va.gov/common" xmlns:efu="http://service.efolder.vbms.vba.va.gov/eFolderUploadService" xmlns:part="http://vbms.vba.va.gov/cdm/participant/v4"><uploadToken xmlns="">{1587FC2D-63FA-40EA-8E59-D99FF790395B}</uploadToken></initializeUpdateResponse>
</env:Body>
</env:Envelope>
59 changes: 59 additions & 0 deletions spec/fixtures/responses/update_document.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Timestamp wsu:Id="TS-90">
<wsu:Created>2017-03-10T16:36:40.053Z</wsu:Created>
<wsu:Expires>2017-03-10T16:41:40.053Z</wsu:Expires>
</wsu:Timestamp>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-92">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="env"/>
</ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<ds:Reference URI="#TS-90">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="wsse env"/>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>IFu9SoNbhXai/K4XyPMdtwVz3wk=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#id-91">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>XSJ5sbAPDq5bJtKC829hzS2cVzA=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>uMAiCizESYU18PArGpYeovweNhXiMNjOAzn2YK4HSroMD4mwBjJI5EgoGoRBblzT8TJoxdFgPmq0
fTaJnVP/9Vx2MUV+7rOB957I6atSbAVOyDNYuFoAUDh1A7Yd08zrSZp9y7UIehwkv0kvQCA+Dinm
YXcuZBdEogOES7G7dB+reu6YDWFOjup6iQoZPNC4hO28dXI4IyIBAp6HzGK+Zhvrl1c5fwlnIhTV
AL6ot1ldk2UDeEwEI0Zi+PoCJVH5gNMSE6TjrD96/JAMmQVInXkuczJdcj04H6ISfDWHES9B/h5K
LFm9eUMFNIPZc3OXTnt+j+eFKcOv8ragsD+aKw==</ds:SignatureValue>
<ds:KeyInfo Id="KI-A21247356141E189CF148916380005491">
<wsse:SecurityTokenReference wsu:Id="STR-A21247356141E189CF148916380005492">
<ds:X509Data>
<ds:X509IssuerSerial>
<ds:X509IssuerName>CN=AIDE CA2,OU=CA2,O=AIDE,L=Culpeper,ST=Virginia,C=US</ds:X509IssuerName>
<ds:X509SerialNumber>4</ds:X509SerialNumber>
</ds:X509IssuerSerial>
</ds:X509Data>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature>
</wsse:Security>
</env:Header>
<env:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-91">
<updateDocumentResponse xmlns="http://service.efolder.vbms.vba.va.gov/eFolderUploadService" xmlns:com="http://vbms.vba.va.gov/cdm/common/v4" xmlns:efc="http://service.efolder.vbms.vba.va.gov/common" xmlns:efu="http://service.efolder.vbms.vba.va.gov/eFolderUploadService" xmlns:part="http://vbms.vba.va.gov/cdm/participant/v4" xmlns:doc="http://vbms.vba.va.gov/cdm/document/v5" newDocumentVersionRefId="{2F1A4BCB-F80F-45BF-82A6-CC9E5DAF3B81}" documentSeriesRefId="{60494099-3440-4624-9BAC-E791589914A0}" mimeType="application/pdf">
<typeCategory xmlns="" categoryId="44" categoryDescriptionText="Medical Records" typeId="356" typeDescriptionText="C&amp;P Exam" typeLabelText="L214"/>
<vaReceiveDate xmlns="">2017-03-10-05:00</vaReceiveDate>
<vbmsUploadDate xmlns="">2017-03-10-05:00</vbmsUploadDate>
</updateDocumentResponse>
</env:Body>
</env:Envelope>
38 changes: 38 additions & 0 deletions spec/requests/initialize_update_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

describe VBMS::Requests::InitializeUpdate do
describe "soap_doc" do
subject do
VBMS::Requests::InitializeUpdate.new(content_hash: "1a1389d7934dc6444ce6471beb9fcf16ff57221f",
document_version_reference_id: "86cf9cc9-1791-48b0-9955-8dc806816a0f",
va_receive_date: Time.now,
subject: "head")
end

it "generates valid SOAP" do
xml = subject.soap_doc.to_xml
xsd = Nokogiri::XML::Schema(fixture("soap.xsd"))
expect(xsd.errors).to eq []
errors = xsd.validate(parse_strict(xml))
expect(errors).to eq []
end
end

describe "parsing the XML" do
before(:all) do
request = VBMS::Requests::InitializeUpdate.new(content_hash: "1a1389d7934dc6444ce6471beb9fcf16ff57221f",
document_version_reference_id: "86cf9cc9-1791-48b0-9955-8dc806816a0f",
va_receive_date: Time.now,
subject: "head")
xml = fixture("responses/initialize_update.xml")
doc = parse_strict(xml)
@response = request.handle_response(doc)
end

subject { @response }

it "returns upload token" do
expect(subject[:updated_document_token]).to eq "{1587FC2D-63FA-40EA-8E59-D99FF790395B}"
end
end
end
44 changes: 44 additions & 0 deletions spec/requests/update_document_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

describe VBMS::Requests::UpdateDocument do
before(:all) do
@file = Tempfile.new("foo")
@file.write("hello world")
end

describe "soap_doc" do
subject do
VBMS::Requests::UpdateDocument.new(upload_token: "{1587FC2D-63FA-40EA-8E59-D99FF790395B}",
filepath: @file.path)
end

it "generates valid SOAP" do
xml = subject.soap_doc.to_xml
xsd = Nokogiri::XML::Schema(fixture("soap.xsd"))
expect(xsd.errors).to eq []
errors = xsd.validate(parse_strict(xml))
expect(errors).to eq []
end
end

describe "parsing the XML" do
before(:all) do
request = VBMS::Requests::UpdateDocument.new(upload_token: "{1587FC2D-63FA-40EA-8E59-D99FF790395B}",
filepath: @file.path)
xml = fixture("responses/update_document.xml")
doc = parse_strict(xml)
@response = request.handle_response(doc)
end

subject { @response }

it "returns upload token" do
expect(subject[:update_document_response][:@new_document_version_ref_id]).to eq "{2F1A4BCB-F80F-45BF-82A6-CC9E5DAF3B81}"
end
end

after(:all) do
@file.close
@file.unlink
end
end

0 comments on commit 98b1f9f

Please sign in to comment.