test/test_web.rb in messenger-0.0.3 vs test/test_web.rb in messenger-0.1.0
- old
+ new
@@ -20,9 +20,43 @@
should "post a failed message" do
HTTParty.expects(:post).with("http://example.com", :body => '{ "key": "value" }', :headers => { "Content-Type" => "application/json" }).returns(@failure_response)
result = Web.send("http://example.com", '{ "key": "value" }', :headers => { "Content-Type" => "application/json" })
assert_equal [false, @failure_response], result
end
+
+ should "raise if trying to send to an invalid URL" do
+ assert_raises URLError do
+ Web.send("http://!", :body => "whatever")
+ end
+ end
+
+ should "obfuscate the URL" do
+ assert_equal "http://example.com", Web.obfuscate("http://example.com")
+ assert_equal "http://user:xxxx@example.com", Web.obfuscate("http://user:secure_pass@example.com")
+ assert_equal "https://user:xxxx@example.com", Web.obfuscate("https://user:secure_pass@example.com")
+ end
+
+ should "raise if trying to obfuscate an invalid URL" do
+ assert_raises URLError do
+ Web.obfuscate("http://!")
+ end
+ end
+ end
+
+ context "Web notificaiton URL validation" do
+ should "return true for good URLs" do
+ assert true, Web.valid_url?("http://example.com")
+ assert true, Web.valid_url?("https://example.com")
+ assert true, Web.valid_url?("https://user@example.com")
+ assert true, Web.valid_url?("http://user:pass@example.com")
+ assert true, Web.valid_url?("https://user:#{URI.escape('!#$%^&*¢ç⎋')}@example.com")
+ end
+
+ should "return false for bad URLs" do
+ assert_equal false, Web.valid_url?("http://!")
+ assert_equal false, Web.valid_url?("http://")
+ assert_equal false, Web.valid_url?("https://")
+ end
end
end
end