/* Copyright 2014 Google Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package apiserver import ( "bytes" "compress/gzip" "fmt" "io" "io/ioutil" "net/http" "net/http/httptest" "net/url" "strings" "testing" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest" "golang.org/x/net/html" "golang.org/x/net/websocket" ) func parseURLOrDie(inURL string) *url.URL { parsed, err := url.Parse(inURL) if err != nil { panic(err) } return parsed } // fmtHTML parses and re-emits 'in', effectively canonicalizing it. func fmtHTML(in string) string { doc, err := html.Parse(strings.NewReader(in)) if err != nil { panic(err) } out := &bytes.Buffer{} if err := html.Render(out, doc); err != nil { panic(err) } return string(out.Bytes()) } func TestProxyTransport(t *testing.T) { testTransport := &proxyTransport{ proxyScheme: "http", proxyHost: "foo.com", proxyPathPrepend: "/proxy/minion/minion1:10250", } testTransport2 := &proxyTransport{ proxyScheme: "https", proxyHost: "foo.com", proxyPathPrepend: "/proxy/minion/minion1:8080", } type Item struct { input string sourceURL string transport *proxyTransport output string contentType string forwardedURI string redirect string redirectWant string } table := map[string]Item{ "normal": { input: `
kubelet.loggoogle.log
`, sourceURL: "http://myminion.com/logs/log.log", transport: testTransport, output: `
kubelet.loggoogle.log
`, contentType: "text/html", forwardedURI: "/proxy/minion/minion1:10250/logs/log.log", }, "trailing slash": { input: `
kubelet.loggoogle.log
`, sourceURL: "http://myminion.com/logs/log.log", transport: testTransport, output: `
kubelet.loggoogle.log
`, contentType: "text/html", forwardedURI: "/proxy/minion/minion1:10250/logs/log.log", }, "content-type charset": { input: `
kubelet.loggoogle.log
`, sourceURL: "http://myminion.com/logs/log.log", transport: testTransport, output: `
kubelet.loggoogle.log
`, contentType: "text/html; charset=utf-8", forwardedURI: "/proxy/minion/minion1:10250/logs/log.log", }, "content-type passthrough": { input: `
kubelet.loggoogle.log
`, sourceURL: "http://myminion.com/logs/log.log", transport: testTransport, output: `
kubelet.loggoogle.log
`, contentType: "text/plain", forwardedURI: "/proxy/minion/minion1:10250/logs/log.log", }, "subdir": { input: `kubelet.loggoogle.log`, sourceURL: "http://myminion.com/whatever/apt/somelog.log", transport: testTransport2, output: `kubelet.loggoogle.log`, contentType: "text/html", forwardedURI: "/proxy/minion/minion1:8080/whatever/apt/somelog.log", }, "image": { input: `
`, sourceURL: "http://myminion.com/", transport: testTransport, output: `
`, contentType: "text/html", forwardedURI: "/proxy/minion/minion1:10250/", }, "abs": { input: `