Skip to content

Commit

Permalink
fix: add OpenShift token check for che-dashboard
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <[email protected]>
  • Loading branch information
olexii4 committed Apr 28, 2022
1 parent 2fdc36e commit 9cd32fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/deploy/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (d *DashboardReconciler) createGatewayConfig(ctx *deploy.DeployContext) *ga
[]string{})
if util.IsOpenShift {
cfg.AddAuthHeaderRewrite(d.getComponentName(ctx))
cfg.AddOpenShiftTokenCheck(d.getComponentName(ctx))
}
return cfg
}
18 changes: 18 additions & 0 deletions pkg/deploy/dashboard/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ func TestDashboardOpenShift(t *testing.T) {
assert.True(t, util.ContainsString(ctx.CheCluster.Finalizers, ClusterPermissionsDashboardFinalizer))
}

func TestTokenValidityCheckOnOpenShift(t *testing.T) {
util.IsOpenShift = true

ctx := deploy.GetTestDeployContext(nil, []runtime.Object{})
dashboard := NewDashboardReconciler()
_, done, err := dashboard.Reconcile(ctx)
assert.True(t, done)
assert.Nil(t, err)
cfg := dashboard.createGatewayConfig(ctx)

if assert.Contains(t, cfg.HTTP.Routers, "che-dashboard") {
assert.Contains(t, cfg.HTTP.Routers["che-dashboard"].Middlewares, "che-dashboard-token-check")
}
if assert.Contains(t, cfg.HTTP.Middlewares, "che-dashboard-token-check") && assert.NotNil(t, cfg.HTTP.Middlewares["che-dashboard-token-check"].ForwardAuth) {
assert.Equal(t, "https://kubernetes.default.svc/apis/user.openshift.io/v1/users/~", cfg.HTTP.Middlewares["che-dashboard-token-check"].ForwardAuth.Address)
}
}

func TestDashboardKubernetes(t *testing.T) {
util.IsOpenShift = false

Expand Down

0 comments on commit 9cd32fc

Please sign in to comment.