From 985e9ce26cb87d8c2663b41670789cfbbd9e3603 Mon Sep 17 00:00:00 2001
From: Peter Cai <222655+pcai@users.noreply.github.com>
Date: Mon, 15 Jul 2024 18:50:33 +0000
Subject: [PATCH] mtom tests
---
spec/savon/operation_spec.rb | 72 ++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/spec/savon/operation_spec.rb b/spec/savon/operation_spec.rb
index 24ee8cbc..a465b22d 100644
--- a/spec/savon/operation_spec.rb
+++ b/spec/savon/operation_spec.rb
@@ -197,6 +197,78 @@ def new_operation(operation_name, wsdl, globals)
end
end
+ describe "attachments" do
+ context "soap_version 1" do
+ it "sends requests with content-type text/xml" do
+ globals.endpoint @server.url(:multipart)
+ operation = new_operation(:example, no_wsdl, globals)
+ req = operation.request do
+ attachments [
+ { filename: 'x1.xml', content: 'abc'},
+ { filename: 'x2.xml', content: 'cde'},
+ ]
+ end
+ expect(req.headers["Content-Type"]).to start_with "multipart/related; type=\"text/xml\"; "
+ end
+ end
+ context "soap_version 2" do
+ it "sends requests with content-type application/soap+xml" do
+ globals.endpoint @server.url(:multipart)
+ globals.soap_version 2
+ operation = new_operation(:example, no_wsdl, globals)
+ req = operation.request do
+ attachments [
+ { filename: 'x1.xml', content: 'abc'},
+ { filename: 'x2.xml', content: 'cde'},
+ ]
+ end
+ expect(req.headers["Content-Type"]).to start_with "multipart/related; type=\"application/soap+xml\"; "
+ end
+ end
+ context "MTOM" do
+ it "sends request with content-type header application/xop+xml" do
+ globals.endpoint @server.url(:multipart)
+ operation = new_operation(:example, no_wsdl, globals)
+ req = operation.request do
+ mtom true
+ attachments [
+ { filename: 'x1.xml', content: 'abc'},
+ { filename: 'x2.xml', content: 'cde'},
+ ]
+ end
+ expect(req.headers["Content-Type"]).to start_with "multipart/related; type=\"application/xop+xml\"; start-info=\"text/xml\"; start=\"\"; boundary=\"--==_mimepart_"
+ end
+
+ it "sends attachments with Content-Transfer-Encoding: binary" do
+ globals.endpoint @server.url(:multipart)
+ operation = new_operation(:example, no_wsdl, globals)
+ req = operation.request do
+ mtom true
+ attachments [
+ { filename: 'x1.xml', content: 'abc'},
+ { filename: 'x2.xml', content: 'cde'},
+ ]
+ end
+ expect(req.body.to_s).to include("filename=x1.xml\r\nContent-Transfer-Encoding: binary")
+ end
+
+ it "successfully makes request" do
+ globals.endpoint @server.url(:multipart)
+ operation = new_operation(:example, no_wsdl, globals)
+ response = operation.call do
+ mtom true
+ attachments [
+ { filename: 'x1.xml', content: 'abc'},
+ { filename: 'x2.xml', content: 'cde'},
+ ]
+ end
+
+ expect(response.multipart?).to be true
+ expect(response.attachments.first.content_id).to include('attachment1')
+ end
+ end
+ end
+
def inspect_request(response)
hash = JSON.parse(response.http.body)
OpenStruct.new(hash)