Refactor e2e tests to use testify y httpexpect
This commit is contained in:
parent
046e2d959d
commit
f9624cbe46
80 changed files with 2280 additions and 2631 deletions
|
|
@ -21,11 +21,11 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"os/exec"
|
||||
"time"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/parnurzeal/gorequest"
|
||||
"github.com/onsi/ginkgo"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
|
@ -36,14 +36,11 @@ import (
|
|||
var _ = framework.DescribeAnnotation("auth-*", func() {
|
||||
f := framework.NewDefaultFramework("auth")
|
||||
|
||||
BeforeEach(func() {
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeployment()
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
})
|
||||
|
||||
It("should return status code 200 when no authentication is configured", func() {
|
||||
ginkgo.It("should return status code 200 when no authentication is configured", func() {
|
||||
host := "auth"
|
||||
|
||||
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil)
|
||||
|
|
@ -51,21 +48,18 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return Expect(server).Should(ContainSubstring("server_name auth"))
|
||||
return strings.Contains(server, "server_name auth")
|
||||
})
|
||||
|
||||
resp, body, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", host).
|
||||
End()
|
||||
|
||||
Expect(errs).Should(BeEmpty())
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
|
||||
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=%v", host)))
|
||||
f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", host).
|
||||
Expect().
|
||||
Status(http.StatusOK).
|
||||
Body().Contains(fmt.Sprintf("host=%v", host))
|
||||
})
|
||||
|
||||
It("should return status code 503 when authentication is configured with an invalid secret", func() {
|
||||
ginkgo.It("should return status code 503 when authentication is configured with an invalid secret", func() {
|
||||
host := "auth"
|
||||
annotations := map[string]string{
|
||||
"nginx.ingress.kubernetes.io/auth-type": "basic",
|
||||
|
|
@ -78,21 +72,18 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return Expect(server).Should(ContainSubstring("server_name auth"))
|
||||
return strings.Contains(server, "server_name auth")
|
||||
})
|
||||
|
||||
resp, body, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", host).
|
||||
End()
|
||||
|
||||
Expect(errs).Should(BeEmpty())
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusServiceUnavailable))
|
||||
Expect(body).Should(ContainSubstring("503 Service Temporarily Unavailable"))
|
||||
f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", host).
|
||||
Expect().
|
||||
Status(http.StatusServiceUnavailable).
|
||||
Body().Contains("503 Service Temporarily Unavailable")
|
||||
})
|
||||
|
||||
It("should return status code 401 when authentication is configured but Authorization header is not configured", func() {
|
||||
ginkgo.It("should return status code 401 when authentication is configured but Authorization header is not configured", func() {
|
||||
host := "auth"
|
||||
|
||||
s := f.EnsureSecret(buildSecret("foo", "bar", "test", f.Namespace))
|
||||
|
|
@ -108,21 +99,18 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return Expect(server).Should(ContainSubstring("server_name auth"))
|
||||
return strings.Contains(server, "server_name auth")
|
||||
})
|
||||
|
||||
resp, body, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", host).
|
||||
End()
|
||||
|
||||
Expect(errs).Should(BeEmpty())
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusUnauthorized))
|
||||
Expect(body).Should(ContainSubstring("401 Authorization Required"))
|
||||
f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", host).
|
||||
Expect().
|
||||
Status(http.StatusUnauthorized).
|
||||
Body().Contains("401 Authorization Required")
|
||||
})
|
||||
|
||||
It("should return status code 401 when authentication is configured and Authorization header is sent with invalid credentials", func() {
|
||||
ginkgo.It("should return status code 401 when authentication is configured and Authorization header is sent with invalid credentials", func() {
|
||||
host := "auth"
|
||||
|
||||
s := f.EnsureSecret(buildSecret("foo", "bar", "test", f.Namespace))
|
||||
|
|
@ -138,22 +126,19 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return Expect(server).Should(ContainSubstring("server_name auth"))
|
||||
return strings.Contains(server, "server_name auth")
|
||||
})
|
||||
|
||||
resp, body, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", host).
|
||||
SetBasicAuth("user", "pass").
|
||||
End()
|
||||
|
||||
Expect(errs).Should(BeEmpty())
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusUnauthorized))
|
||||
Expect(body).Should(ContainSubstring("401 Authorization Required"))
|
||||
f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", host).
|
||||
WithBasicAuth("user", "pass").
|
||||
Expect().
|
||||
Status(http.StatusUnauthorized).
|
||||
Body().Contains("401 Authorization Required")
|
||||
})
|
||||
|
||||
It("should return status code 200 when authentication is configured and Authorization header is sent", func() {
|
||||
ginkgo.It("should return status code 200 when authentication is configured and Authorization header is sent", func() {
|
||||
host := "auth"
|
||||
|
||||
s := f.EnsureSecret(buildSecret("foo", "bar", "test", f.Namespace))
|
||||
|
|
@ -169,21 +154,18 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return Expect(server).Should(ContainSubstring("server_name auth"))
|
||||
return strings.Contains(server, "server_name auth")
|
||||
})
|
||||
|
||||
resp, _, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", host).
|
||||
SetBasicAuth("foo", "bar").
|
||||
End()
|
||||
|
||||
Expect(errs).Should(BeEmpty())
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
|
||||
f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", host).
|
||||
WithBasicAuth("foo", "bar").
|
||||
Expect().
|
||||
Status(http.StatusOK)
|
||||
})
|
||||
|
||||
It("should return status code 200 when authentication is configured with a map and Authorization header is sent", func() {
|
||||
ginkgo.It("should return status code 200 when authentication is configured with a map and Authorization header is sent", func() {
|
||||
host := "auth"
|
||||
|
||||
s := f.EnsureSecret(buildMapSecret("foo", "bar", "test", f.Namespace))
|
||||
|
|
@ -200,21 +182,18 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return Expect(server).Should(ContainSubstring("server_name auth"))
|
||||
return strings.Contains(server, "server_name auth")
|
||||
})
|
||||
|
||||
resp, _, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", host).
|
||||
SetBasicAuth("foo", "bar").
|
||||
End()
|
||||
|
||||
Expect(errs).Should(BeEmpty())
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
|
||||
f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", host).
|
||||
WithBasicAuth("foo", "bar").
|
||||
Expect().
|
||||
Status(http.StatusOK)
|
||||
})
|
||||
|
||||
It("should return status code 401 when authentication is configured with invalid content and Authorization header is sent", func() {
|
||||
ginkgo.It("should return status code 401 when authentication is configured with invalid content and Authorization header is sent", func() {
|
||||
host := "auth"
|
||||
|
||||
s := f.EnsureSecret(
|
||||
|
|
@ -242,21 +221,18 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return Expect(server).Should(ContainSubstring("server_name auth"))
|
||||
return strings.Contains(server, "server_name auth")
|
||||
})
|
||||
|
||||
resp, _, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", host).
|
||||
SetBasicAuth("foo", "bar").
|
||||
End()
|
||||
|
||||
Expect(errs).Should(BeEmpty())
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusUnauthorized))
|
||||
f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", host).
|
||||
WithBasicAuth("foo", "bar").
|
||||
Expect().
|
||||
Status(http.StatusUnauthorized)
|
||||
})
|
||||
|
||||
It(`should set snippet "proxy_set_header My-Custom-Header 42;" when external auth is configured`, func() {
|
||||
ginkgo.It(`should set snippet "proxy_set_header My-Custom-Header 42;" when external auth is configured`, func() {
|
||||
host := "auth"
|
||||
|
||||
annotations := map[string]string{
|
||||
|
|
@ -270,11 +246,11 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return Expect(server).Should(ContainSubstring(`proxy_set_header My-Custom-Header 42;`))
|
||||
return strings.Contains(server, `proxy_set_header My-Custom-Header 42;`)
|
||||
})
|
||||
})
|
||||
|
||||
It(`should not set snippet "proxy_set_header My-Custom-Header 42;" when external auth is not configured`, func() {
|
||||
ginkgo.It(`should not set snippet "proxy_set_header My-Custom-Header 42;" when external auth is not configured`, func() {
|
||||
host := "auth"
|
||||
|
||||
annotations := map[string]string{
|
||||
|
|
@ -287,11 +263,11 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return Expect(server).ShouldNot(ContainSubstring(`proxy_set_header My-Custom-Header 42;`))
|
||||
return !strings.Contains(server, `proxy_set_header My-Custom-Header 42;`)
|
||||
})
|
||||
})
|
||||
|
||||
It(`should set "proxy_set_header 'My-Custom-Header' '42';" when auth-headers are set`, func() {
|
||||
ginkgo.It(`should set "proxy_set_header 'My-Custom-Header' '42';" when auth-headers are set`, func() {
|
||||
host := "auth"
|
||||
|
||||
annotations := map[string]string{
|
||||
|
|
@ -308,11 +284,11 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return Expect(server).Should(ContainSubstring(`proxy_set_header 'My-Custom-Header' '42';`))
|
||||
return strings.Contains(server, `proxy_set_header 'My-Custom-Header' '42';`)
|
||||
})
|
||||
})
|
||||
|
||||
It(`should set cache_key when external auth cache is configured`, func() {
|
||||
ginkgo.It(`should set cache_key when external auth cache is configured`, func() {
|
||||
host := "auth"
|
||||
|
||||
annotations := map[string]string{
|
||||
|
|
@ -324,16 +300,18 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
|
||||
f.EnsureIngress(ing)
|
||||
|
||||
cacheRegex := regexp.MustCompile(`\$cache_key.*foo`)
|
||||
|
||||
f.WaitForNginxServer(host,
|
||||
func(server string) bool {
|
||||
return Expect(server).Should(MatchRegexp(`\$cache_key.*foo`)) &&
|
||||
Expect(server).Should(ContainSubstring(`proxy_cache_valid 200 202 401 30m;`))
|
||||
return cacheRegex.MatchString(server) &&
|
||||
strings.Contains(server, `proxy_cache_valid 200 202 401 30m;`)
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
It("retains cookie set by external authentication server", func() {
|
||||
Skip("Skipping test until refactoring")
|
||||
ginkgo.It("retains cookie set by external authentication server", func() {
|
||||
ginkgo.Skip("Skipping test until refactoring")
|
||||
// TODO: this test should look like https://gist.github.com/aledbf/250645d76c080677c695929273f8fd22
|
||||
|
||||
host := "auth"
|
||||
|
|
@ -343,10 +321,10 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
var httpbinIP string
|
||||
|
||||
err := framework.WaitForEndpoints(f.KubeClientSet, framework.DefaultTimeout, framework.HTTPBinService, f.Namespace, 1)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
|
||||
e, err := f.KubeClientSet.CoreV1().Endpoints(f.Namespace).Get(framework.HTTPBinService, metav1.GetOptions{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
|
||||
httpbinIP = e.Subsets[0].Addresses[0].IP
|
||||
|
||||
|
|
@ -359,38 +337,32 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
f.EnsureIngress(ing)
|
||||
|
||||
f.WaitForNginxServer(host, func(server string) bool {
|
||||
return Expect(server).Should(ContainSubstring("server_name auth"))
|
||||
return strings.Contains(server, "server_name auth")
|
||||
})
|
||||
|
||||
resp, _, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", host).
|
||||
Param("a", "b").
|
||||
Param("c", "d").
|
||||
End()
|
||||
|
||||
for _, err := range errs {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
framework.Logf("Cookie: %v", resp.Header)
|
||||
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("alma=armud"))
|
||||
f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", host).
|
||||
WithQuery("a", "b").
|
||||
WithQuery("c", "d").
|
||||
Expect().
|
||||
Status(http.StatusOK).
|
||||
Header("Set-Cookie").Contains("alma=armud")
|
||||
})
|
||||
|
||||
Context("when external authentication is configured", func() {
|
||||
ginkgo.Context("when external authentication is configured", func() {
|
||||
host := "auth"
|
||||
|
||||
BeforeEach(func() {
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewHttpbinDeployment()
|
||||
|
||||
var httpbinIP string
|
||||
|
||||
err := framework.WaitForEndpoints(f.KubeClientSet, framework.DefaultTimeout, framework.HTTPBinService, f.Namespace, 1)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
|
||||
e, err := f.KubeClientSet.CoreV1().Endpoints(f.Namespace).Get(framework.HTTPBinService, metav1.GetOptions{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
|
||||
httpbinIP = e.Subsets[0].Addresses[0].IP
|
||||
|
||||
|
|
@ -403,61 +375,48 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
f.EnsureIngress(ing)
|
||||
|
||||
f.WaitForNginxServer(host, func(server string) bool {
|
||||
return Expect(server).Should(ContainSubstring("server_name auth"))
|
||||
return strings.Contains(server, "server_name auth")
|
||||
})
|
||||
})
|
||||
|
||||
It("should return status code 200 when signed in", func() {
|
||||
resp, _, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", host).
|
||||
SetBasicAuth("user", "password").
|
||||
End()
|
||||
|
||||
for _, err := range errs {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
|
||||
ginkgo.It("should return status code 200 when signed in", func() {
|
||||
f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", host).
|
||||
WithBasicAuth("user", "password").
|
||||
Expect().
|
||||
Status(http.StatusOK)
|
||||
})
|
||||
|
||||
It("should redirect to signin url when not signed in", func() {
|
||||
resp, _, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", host).
|
||||
RedirectPolicy(func(req gorequest.Request, via []gorequest.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
}).
|
||||
Param("a", "b").
|
||||
Param("c", "d").
|
||||
End()
|
||||
|
||||
for _, err := range errs {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusFound))
|
||||
Expect(resp.Header.Get("Location")).Should(Equal(fmt.Sprintf("http://%s/auth/start?rd=http://%s%s", host, host, url.QueryEscape("/?a=b&c=d"))))
|
||||
ginkgo.It("should redirect to signin url when not signed in", func() {
|
||||
f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", host).
|
||||
WithQuery("a", "b").
|
||||
WithQuery("c", "d").
|
||||
Expect().
|
||||
Status(http.StatusFound).
|
||||
Header("Location").Equal(fmt.Sprintf("http://%s/auth/start?rd=http://%s%s", host, host, url.QueryEscape("/?a=b&c=d")))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when external authentication with caching is configured", func() {
|
||||
ginkgo.Context("when external authentication with caching is configured", func() {
|
||||
thisHost := "auth"
|
||||
thatHost := "different"
|
||||
|
||||
fooPath := "/foo"
|
||||
barPath := "/bar"
|
||||
|
||||
BeforeEach(func() {
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewHttpbinDeployment()
|
||||
|
||||
var httpbinIP string
|
||||
|
||||
err := framework.WaitForEndpoints(f.KubeClientSet, framework.DefaultTimeout, framework.HTTPBinService, f.Namespace, 1)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
|
||||
e, err := f.KubeClientSet.CoreV1().Endpoints(f.Namespace).Get(framework.HTTPBinService, metav1.GetOptions{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
|
||||
httpbinIP = e.Subsets[0].Addresses[0].IP
|
||||
|
||||
|
|
@ -469,154 +428,106 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
}
|
||||
|
||||
for _, host := range []string{thisHost, thatHost} {
|
||||
By("Adding an ingress rule for /foo")
|
||||
ginkgo.By("Adding an ingress rule for /foo")
|
||||
fooIng := framework.NewSingleIngress(fmt.Sprintf("foo-%s-ing", host), fooPath, host, f.Namespace, framework.EchoService, 80, annotations)
|
||||
f.EnsureIngress(fooIng)
|
||||
f.WaitForNginxServer(host, func(server string) bool {
|
||||
return Expect(server).Should(ContainSubstring("location /foo"))
|
||||
return strings.Contains(server, "location /foo")
|
||||
})
|
||||
|
||||
By("Adding an ingress rule for /bar")
|
||||
ginkgo.By("Adding an ingress rule for /bar")
|
||||
barIng := framework.NewSingleIngress(fmt.Sprintf("bar-%s-ing", host), barPath, host, f.Namespace, framework.EchoService, 80, annotations)
|
||||
f.EnsureIngress(barIng)
|
||||
f.WaitForNginxServer(host, func(server string) bool {
|
||||
return Expect(server).Should(ContainSubstring("location /bar"))
|
||||
return strings.Contains(server, "location /bar")
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
It("should return status code 200 when signed in after auth backend is deleted ", func() {
|
||||
resp, _, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)+fooPath).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", thisHost).
|
||||
SetBasicAuth("user", "password").
|
||||
End()
|
||||
|
||||
for _, err := range errs {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
|
||||
ginkgo.It("should return status code 200 when signed in after auth backend is deleted ", func() {
|
||||
f.HTTPTestClient().
|
||||
GET(fooPath).
|
||||
WithHeader("Host", thisHost).
|
||||
WithBasicAuth("user", "password").
|
||||
Expect().
|
||||
Status(http.StatusOK)
|
||||
|
||||
err := f.DeleteDeployment(framework.HTTPBinService)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
|
||||
resp, _, errs = gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)+fooPath).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", thisHost).
|
||||
SetBasicAuth("user", "password").
|
||||
End()
|
||||
|
||||
for _, err := range errs {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
|
||||
f.HTTPTestClient().
|
||||
GET(fooPath).
|
||||
WithHeader("Host", thisHost).
|
||||
WithBasicAuth("user", "password").
|
||||
Expect().
|
||||
Status(http.StatusOK)
|
||||
})
|
||||
|
||||
It("should deny login for different location on same server", func() {
|
||||
resp, _, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)+fooPath).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", thisHost).
|
||||
SetBasicAuth("user", "password").
|
||||
End()
|
||||
|
||||
for _, err := range errs {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
|
||||
ginkgo.It("should deny login for different location on same server", func() {
|
||||
f.HTTPTestClient().
|
||||
GET(fooPath).
|
||||
WithHeader("Host", thisHost).
|
||||
WithBasicAuth("user", "password").
|
||||
Expect().
|
||||
Status(http.StatusOK)
|
||||
|
||||
err := f.DeleteDeployment(framework.HTTPBinService)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
|
||||
_, _, errs = gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)+fooPath).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", thisHost).
|
||||
SetBasicAuth("user", "password").
|
||||
End()
|
||||
f.HTTPTestClient().
|
||||
GET(fooPath).
|
||||
WithHeader("Host", thisHost).
|
||||
WithBasicAuth("user", "password").
|
||||
Expect().
|
||||
Status(http.StatusOK)
|
||||
|
||||
for _, err := range errs {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
ginkgo.By("receiving an internal server error without cache on location /bar")
|
||||
f.HTTPTestClient().
|
||||
GET(barPath).
|
||||
WithHeader("Host", thisHost).
|
||||
WithBasicAuth("user", "password").
|
||||
Expect().
|
||||
Status(http.StatusInternalServerError)
|
||||
|
||||
resp, _, errs = gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)+barPath).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", thisHost).
|
||||
SetBasicAuth("user", "password").
|
||||
End()
|
||||
|
||||
for _, err := range errs {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
By("receiving an internal server error without cache on location /bar")
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusInternalServerError))
|
||||
})
|
||||
|
||||
It("should deny login for different servers", func() {
|
||||
By("logging into server thisHost /foo")
|
||||
resp, _, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)+fooPath).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", thisHost).
|
||||
SetBasicAuth("user", "password").
|
||||
End()
|
||||
|
||||
for _, err := range errs {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
|
||||
ginkgo.It("should deny login for different servers", func() {
|
||||
ginkgo.By("logging into server thisHost /foo")
|
||||
f.HTTPTestClient().
|
||||
GET(fooPath).
|
||||
WithHeader("Host", thisHost).
|
||||
WithBasicAuth("user", "password").
|
||||
Expect().
|
||||
Status(http.StatusOK)
|
||||
|
||||
err := f.DeleteDeployment(framework.HTTPBinService)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
|
||||
resp, _, errs = gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)+fooPath).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", thisHost).
|
||||
SetBasicAuth("user", "password").
|
||||
End()
|
||||
ginkgo.By("receiving an internal server error without cache on thisHost location /bar")
|
||||
f.HTTPTestClient().
|
||||
GET(fooPath).
|
||||
WithHeader("Host", thisHost).
|
||||
WithBasicAuth("user", "password").
|
||||
Expect().
|
||||
Status(http.StatusOK)
|
||||
|
||||
for _, err := range errs {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
|
||||
|
||||
resp, _, errs = gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)+fooPath).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", thatHost).
|
||||
SetBasicAuth("user", "password").
|
||||
End()
|
||||
|
||||
for _, err := range errs {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
By("receiving an internal server error without cache on thisHost location /bar")
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusInternalServerError))
|
||||
f.HTTPTestClient().
|
||||
GET(fooPath).
|
||||
WithHeader("Host", thatHost).
|
||||
WithBasicAuth("user", "password").
|
||||
Expect().
|
||||
Status(http.StatusInternalServerError)
|
||||
})
|
||||
|
||||
It("should redirect to signin url when not signed in", func() {
|
||||
resp, _, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)).
|
||||
Retry(10, 1*time.Second, http.StatusNotFound).
|
||||
Set("Host", thisHost).
|
||||
RedirectPolicy(func(req gorequest.Request, via []gorequest.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
}).
|
||||
Param("a", "b").
|
||||
Param("c", "d").
|
||||
End()
|
||||
|
||||
for _, err := range errs {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
Expect(resp.StatusCode).Should(Equal(http.StatusFound))
|
||||
Expect(resp.Header.Get("Location")).Should(Equal(fmt.Sprintf("http://%s/auth/start?rd=http://%s%s", thisHost, thisHost, url.QueryEscape("/?a=b&c=d"))))
|
||||
ginkgo.It("should redirect to signin url when not signed in", func() {
|
||||
f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", thisHost).
|
||||
WithQuery("a", "b").
|
||||
WithQuery("c", "d").
|
||||
Expect().
|
||||
Status(http.StatusFound).
|
||||
Header("Location").Equal(fmt.Sprintf("http://%s/auth/start?rd=http://%s%s", thisHost, thisHost, url.QueryEscape("/?a=b&c=d")))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -630,7 +541,7 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
|
|||
func buildSecret(username, password, name, namespace string) *corev1.Secret {
|
||||
out, err := exec.Command("openssl", "passwd", "-crypt", password).CombinedOutput()
|
||||
encpass := fmt.Sprintf("%v:%s\n", username, out)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
|
||||
return &corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
@ -647,7 +558,7 @@ func buildSecret(username, password, name, namespace string) *corev1.Secret {
|
|||
|
||||
func buildMapSecret(username, password, name, namespace string) *corev1.Secret {
|
||||
out, err := exec.Command("openssl", "passwd", "-crypt", password).CombinedOutput()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
|
||||
return &corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue