diff options
author | Carl Mastrangelo <notcarl@google.com> | 2015-10-28 11:05:49 -0700 |
---|---|---|
committer | Carl Mastrangelo <notcarl@google.com> | 2015-11-06 12:37:21 -0800 |
commit | de4491076f861f41d1d86f6611f93f14d4536cd4 (patch) | |
tree | cef74057b35f59f770568e0072a02854d4a184d9 /tools/http2_interop/http2interop_test.go | |
parent | 5cd55dd441b43e33bb3e5abeaa3dce12644e6e87 (diff) |
Add HTTP/2 Interop tests to be run
Diffstat (limited to 'tools/http2_interop/http2interop_test.go')
-rw-r--r-- | tools/http2_interop/http2interop_test.go | 95 |
1 files changed, 83 insertions, 12 deletions
diff --git a/tools/http2_interop/http2interop_test.go b/tools/http2_interop/http2interop_test.go index 3b687c035e..dc2960048f 100644 --- a/tools/http2_interop/http2interop_test.go +++ b/tools/http2_interop/http2interop_test.go @@ -2,46 +2,117 @@ package http2interop import ( "crypto/tls" + "crypto/x509" + "strings" "flag" + "fmt" "io" + "io/ioutil" "os" + "strconv" "testing" ) var ( - serverSpec = flag.String("spec", ":50051", "The server spec to test") + serverHost = flag.String("server_host", "", "The host to test") + serverPort = flag.Int("server_port", 443, "The port to test") + useTls = flag.Bool("use_tls", true, "Should TLS tests be run") + // TODO: implement + testCase = flag.String("test_case", "", "What test cases to run") + + // The rest of these are unused, but present to fulfill the client interface + serverHostOverride = flag.String("server_host_override", "", "Unused") + useTestCa = flag.Bool("use_test_ca", false, "Unused") + defaultServiceAccount = flag.String("default_service_account", "", "Unused") + oauthScope = flag.String("oauth_scope", "", "Unused") + serviceAccountKeyFile = flag.String("service_account_key_file", "", "Unused") ) +func InteropCtx(t *testing.T) *HTTP2InteropCtx { + ctx := &HTTP2InteropCtx{ + ServerHost: *serverHost, + ServerPort: *serverPort, + ServerHostnameOverride: *serverHostOverride, + UseTLS: *useTls, + UseTestCa: *useTestCa, + T: t, + } + + ctx.serverSpec = ctx.ServerHost + if ctx.ServerPort != -1 { + ctx.serverSpec += ":" + strconv.Itoa(ctx.ServerPort) + } + if ctx.ServerHostnameOverride == "" { + ctx.authority = ctx.ServerHost + } else { + ctx.authority = ctx.ServerHostnameOverride + } + + if ctx.UseTestCa { + // It would be odd if useTestCa was true, but not useTls. meh + certData, err := ioutil.ReadFile("src/core/tsi/test_creds/ca.pem") + if err != nil { + t.Fatal(err) + } + + ctx.rootCAs = x509.NewCertPool() + if !ctx.rootCAs.AppendCertsFromPEM(certData) { + t.Fatal(fmt.Errorf("Unable to parse pem data")) + } + } + + return ctx +} + +func (ctx *HTTP2InteropCtx) Close() error { + // currently a noop + return nil +} + func TestShortPreface(t *testing.T) { + ctx := InteropCtx(t) for i := 0; i < len(Preface)-1; i++ { - if err := testShortPreface(*serverSpec, Preface[:i]+"X"); err != io.EOF { + if err := testShortPreface(ctx, Preface[:i]+"X"); err != io.EOF { t.Error("Expected an EOF but was", err) } } } func TestUnknownFrameType(t *testing.T) { - if err := testUnknownFrameType(*serverSpec); err != nil { + ctx := InteropCtx(t) + if err := testUnknownFrameType(ctx); err != nil { t.Fatal(err) } } func TestTLSApplicationProtocol(t *testing.T) { - if err := testTLSApplicationProtocol(*serverSpec); err != io.EOF { - t.Fatal("Expected an EOF but was", err) - } + ctx := InteropCtx(t) + err := testTLSApplicationProtocol(ctx); + matchError(t, err, "EOF") } func TestTLSMaxVersion(t *testing.T) { - if err := testTLSMaxVersion(*serverSpec, tls.VersionTLS11); err != io.EOF { - t.Fatal("Expected an EOF but was", err) - } + ctx := InteropCtx(t) + err := testTLSMaxVersion(ctx, tls.VersionTLS11); + matchError(t, err, "EOF", "server selected unsupported protocol") } func TestClientPrefaceWithStreamId(t *testing.T) { - if err := testClientPrefaceWithStreamId(*serverSpec); err != io.EOF { - t.Fatal("Expected an EOF but was", err) - } + ctx := InteropCtx(t) + err := testClientPrefaceWithStreamId(ctx) + matchError(t, err, "EOF") +} + +func matchError(t *testing.T, err error, matches ... string) { + if err == nil { + t.Fatal("Expected an error") + } + for _, s := range matches { + if strings.Contains(err.Error(), s) { + return + } + } + t.Fatalf("Error %v not in %+v", err, matches) } func TestMain(m *testing.M) { |