| 1703 | } |
| 1704 | |
| 1705 | func TestDisableInsecurePathCheck(t *testing.T) { |
| 1706 | t.Setenv("GODEBUG", "zipinsecurepath=1") |
| 1707 | var buf bytes.Buffer |
| 1708 | zw := NewWriter(&buf) |
| 1709 | const name = "/foo" |
| 1710 | _, err := zw.Create(name) |
| 1711 | if err != nil { |
| 1712 | t.Fatalf("zw.Create(%q) = %v", name, err) |
| 1713 | } |
| 1714 | zw.Close() |
| 1715 | zr, err := NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len())) |
| 1716 | if err != nil { |
| 1717 | t.Fatalf("NewReader with zipinsecurepath=1: got err %v, want nil", err) |
| 1718 | } |
| 1719 | var gotPaths []string |
| 1720 | for _, f := range zr.File { |
| 1721 | gotPaths = append(gotPaths, f.Name) |
| 1722 | } |
| 1723 | if want := []string{name}; !reflect.DeepEqual(gotPaths, want) { |
| 1724 | t.Errorf("NewReader with zipinsecurepath=1: got files %q, want %q", gotPaths, want) |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | func TestCompressedDirectory(t *testing.T) { |
| 1729 | // Empty Java JAR, with a compressed directory with uncompressed size 0 |