knative-extensions / backstage-plugins

Knative plugins for Backstage.
Apache License 2.0
3 stars 18 forks source link

E2E test for authentication support #71

Closed pierDipi closed 1 month ago

pierDipi commented 4 months ago

For testing authentication added in https://github.com/knative-extensions/backstage-plugins/pull/66, we would need to:

  1. setup E2E testing infrastructure and the setup itself (create cluster, deploy backend)
  2. create the e2e tests itself, here is an high level idea using https://github.com/knative-extensions/reconciler-test [1]

The first point is quite involved and it requires a few steps to setup the jobs in knative/infra

[1]


func VerifyBackstageBackendAuthentication() *feature.Feature {

    f := feature.NewFeature()

    authenticatedClientName := feature.MakeRandomK8sName("authenticated-client")
    unauthenticatedClientName := feature.MakeRandomK8sName("unauthenticated-client")
    SAName := "test-service-account"
    SANamespace := "test-service-account"

    f.Setup("request with authenticated client", func(ctx context.Context, t feature.T) {
        tr := &authenticationv1.TokenRequest{
            // TODO: fill up
        }
        tr, err := kubeclient.Get(ctx).
            CoreV1().
            ServiceAccounts(SANamespace).
            CreateToken(ctx, SAName, tr, metav1.CreateOptions{})
        if err != nil {
            t.Fatal("Failed to create token for SA", err)
        }
        eventshub.Install(authenticatedClientName,
            eventshub.StartSenderURL("TODO_backstage_backend_url"),
            eventshub.InputHeader("Authorization", "Bearer "+tr.Status.Token),
            eventshub.InputMethod("GET"),
        )(ctx, t)
    })
    f.Setup("request with unauthenticated client", eventshub.Install(
        unauthenticatedClientName,
        eventshub.StartSenderURL("TODO_backstage_backend_url"),
        eventshub.InputMethod("GET")),
    )

    f.Assert("assert response with authenticated client", assert.OnStore(authenticatedClientName).
        Match(assert.MatchKind(eventshub.EventResponse)).
        Match(assert.MatchStatusCode(202)).
        AtLeast(1))
    f.Assert("assert response with unauthenticated client", assert.OnStore(unauthenticatedClientName).
        Match(assert.MatchKind(eventshub.EventResponse)).
        Match(assert.MatchStatusCode(401)).
        AtLeast(1))

    return f
}
ahmetcihank commented 4 months ago

/assign