Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
diptadas committed Apr 24, 2018
1 parent 914a0b0 commit a030878
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/e2e/options.go
Expand Up @@ -40,7 +40,7 @@ var (
)

func init() {
options.OperatorOptions.HAProxyImageTag = "1.7.10-tcp-sni"
options.OperatorOptions.HAProxyImageTag = "1.8.8-tcp-sni"
options.OperatorOptions.ExporterImageTag = "tcp-sni"

options.AddGoFlags(flag.CommandLine)
Expand Down
95 changes: 95 additions & 0 deletions test/e2e/tcp-sni.go
@@ -0,0 +1,95 @@
package e2e

import (
api "github.com/appscode/voyager/apis/voyager/v1beta1"
"github.com/appscode/voyager/test/framework"
"github.com/appscode/voyager/test/test-server/client"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/util/intstr"
)

var _ = FDescribe("Ingress TCP SNI", func() {
var (
f *framework.Invocation
ing *api.Ingress
)

BeforeEach(func() {
f = root.Invoke()
ing = f.Ingress.GetSkeleton()
f.Ingress.SetSkeletonRule(ing)
})

JustBeforeEach(func() {
By("Creating ingress with name " + ing.GetName())
err := f.Ingress.Create(ing)
Expect(err).NotTo(HaveOccurred())

f.Ingress.EventuallyStarted(ing).Should(BeTrue())

By("Checking generated resource")
Expect(f.Ingress.IsExistsEventually(ing)).Should(BeTrue())
})

AfterEach(func() {
if options.Cleanup {
f.Ingress.Delete(ing)
}
})

Describe("Create", func() {
BeforeEach(func() {
ing.Spec.Rules = []api.IngressRule{
{
Host: "http.appscode.test",
IngressRuleValue: api.IngressRuleValue{
TCP: &api.TCPIngressRuleValue{
Port: intstr.FromInt(8443),
Backend: api.IngressBackend{
ServiceName: f.Ingress.TestServerHTTPSName(),
ServicePort: intstr.FromInt(443),
},
},
},
},
{
Host: "ssl.appscode.test",
IngressRuleValue: api.IngressRuleValue{
TCP: &api.TCPIngressRuleValue{
Port: intstr.FromInt(8443),
Backend: api.IngressBackend{
ServiceName: f.Ingress.TestServerHTTPSName(),
ServicePort: intstr.FromInt(3443),
},
},
},
},
}
})

It("Should response based on Host", func() {
By("Getting HTTP endpoints")
eps, err := f.Ingress.GetHTTPEndpoints(ing)
Expect(err).NotTo(HaveOccurred())
Expect(len(eps)).Should(BeNumerically(">=", 1))

svc, err := f.Ingress.GetOffShootService(ing)
Expect(err).NotTo(HaveOccurred())
Expect(len(svc.Spec.Ports)).Should(Equal(1))
Expect(svc.Spec.Ports[0].Port).To(Equal(int32(8443)))

By("Request with host: http.appscode.test")
err = f.Ingress.DoHTTPWithSNI(5, "http.appscode.test", eps, func(r *client.Response) bool {
return Expect(r.ServerPort).Should(Equal(":6443"))
})
Expect(err).NotTo(HaveOccurred())

By("Request with host: ssl.appscode.test")
err = f.Ingress.DoHTTPWithSNI(5, "ssl.appscode.test", eps, func(r *client.Response) bool {
return Expect(r.ServerPort).Should(Equal(":3443"))
})
Expect(err).NotTo(HaveOccurred())
})
})
})
28 changes: 28 additions & 0 deletions test/framework/ingress_suite.go
Expand Up @@ -6,6 +6,8 @@ import (
"strings"
"time"

"crypto/tls"

"github.com/appscode/go/crypto/rand"
"github.com/appscode/go/log"
"github.com/appscode/go/types"
Expand Down Expand Up @@ -419,6 +421,32 @@ func (i *ingressInvocation) DoHTTPStatusWithHeader(retryCount int, ing *api.Ingr
return nil
}

func (i *ingressInvocation) DoHTTPWithSNI(retryCount int, host string, eps []string, matcher func(resp *client.Response) bool) error {
for _, url := range eps {
if strings.HasPrefix(url, "http://") {
url = "https://" + url[len("http://"):]
}

tr := &http.Transport{
TLSClientConfig: &tls.Config{
ServerName: host,
InsecureSkipVerify: true,
},
}

resp, err := client.NewTestHTTPClient(url).WithHost(host).WithTransport(tr).DoWithRetry(retryCount)
if err != nil {
return err
}

log.Infoln("HTTP Response received from server", *resp)
if !matcher(resp) {
return errors.New("Failed to match")
}
}
return nil
}

func (i *ingressInvocation) DoTCP(retryCount int, ing *api.Ingress, eps []string, matcher func(resp *client.Response) bool) error {
for _, url := range eps {
resp, err := client.NewTestTCPClient(url).DoWithRetry(retryCount)
Expand Down
4 changes: 2 additions & 2 deletions test/framework/ingress_util.go
Expand Up @@ -162,9 +162,9 @@ func (i *ingressInvocation) createTestServerService() error {
Labels: map[string]string{
"app": "test-server-" + i.app,
},
Annotations: map[string]string{
/*Annotations: map[string]string{
"ingress.appscode.com/backend-tls": "ssl verify none",
},
},*/
},
Spec: core.ServiceSpec{
Ports: []core.ServicePort{
Expand Down

0 comments on commit a030878

Please sign in to comment.