mirror of
https://github.com/penpot/penpot.git
synced 2026-08-19 03:08:40 +00:00
🐛 Mock DNS resolution in SSRF tests for environments without public DNS (#11040)
The validate-url-allows-public-{https,http} tests relied on real DNS
resolution of example.com, which fails in containers without public
DNS access. Mock resolve-host to return a known public IP, consistent
with the pattern used by other tests in the same file.
AI-assisted-by: mimo-v2.5-pro
This commit is contained in:
parent
68e1db984d
commit
c688cba8d8
@ -13,11 +13,25 @@
|
|||||||
[clojure.test :as t]))
|
[clojure.test :as t]))
|
||||||
|
|
||||||
(t/deftest validate-url-allows-public-https
|
(t/deftest validate-url-allows-public-https
|
||||||
(t/is (true? (ssrf/safe-url? "https://example.com/foo")))
|
(let [original ssrf/resolve-host]
|
||||||
(t/is (true? (ssrf/safe-url? "https://example.com:8080/path?q=1"))))
|
(with-redefs [ssrf/resolve-host
|
||||||
|
(fn [hostname]
|
||||||
|
(if (= hostname "example.com")
|
||||||
|
(into-array java.net.InetAddress
|
||||||
|
[(java.net.InetAddress/getByName "93.184.216.34")])
|
||||||
|
(original hostname)))]
|
||||||
|
(t/is (true? (ssrf/safe-url? "https://example.com/foo")))
|
||||||
|
(t/is (true? (ssrf/safe-url? "https://example.com:8080/path?q=1"))))))
|
||||||
|
|
||||||
(t/deftest validate-url-allows-public-http
|
(t/deftest validate-url-allows-public-http
|
||||||
(t/is (true? (ssrf/safe-url? "http://example.com/foo"))))
|
(let [original ssrf/resolve-host]
|
||||||
|
(with-redefs [ssrf/resolve-host
|
||||||
|
(fn [hostname]
|
||||||
|
(if (= hostname "example.com")
|
||||||
|
(into-array java.net.InetAddress
|
||||||
|
[(java.net.InetAddress/getByName "93.184.216.34")])
|
||||||
|
(original hostname)))]
|
||||||
|
(t/is (true? (ssrf/safe-url? "http://example.com/foo"))))))
|
||||||
|
|
||||||
(t/deftest validate-url-blocks-disallowed-schemes
|
(t/deftest validate-url-blocks-disallowed-schemes
|
||||||
(t/is (false? (ssrf/safe-url? "file:///etc/passwd")))
|
(t/is (false? (ssrf/safe-url? "file:///etc/passwd")))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user