| 15 | ) |
| 16 | |
| 17 | func TestUnixSocketOrigin(t *testing.T) { |
| 18 | file, err := os.CreateTemp("", "unix.sock") |
| 19 | require.NoError(t, err) |
| 20 | os.Remove(file.Name()) // remove the file since binding the socket expects to create it |
| 21 | |
| 22 | l, err := net.Listen("unix", file.Name()) |
| 23 | require.NoError(t, err) |
| 24 | defer l.Close() |
| 25 | defer os.Remove(file.Name()) |
| 26 | |
| 27 | api := &httptest.Server{ |
| 28 | Listener: l, |
| 29 | Config: &http.Server{Handler: mockAPI{}}, |
| 30 | } |
| 31 | api.Start() |
| 32 | defer api.Close() |
| 33 | |
| 34 | unvalidatedIngress := []config.UnvalidatedIngressRule{ |
| 35 | { |
| 36 | Hostname: "unix.example.com", |
| 37 | Service: "unix:" + file.Name(), |
| 38 | }, |
| 39 | { |
| 40 | Hostname: "*", |
| 41 | Service: "http_status:404", |
| 42 | }, |
| 43 | } |
| 44 | |
| 45 | tests := []MultipleIngressTest{ |
| 46 | { |
| 47 | url: "http://unix.example.com", |
| 48 | expectedStatus: http.StatusCreated, |
| 49 | expectedBody: []byte("Created"), |
| 50 | }, |
| 51 | } |
| 52 | |
| 53 | runIngressTestScenarios(t, unvalidatedIngress, tests) |
| 54 | } |