ssrf_test.go raw

   1  package sales
   2  
   3  import "testing"
   4  
   5  func TestMirrorURLGuard(t *testing.T) {
   6  	bad := []string{
   7  		"http://127.0.0.1/x",
   8  		"http://localhost/x",
   9  		"http://10.0.0.5/x",
  10  		"http://192.168.1.1/x",
  11  		"http://169.254.169.254/latest/meta-data",
  12  		"http://[::1]/x",
  13  		"file:///etc/passwd",
  14  		"ftp://example.com/x",
  15  		"http:///nohost",
  16  	}
  17  	for _, u := range bad {
  18  		if err := checkMirrorURL(u, false); err == nil {
  19  			t.Fatalf("%q was accepted", u)
  20  		}
  21  	}
  22  	if err := checkMirrorURL("http://127.0.0.1/x", true); err != nil {
  23  		t.Fatalf("private target refused in lab mode: %v", err)
  24  	}
  25  	if err := checkMirrorURL("https://8.8.8.8/blob", false); err != nil {
  26  		t.Fatalf("public address refused: %v", err)
  27  	}
  28  }
  29