From 4105c4dd25b32bee25ee229a33ffdacdf41e1a9d Mon Sep 17 00:00:00 2001 From: Stephan Renatus Date: Wed, 7 Sep 2022 09:25:50 +0200 Subject: [PATCH] rego/rego_test: test with test server, not httpbin.org Signed-off-by: Stephan Renatus --- rego/rego_test.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/rego/rego_test.go b/rego/rego_test.go index 3688b8cdce..6f20c05027 100644 --- a/rego/rego_test.go +++ b/rego/rego_test.go @@ -2090,15 +2090,18 @@ func TestEvalWithPrebuiltNDCache(t *testing.T) { func TestNDBCacheWithRuleBody(t *testing.T) { ctx := context.Background() + ts := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})) + defer ts.Close() + ndBC := builtins.NDBCache{} query := "data.foo.p = x" _, err := New( Query(query), NDBuiltinCache(ndBC), - Module("test.rego", `package foo + Module("test.rego", fmt.Sprintf(`package foo p { - http.send({"url": "http://httpbin.org", "method":"get"}) -}`), + http.send({"url": "%s", "method":"get"}) +}`, ts.URL)), ).Eval(ctx) if err != nil { t.Fatal(err) @@ -2112,19 +2115,23 @@ p { // Catches issues around iteration with ND builtins. func TestNDBCacheWithRuleBodyAndIteration(t *testing.T) { ctx := context.Background() + ts := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { + })) + defer ts.Close() + ndBC := builtins.NDBCache{} query := "data.foo.results = x" _, err := New( Query(query), NDBuiltinCache(ndBC), - Module("test.rego", `package foo + Module("test.rego", fmt.Sprintf(`package foo import future.keywords urls := [ - "https://httpbin.org/headers", - "https://httpbin.org/ip", - "https://httpbin.org/user-agent" + "%[1]s/headers", + "%[1]s/ip", + "%[1]s/user-agent" ] results[response] { @@ -2133,7 +2140,7 @@ results[response] { "method": "GET", "url": url }) -}`), +}`, ts.URL)), ).Eval(ctx) if err != nil { t.Fatal(err)