Skip to content

Commit

Permalink
testing http2 on tyk
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblakeley committed Jan 24, 2018
1 parent f415562 commit c6b6b9f
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
27 changes: 27 additions & 0 deletions cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,30 @@ func TestCipherSuites(t *testing.T) {
ts.Run(t, test.TestCase{Client: client, Path: "/", ErrorMatch: "tls: handshake failure"})
})
}

func TestHttp2(t *testing.T) {
//configure server so we can useSSL and utilize the logic, but skip verification in the clients
_, _, combinedPEM, _ := genServerCertificate()
serverCertID, _ := CertificateManager.Add(combinedPEM, "")
defer CertificateManager.Delete(serverCertID)

config.Global.HttpServerOptions.UseSSL = true
config.Global.HttpServerOptions.SSLCertificates = []string{serverCertID}
config.Global.HttpServerOptions.UseHttp2 = true

defer resetTestConfig()

ts := newTykTestServer()
defer ts.Close()

buildAndLoadAPI(func(spec *APISpec) {
spec.Proxy.ListenPath = "/"
})


t.Run("http2client", func(t *testing.T) {
client := getTLSClient(nil, nil)

ts.Run(t, test.TestCase{Client: client, Path: "/"})
})
}
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ type HttpServerOptionsConfig struct {
SkipURLCleaning bool `json:"skip_url_cleaning"`
SkipTargetPathEscaping bool `json:"skip_target_path_escaping"`
Ciphers []string `json:"ssl_ciphers"`
UseHttp2 bool `json:"use_http2"`
}

type AuthOverrideConf struct {
Expand Down
3 changes: 3 additions & 0 deletions lint/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ const confSchema = `{
"type": "string"
}
},
"use_http2":{
"type": "boolean"
},
"ssl_ciphers":{
"type": ["array", "null"],
"items": {
Expand Down
18 changes: 17 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"golang.org/x/net/http2"
"crypto/tls"
"fmt"
"html/template"
Expand Down Expand Up @@ -1217,7 +1218,22 @@ func generateListener(listenPort int) (net.Listener, error) {
log.WithFields(logrus.Fields{
"prefix": "main",
}).Info("--> Using SSL (https)")

if config.Global.HttpServerOptions.UseHttp2{

tlsConfig := tls.Config{
GetCertificate: dummyGetCertificate,
ServerName: config.Global.HttpServerOptions.ServerName,
MinVersion: config.Global.HttpServerOptions.MinVersion,
ClientAuth: tls.RequestClientCert,
InsecureSkipVerify: config.Global.HttpServerOptions.SSLInsecureSkipVerify,
CipherSuites: getCipherAliases([]string{"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"}),
NextProtos: []string{http2.NextProtoTLS},
}

tlsConfig.GetConfigForClient = getTLSConfigForClient(&tlsConfig, listenPort)

return tls.Listen("tcp", targetPort, &tlsConfig)
}
tlsConfig := tls.Config{
GetCertificate: dummyGetCertificate,
ServerName: config.Global.HttpServerOptions.ServerName,
Expand Down
61 changes: 61 additions & 0 deletions vendor/golang.org/x/net/internal/socket/zsys_darwin_arm64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c6b6b9f

Please sign in to comment.