-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
server: enable H2C for HTTP listeners via CLI flag #2739
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package h2c_test | ||
|
||
import ( | ||
"crypto/tls" | ||
"flag" | ||
"net" | ||
"net/http" | ||
"os" | ||
"testing" | ||
|
||
"golang.org/x/net/http2" | ||
|
||
"github.com/open-policy-agent/opa/test/e2e" | ||
) | ||
|
||
var testRuntime *e2e.TestRuntime | ||
|
||
func TestMain(m *testing.M) { | ||
flag.Parse() | ||
testServerParams := e2e.NewAPIServerTestParams() | ||
testServerParams.Addrs = &[]string{":0"} | ||
testServerParams.DiagnosticAddrs = &[]string{":0"} | ||
testServerParams.InsecureAddr = ":0" | ||
testServerParams.H2CEnabled = true | ||
|
||
var err error | ||
testRuntime, err = e2e.NewTestRuntime(testServerParams) | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
|
||
os.Exit(testRuntime.RunTests(m)) | ||
} | ||
|
||
func TestH2CHTTPListeners(t *testing.T) { | ||
// h2c-enabled client | ||
client := http.Client{ | ||
Transport: &http2.Transport{ | ||
AllowHTTP: true, | ||
DialTLS: func(network, addr string, _ *tls.Config) (net.Conn, error) { | ||
return net.Dial(network, addr) | ||
}, | ||
}, | ||
} | ||
|
||
addrs := append(testRuntime.Runtime.Addrs(), testRuntime.Runtime.DiagnosticAddrs()...) | ||
|
||
if expected, actual := 3, len(addrs); expected != actual { | ||
t.Fatalf("expected %d addresses, found %d", expected, actual) | ||
} | ||
|
||
for _, addr := range addrs { | ||
u := "http://" + addr + "/health" | ||
|
||
resp, err := client.Get(u) | ||
if err != nil { | ||
t.Fatalf("failed to GET %s: %s", u, err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
if expected, actual := http.StatusOK, resp.StatusCode; expected != actual { | ||
t.Errorf("resp status: expected %d, got %d", expected, actual) | ||
} | ||
if expected, actual := 2, resp.ProtoMajor; expected != actual { | ||
t.Errorf("resp.ProtoMajor: expected %d, got %d", expected, actual) | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These blow the PR size out of proportion 🙄 No idea what to do about that, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dangers of adding new dependencies! 😆