(t *testing.T, sb integration.Sandbox)
| 708 | } |
| 709 | |
| 710 | func testBuildPolicyHTTP(t *testing.T, sb integration.Sandbox) { |
| 711 | skipNoCompatBuildKit(t, sb, ">= 0.26.0-0", "policy input requires BuildKit v0.26.0+") |
| 712 | resp := &httpserver.Response{Content: []byte("policy-http")} |
| 713 | server := httpserver.NewTestServer(map[string]*httpserver.Response{ |
| 714 | "/file": resp, |
| 715 | }) |
| 716 | defer server.Close() |
| 717 | |
| 718 | parsedURL, err := url.Parse(server.URL) |
| 719 | require.NoError(t, err) |
| 720 | |
| 721 | baseURL := server.URL + "/file" |
| 722 | queryURL := baseURL + "?policy=allow&case=http" |
| 723 | checksum := digest.FromBytes(resp.Content).String() |
| 724 | testCases := []struct { |
| 725 | name string |
| 726 | policy string |
| 727 | addURL string |
| 728 | wantErrContains string |
| 729 | requiresHTTPChecksum bool |
| 730 | }{ |
| 731 | { |
| 732 | name: "http-url-allow", |
| 733 | policy: fmt.Sprintf(` |
| 734 | package docker |
| 735 | |
| 736 | default allow = false |
| 737 | |
| 738 | allow if not input.http |
| 739 | |
| 740 | allow if input.http.url == "%s" |
| 741 | |
| 742 | decision := {"allow": allow} |
| 743 | `, queryURL), |
| 744 | addURL: queryURL, |
| 745 | }, |
| 746 | { |
| 747 | name: "http-schema-allow", |
| 748 | policy: ` |
| 749 | package docker |
| 750 | |
| 751 | default allow = false |
| 752 | |
| 753 | allow if not input.http |
| 754 | |
| 755 | allow if input.http.schema == "http" |
| 756 | |
| 757 | decision := {"allow": allow} |
| 758 | `, |
| 759 | addURL: baseURL, |
| 760 | }, |
| 761 | { |
| 762 | name: "http-host-allow", |
| 763 | policy: fmt.Sprintf(` |
| 764 | package docker |
| 765 | |
| 766 | default allow = false |
| 767 |
nothing calls this directly
no test coverage detected
searching dependent graphs…