Skip to content

Commit 3d508cf

Browse files
committed
Adding things for OIDC test
Signed-off-by: Matthias Wessendorf <[email protected]>
1 parent 4fd274a commit 3d508cf

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

test/rekt/features/integrationsink/features.go

+73
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ limitations under the License.
1717
package integrationsink
1818

1919
import (
20+
"context"
2021
"time"
2122

23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"knative.dev/eventing/pkg/auth"
25+
"knative.dev/reconciler-test/pkg/environment"
26+
2227
cetest "github.com/cloudevents/sdk-go/v2/test"
2328
"github.com/google/uuid"
2429
"knative.dev/eventing/test/rekt/features/featureflags"
@@ -95,3 +100,71 @@ func SuccessTLS() *feature.Feature {
95100

96101
return f
97102
}
103+
104+
func OIDC() *feature.Feature {
105+
f := feature.NewFeature()
106+
107+
integrationSink := feature.MakeRandomK8sName("integrationsink")
108+
source := feature.MakeRandomK8sName("source")
109+
sourceNoAudience := feature.MakeRandomK8sName("source-no-audience")
110+
111+
//sinkURL := &apis.URL{Scheme: "http", Host: sink}
112+
113+
event := cetest.FullEvent()
114+
event.SetID(uuid.NewString())
115+
116+
eventNoAudience := cetest.FullEvent()
117+
eventNoAudience.SetID(uuid.NewString())
118+
119+
f.Prerequisite("OIDC authentication is enabled", featureflags.AuthenticationOIDCEnabled())
120+
f.Prerequisite("transport encryption is strict", featureflags.TransportEncryptionStrict())
121+
f.Prerequisite("should not run when Istio is enabled", featureflags.IstioDisabled())
122+
123+
f.Setup("install integration sink", integrationsink.Install(integrationSink))
124+
125+
f.Setup("integrationsink is addressable", integrationsink.IsAddressable(integrationSink))
126+
f.Setup("integrationsink is ready", integrationsink.IsReady(integrationSink))
127+
128+
f.Requirement("install source for ksink", eventshub.Install(source,
129+
eventshub.StartSenderToResource(integrationsink.GVR(), integrationSink),
130+
eventshub.InputEvent(event),
131+
eventshub.AddSequence,
132+
eventshub.SendMultipleEvents(2, time.Millisecond)))
133+
134+
f.Requirement("install source for ksink without audience", func(ctx context.Context, t feature.T) {
135+
addr, err := integrationsink.Address(ctx, sourceNoAudience)
136+
if err != nil {
137+
t.Error(err)
138+
return
139+
}
140+
141+
eventshub.Install(sourceNoAudience,
142+
eventshub.StartSenderURLTLS(addr.URL.String(), addr.CACerts),
143+
eventshub.InputEvent(eventNoAudience))(ctx, t)
144+
})
145+
146+
f.Assert("IntegrationSink has audience in address", func(ctx context.Context, t feature.T) {
147+
gvk := schema.GroupVersionKind{
148+
Group: integrationsink.GVR().Group,
149+
Version: integrationsink.GVR().Version,
150+
Kind: "IntegrationSink",
151+
}
152+
addressable.ValidateAddress(integrationsink.GVR(), integrationSink, addressable.AssertAddressWithAudience(
153+
auth.GetAudienceDirect(gvk, environment.FromContext(ctx).Namespace(), integrationSink)),
154+
)(ctx, t)
155+
})
156+
157+
f.Assert("Source sent the event", assert.OnStore(source).
158+
Match(assert.MatchKind(eventshub.EventResponse)).
159+
Match(assert.MatchStatusCode(204)).
160+
AtLeast(1),
161+
)
162+
163+
f.Assert("Source sent the event", assert.OnStore(sourceNoAudience).
164+
Match(assert.MatchKind(eventshub.EventResponse)).
165+
Match(assert.MatchStatusCode(404)).
166+
AtLeast(1),
167+
)
168+
169+
return f
170+
}

test/rekt/integration_sink_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,18 @@ func TestIntegrationSinkSuccessTLS(t *testing.T) {
5858

5959
env.Test(ctx, t, integrationsink.SuccessTLS())
6060
}
61+
62+
func TestIntegrationSinkOIDC(t *testing.T) {
63+
t.Parallel()
64+
65+
ctx, env := global.Environment(
66+
knative.WithKnativeNamespace(system.Namespace()),
67+
knative.WithLoggingConfig,
68+
knative.WithTracingConfig,
69+
k8s.WithEventListener,
70+
eventshub.WithTLS(t),
71+
environment.Managed(t),
72+
)
73+
74+
env.Test(ctx, t, integrationsink.OIDC())
75+
}

test/rekt/resources/integrationsink/integrationsink.go

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"embed"
66
"time"
77

8+
"knative.dev/eventing/test/rekt/resources/addressable"
9+
duckv1 "knative.dev/pkg/apis/duck/v1"
10+
811
"k8s.io/apimachinery/pkg/runtime/schema"
912
"knative.dev/reconciler-test/pkg/environment"
1013
"knative.dev/reconciler-test/pkg/eventshub"
@@ -66,3 +69,8 @@ func IsNotReady(name string, timing ...time.Duration) feature.StepFn {
6669
func IsAddressable(name string, timings ...time.Duration) feature.StepFn {
6770
return k8s.IsAddressable(GVR(), name, timings...)
6871
}
72+
73+
// Address returns a IntegrationSink's address.
74+
func Address(ctx context.Context, name string, timings ...time.Duration) (*duckv1.Addressable, error) {
75+
return addressable.Address(ctx, GVR(), name, timings...)
76+
}

0 commit comments

Comments
 (0)