sgx-bwmsgsv2.rb 🔗
@@ -493,7 +493,7 @@ module SGXbwmsgsv2
)
)),
{'Content-Type' => 'application/json'},
- [201]
+ [201, 202]
).then { |response|
parsed = JSON.parse(response) rescue {}
MessageEvent::Out.new(
Phillip Davis created
sgx-bwmsgsv2.rb | 2
test/property/rantly_extensions/data_extensions.rb | 13 +++
test/property/test_to_catapult.rb | 59 ++++++++++++++++
3 files changed, 73 insertions(+), 1 deletion(-)
@@ -493,7 +493,7 @@ module SGXbwmsgsv2
)
)),
{'Content-Type' => 'application/json'},
- [201]
+ [201, 202]
).then { |response|
parsed = JSON.parse(response) rescue {}
MessageEvent::Out.new(
@@ -90,6 +90,19 @@ class Rantly
range(10000, 999999).to_s
end
+ # @return [Array<String>]
+ HTTP_ESCAPABLE = " &=?/+@#".chars.freeze
+
+ # @return [String]
+ def maybe_http_escapable_string
+ base = sized(range(3, 8)) { string(:alnum) }
+ choose(
+ base,
+ base + choose(*HTTP_ESCAPABLE) +
+ sized(range(1, 5)) { string(:alnum) }
+ )
+ end
+
# @return [String]
def media_url
user_id = sized(range(3, 10)) { string(:alnum) }
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+require "test_helper"
+require_relative "../../sgx-bwmsgsv2"
+require "rantly/minitest_extensions"
+require_relative "rantly_extensions/data_extensions"
+
+class ToCatapultPropertyTest < Minitest::Test
+ def test_accepts_201_and_202_with_escaped_tag
+ property_of {
+ dest = nanpa_phone
+ guard(dest != "+15550000000")
+
+ words = array(range(1, 4)) { sized(range(3, 8)) { string(:alnum) } }
+ guard(words.none? { |w| BADWORD_LIST.include?(w.downcase) })
+ body = words.join(" ")
+
+ stanza_id = maybe_http_escapable_string
+ resource = maybe_http_escapable_string
+ status = choose(201, 202)
+
+ [dest, body, stanza_id, resource, status]
+ }.check { |dest, body, stanza_id, resource, status|
+ reset_stanzas!
+ reset_redis!
+ WebMock.reset!
+
+ bw_request_body = nil
+ bw_req = stub_request(:post, BW_MESSAGES_URL).to_return { |request|
+ bw_request_body = JSON.parse(request.body)
+ {
+ status: status,
+ body: JSON.dump(id: "bw-msg-id", time: Time.now.iso8601)
+ }
+ }
+
+ m = Blather::Stanza::Message.new("#{dest}@component", body)
+ m.from = "test@example.com/#{resource}"
+ m.id = stanza_id
+
+ process_stanza(m)
+
+ expected_tag = WEBrick::HTTPUtils.escape(stanza_id) +
+ " " +
+ WEBrick::HTTPUtils.escape(resource)
+ assert_equal expected_tag, bw_request_body["tag"],
+ "Tag should be HTTP-escaped (status=#{status})"
+
+ assert_requested bw_req
+
+ written.each do |response|
+ stanza = Blather::XMPPNode.parse(response.to_xml)
+ refute stanza.error?,
+ "Expected success for status #{status} but got error"
+ end
+ }
+ end
+ em :test_accepts_201_and_202_with_escaped_tag
+end