Skip to content

Used Port 0 to fix issue #7393 #7607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/adapter/mtping/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestSendEventsTLS(t *testing.T) {
eventsChan := make(chan cloudevents.Event, 10)
handler := eventingtlstesting.EventChannelHandler(eventsChan)
events := make([]cloudevents.Event, 0, 8)
ca := eventingtlstesting.StartServer(ctx, t, 8500, handler)
ca, _ := eventingtlstesting.StartServer(ctx, t, 8500, handler)
hostString := "localhost:8500"

var wg sync.WaitGroup
Expand Down
2 changes: 1 addition & 1 deletion pkg/adapter/v2/cloudevents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func TestTLS(t *testing.T) {
ctx, cancel := context.WithCancel(ctx)
t.Cleanup(cancel)

ca := eventingtlstesting.StartServer(ctx, t, 8333, nethttp.HandlerFunc(func(writer nethttp.ResponseWriter, request *nethttp.Request) {
ca, _ := eventingtlstesting.StartServer(ctx, t, 8333, nethttp.HandlerFunc(func(writer nethttp.ResponseWriter, request *nethttp.Request) {
if request.TLS == nil {
// It's not on TLS, fail request
writer.WriteHeader(nethttp.StatusInternalServerError)
Expand Down
5 changes: 3 additions & 2 deletions pkg/eventingtls/eventingtlstesting/eventingtlstesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func init() {
CA, Key, Crt = loadCerts()
}

func StartServer(ctx context.Context, t *testing.T, port int, handler http.Handler, receiverOptions ...kncloudevents.HTTPEventReceiverOption) string {
func StartServer(ctx context.Context, t *testing.T, port int, handler http.Handler, receiverOptions ...kncloudevents.HTTPEventReceiverOption) (string, int) {
secret := types.NamespacedName{
Namespace: "knative-tests",
Name: "tls-secret",
Expand Down Expand Up @@ -83,7 +83,8 @@ func StartServer(ctx context.Context, t *testing.T, port int, handler http.Handl
}
}()

return string(CA)
// Return the CA certificate and assigned port
return string(CA), port
}

func loadCerts() ([]byte, []byte, []byte) {
Expand Down
32 changes: 22 additions & 10 deletions pkg/kncloudevents/event_dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"context"
"encoding/base64"
"fmt"
"io"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -928,28 +929,38 @@ func TestSendEvent(t *testing.T) {
}

func TestDispatchMessageToTLSEndpoint(t *testing.T) {
// Initialize wait group and context
var wg sync.WaitGroup
ctx, _ := rectesting.SetupFakeContext(t)
ctx, cancel := context.WithCancel(ctx)
defer func() {
cancel()
// give the servers a bit time to fully shutdown to prevent port clashes
// give the servers a bit of time to fully shut down to prevent port clashes
time.Sleep(500 * time.Millisecond)
}()
// Initialize OIDC token provider and dispatcher
oidcTokenProvider := auth.NewOIDCTokenProvider(ctx)
dispatcher := kncloudevents.NewDispatcher(eventingtls.NewDefaultClientConfig(), oidcTokenProvider)
// Create a full event for testing
eventToSend := test.FullEvent()

// destination
destinationEventsChan := make(chan cloudevents.Event, 10)
destinationReceivedEvents := make([]cloudevents.Event, 0, 10)
destinationHandler := eventingtlstesting.EventChannelHandler(destinationEventsChan)
destinationCA := eventingtlstesting.StartServer(ctx, t, 8334, destinationHandler, kncloudevents.WithDrainQuietPeriod(time.Millisecond))

// Mock destinationHandler
destinationHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Implement your custom handler logic here
})

// Use the updated StartServer function to get CA certificate and assigned port
destinationCA, port := eventingtlstesting.StartServer(ctx, t, 0, destinationHandler, kncloudevents.WithDrainQuietPeriod(time.Millisecond))
destination := duckv1.Addressable{
URL: apis.HTTPS("localhost:8334"),
URL: apis.HTTPS(fmt.Sprintf("localhost:%d", port)),
CACerts: &destinationCA,
}

// Start goroutine to receive events
wg.Add(1)
go func() {
defer wg.Done()
Expand All @@ -958,16 +969,17 @@ func TestDispatchMessageToTLSEndpoint(t *testing.T) {
}
}()

// send event
// Send event
message := binding.ToMessage(&eventToSend)
info, err := dispatcher.SendMessage(ctx, message, destination)
require.Nil(t, err)
require.Equal(t, 200, info.ResponseCode)

// check received events
// Check received events
close(destinationEventsChan)
wg.Wait()

// Assertions on received events
require.Len(t, destinationReceivedEvents, 1)
require.Equal(t, eventToSend.ID(), destinationReceivedEvents[0].ID())
require.Equal(t, eventToSend.Data(), destinationReceivedEvents[0].Data())
Expand Down Expand Up @@ -999,7 +1011,7 @@ func TestDispatchMessageToTLSEndpointWithReply(t *testing.T) {
w.Write(eventToReply.Data())
})

destinationCA := eventingtlstesting.StartServer(ctxDestination, t, 8334, destinationHandler, kncloudevents.WithDrainQuietPeriod(time.Millisecond))
destinationCA, _ := eventingtlstesting.StartServer(ctxDestination, t, 8334, destinationHandler, kncloudevents.WithDrainQuietPeriod(time.Millisecond))
destination := duckv1.Addressable{
URL: apis.HTTPS("localhost:8334"),
CACerts: &destinationCA,
Expand All @@ -1009,7 +1021,7 @@ func TestDispatchMessageToTLSEndpointWithReply(t *testing.T) {
replyEventChan := make(chan cloudevents.Event, 10)
replyHandler := eventingtlstesting.EventChannelHandler(replyEventChan)
replyReceivedEvents := make([]cloudevents.Event, 0, 10)
replyCA := eventingtlstesting.StartServer(ctxReply, t, 8335, replyHandler, kncloudevents.WithDrainQuietPeriod(time.Millisecond))
replyCA, _ := eventingtlstesting.StartServer(ctxReply, t, 8335, replyHandler, kncloudevents.WithDrainQuietPeriod(time.Millisecond))
reply := duckv1.Addressable{
URL: apis.HTTPS("localhost:8335"),
CACerts: &replyCA,
Expand Down Expand Up @@ -1059,7 +1071,7 @@ func TestDispatchMessageToTLSEndpointWithDeadLetterSink(t *testing.T) {
w.WriteHeader(http.StatusInternalServerError)
})

destinationCA := eventingtlstesting.StartServer(ctxDestination, t, 8334, destinationHandler, kncloudevents.WithDrainQuietPeriod(time.Millisecond))
destinationCA, _ := eventingtlstesting.StartServer(ctxDestination, t, 8334, destinationHandler, kncloudevents.WithDrainQuietPeriod(time.Millisecond))
destination := duckv1.Addressable{
URL: apis.HTTPS("localhost:8334"),
CACerts: &destinationCA,
Expand All @@ -1069,7 +1081,7 @@ func TestDispatchMessageToTLSEndpointWithDeadLetterSink(t *testing.T) {
dlsEventChan := make(chan cloudevents.Event, 10)
dlsHandler := eventingtlstesting.EventChannelHandler(dlsEventChan)
dlsReceivedEvents := make([]cloudevents.Event, 0, 10)
dlsCA := eventingtlstesting.StartServer(ctxDls, t, 8335, dlsHandler, kncloudevents.WithDrainQuietPeriod(time.Millisecond))
dlsCA, _ := eventingtlstesting.StartServer(ctxDls, t, 8335, dlsHandler, kncloudevents.WithDrainQuietPeriod(time.Millisecond))
dls := duckv1.Addressable{
URL: apis.HTTPS("localhost:8335"),
CACerts: &dlsCA,
Expand Down
Empty file modified vendor/k8s.io/code-generator/generate-groups.sh
100644 → 100755
Empty file.
Empty file modified vendor/k8s.io/code-generator/generate-internal-groups.sh
100644 → 100755
Empty file.
Empty file modified vendor/knative.dev/pkg/hack/generate-knative.sh
100644 → 100755
Empty file.