Skip to content

Commit 010f96a

Browse files
authored
Use https to verify the access when https option is enabled (#11537)
* Use https for DomainMapping when https option is enabled Current TestDomainMapping always http to verify the access. This patch changes to use https for DomainMapping when https option is enabled. * Use pkgtest.WaitForEndpointState
1 parent 1c042a1 commit 010f96a

1 file changed

Lines changed: 43 additions & 14 deletions

File tree

‎test/conformance/api/v1alpha1/domain_mapping_test.go‎

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ package v1alpha1
2020

2121
import (
2222
"context"
23-
"net/url"
2423
"testing"
2524

2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2726
"k8s.io/apimachinery/pkg/util/wait"
2827
duckv1 "knative.dev/pkg/apis/duck/v1"
2928
"knative.dev/pkg/reconciler"
29+
pkgtest "knative.dev/pkg/test"
30+
"knative.dev/pkg/test/spoof"
3031
"knative.dev/serving/pkg/apis/serving/v1alpha1"
3132
"knative.dev/serving/test"
32-
"knative.dev/serving/test/conformance/api/shared"
3333
"knative.dev/serving/test/e2e"
3434
v1test "knative.dev/serving/test/v1"
3535
)
@@ -94,20 +94,30 @@ func TestDomainMapping(t *testing.T) {
9494

9595
// Wait for DomainMapping to go Ready.
9696
waitErr := wait.PollImmediate(test.PollInterval, test.PollTimeout, func() (bool, error) {
97-
state, err := clients.ServingAlphaClient.DomainMappings.Get(context.Background(), dm.Name, metav1.GetOptions{})
97+
var err error
98+
dm, err = clients.ServingAlphaClient.DomainMappings.Get(context.Background(), dm.Name, metav1.GetOptions{})
9899
if err != nil {
99100
return true, err
100101
}
101102

102-
return state.IsReady(), nil
103+
return dm.IsReady(), nil
103104
})
104105
if waitErr != nil {
105106
t.Fatalf("The DomainMapping %s was not marked as Ready: %v", dm.Name, waitErr)
106107
}
107108

108-
// Should be able to access the test image text via the mapped domain.
109-
if err := shared.CheckDistribution(ctx, t, clients, &url.URL{Host: host, Scheme: "http"}, test.ConcurrentRequests, test.ConcurrentRequests, []string{test.PizzaPlanetText1}, resolvableCustomDomain); err != nil {
110-
t.Errorf("CheckDistribution=%v, expected no error", err)
109+
endpoint := dm.Status.URL.URL()
110+
t.Log("Probing", endpoint)
111+
if _, err := pkgtest.WaitForEndpointState(
112+
context.Background(),
113+
clients.KubeClient,
114+
t.Logf,
115+
endpoint,
116+
v1test.RetryingRouteInconsistency(spoof.MatchesAllOf(spoof.IsStatusOK, spoof.MatchesBody(test.PizzaPlanetText1))),
117+
"WaitForSuccessfulResponse",
118+
resolvableCustomDomain,
119+
test.AddRootCAtoTransport(context.Background(), t.Logf, clients, test.ServingFlags.HTTPS)); err != nil {
120+
t.Fatalf("Error probing %s: %v", endpoint, err)
111121
}
112122

113123
altClients := e2e.SetupAlternativeNamespace(t)
@@ -164,8 +174,17 @@ func TestDomainMapping(t *testing.T) {
164174
}
165175

166176
// Because the second DomainMapping collided with the first, it should not have taken effect.
167-
if err := shared.CheckDistribution(ctx, t, clients, &url.URL{Host: host, Scheme: "http"}, test.ConcurrentRequests, test.ConcurrentRequests, []string{test.PizzaPlanetText1}, resolvableCustomDomain); err != nil {
168-
t.Errorf("CheckDistribution=%v, expected no error", err)
177+
t.Log("Probing", endpoint)
178+
if _, err := pkgtest.WaitForEndpointState(
179+
context.Background(),
180+
clients.KubeClient,
181+
t.Logf,
182+
endpoint,
183+
v1test.RetryingRouteInconsistency(spoof.MatchesAllOf(spoof.IsStatusOK, spoof.MatchesBody(test.PizzaPlanetText1))),
184+
"WaitForSuccessfulResponse",
185+
resolvableCustomDomain,
186+
test.AddRootCAtoTransport(context.Background(), t.Logf, clients, test.ServingFlags.HTTPS)); err != nil {
187+
t.Fatalf("Error probing %s: %v", endpoint, err)
169188
}
170189

171190
// Delete the first DomainMapping.
@@ -175,19 +194,29 @@ func TestDomainMapping(t *testing.T) {
175194

176195
// The second DomainMapping should now be able to claim the domain.
177196
waitErr = wait.PollImmediate(test.PollInterval, test.PollTimeout, func() (bool, error) {
178-
state, err := altClients.ServingAlphaClient.DomainMappings.Get(context.Background(), altDm.Name, metav1.GetOptions{})
197+
var err error
198+
altDm, err = altClients.ServingAlphaClient.DomainMappings.Get(context.Background(), altDm.Name, metav1.GetOptions{})
179199
if err != nil {
180200
return true, err
181201
}
182202

183-
return state.IsReady(), nil
203+
return altDm.IsReady(), nil
184204
})
185205
if waitErr != nil {
186206
t.Fatalf("The second DomainMapping %s was not marked as Ready: %v", dm.Name, waitErr)
187207
}
188208

189-
// The domain name should now point to the second service.
190-
if err := shared.CheckDistribution(ctx, t, clients, &url.URL{Host: host, Scheme: "http"}, test.ConcurrentRequests, test.ConcurrentRequests, []string{test.PizzaPlanetText2}, resolvableCustomDomain); err != nil {
191-
t.Errorf("CheckDistribution=%v, expected no error", err)
209+
endpoint = altDm.Status.URL.URL()
210+
t.Log("Probing", endpoint)
211+
if _, err := pkgtest.WaitForEndpointState(
212+
context.Background(),
213+
clients.KubeClient,
214+
t.Logf,
215+
endpoint,
216+
v1test.RetryingRouteInconsistency(spoof.MatchesAllOf(spoof.IsStatusOK, spoof.MatchesBody(test.PizzaPlanetText2))),
217+
"WaitForSuccessfulResponse",
218+
resolvableCustomDomain,
219+
test.AddRootCAtoTransport(context.Background(), t.Logf, clients, test.ServingFlags.HTTPS)); err != nil {
220+
t.Fatalf("Error probing %s: %v", endpoint, err)
192221
}
193222
}

0 commit comments

Comments
 (0)