packages
The Louise packages, each released on its own
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#28 · main · 3 min 34 s
0Étoiles
0Forks
3Issues
| 1 | import client |
| 2 | import requests.{get, with_header} |
| 3 | import std/http |
| 4 | import std/net.{SocketAddress} |
| 5 | import std/test.{assert_equal} |
| 6 | |
| 7 | fn from :: host: String port: Int -> http.Request |
| 8 | { |
| 9 | http.with_peer (get "/login") SocketAddress(host, port) |
| 10 | } |
| 11 | |
| 12 | fn forwarded :: host: String port: Int for: String -> http.Request |
| 13 | { |
| 14 | with_header (from host port) "X-Forwarded-For" for |
| 15 | } |
| 16 | |
| 17 | @test |
| 18 | fn a_direct_client_is_its_peer :: |
| 19 | { |
| 20 | assert_equal |
| 21 | (client.behind [] fn { client.address (from "10.0.0.5" 4321) }) |
| 22 | "10.0.0.5" |
| 23 | } |
| 24 | |
| 25 | @test |
| 26 | fn a_forwarded_for_header_from_an_untrusted_peer_is_ignored :: |
| 27 | { |
| 28 | let spoofed = forwarded "10.0.0.5" 4321 "1.2.3.4" |
| 29 | assert_equal (client.behind [] fn { client.address spoofed }) "10.0.0.5" |
| 30 | } |
| 31 | |
| 32 | @test |
| 33 | fn behind_a_trusted_proxy_the_client_is_the_forwarded_address :: |
| 34 | { |
| 35 | let proxied = forwarded "10.0.0.1" 80 "192.168.1.20" |
| 36 | assert_equal |
| 37 | (client.behind ["10.0.0.1"] fn { client.address proxied }) |
| 38 | "192.168.1.20" |
| 39 | } |
| 40 | |
| 41 | @test |
| 42 | fn a_request_without_a_peer_has_an_unknown_client :: |
| 43 | { |
| 44 | assert_equal (client.behind [] fn { client.address (get "/login") }) "unknown" |
| 45 | } |