]> git.openstreetmap.org Git - rails.git/blobdiff - test/lib/osm_community_index/resource_backend_test.rb
Validate URLs against supply-chain attacks
[rails.git] / test / lib / osm_community_index / resource_backend_test.rb
diff --git a/test/lib/osm_community_index/resource_backend_test.rb b/test/lib/osm_community_index/resource_backend_test.rb
new file mode 100644 (file)
index 0000000..91b0bb5
--- /dev/null
@@ -0,0 +1,15 @@
+require "test_helper"
+
+class ResourceBackendTest < ActiveSupport::TestCase
+  def test_valid_url
+    klass = OsmCommunityIndex::ResourceBackend
+
+    assert klass.valid_url?(nil)
+    assert klass.valid_url?("http://example.com")
+    assert klass.valid_url?("mailto:bob@example.com?subject=Foo%20Bar")
+    assert klass.valid_url?("xmpp:osm@jabber.example.org?join")
+
+    assert_not klass.valid_url?("javascript:doSomething()")
+    assert_not klass.valid_url?("foo:[]")
+  end
+end