Skip to content

Commit 6ccc894

Browse files
authored
tests: improve test coverage for controllers (#946)
1 parent 53af1b9 commit 6ccc894

7 files changed

Lines changed: 751 additions & 33 deletions

File tree

internal/controller/oidc_controller_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,26 @@ func TestOIDCController(t *testing.T) {
209209
},
210210

211211
// --- authorize-complete ---
212+
{
213+
description: "Should fail if oidc is disabled",
214+
oidcDisabled: true,
215+
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {
216+
body, err := json.Marshal(AuthorizeCompleteRequest{Ticket: "some-ticket"})
217+
require.NoError(t, err)
218+
219+
req := httptest.NewRequest("POST", "/api/oidc/authorize-complete", strings.NewReader(string(body)))
220+
req.Header.Set("Content-Type", "application/json")
221+
router.ServeHTTP(recorder, req)
222+
223+
assert.Equal(t, http.StatusOK, recorder.Code)
224+
225+
var res map[string]any
226+
require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &res))
227+
redirectURI, ok := res["redirect_uri"].(string)
228+
require.True(t, ok)
229+
assert.Contains(t, redirectURI, oidcService.GetIssuer()+"/error")
230+
},
231+
},
212232
{
213233
description: "Authorize complete returns a JSON error when the user context is missing",
214234
run: func(t *testing.T, router *gin.Engine, recorder *httptest.ResponseRecorder) {

internal/controller/proxy_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (controller *ProxyController) proxyHandler(c *gin.Context) {
158158
return
159159
}
160160

161-
c.Redirect(http.StatusTemporaryRedirect, redirectURL)
161+
c.Redirect(http.StatusFound, redirectURL)
162162
return
163163
}
164164

@@ -207,7 +207,7 @@ func (controller *ProxyController) proxyHandler(c *gin.Context) {
207207
return
208208
}
209209

210-
c.Redirect(http.StatusTemporaryRedirect, redirectURL)
210+
c.Redirect(http.StatusFound, redirectURL)
211211
return
212212
}
213213

@@ -251,7 +251,7 @@ func (controller *ProxyController) proxyHandler(c *gin.Context) {
251251
return
252252
}
253253

254-
c.Redirect(http.StatusTemporaryRedirect, redirectURL)
254+
c.Redirect(http.StatusFound, redirectURL)
255255
return
256256
}
257257
}
@@ -300,7 +300,7 @@ func (controller *ProxyController) proxyHandler(c *gin.Context) {
300300
return
301301
}
302302

303-
c.Redirect(http.StatusTemporaryRedirect, redirectURL)
303+
c.Redirect(http.StatusFound, redirectURL)
304304
}
305305

306306
func (controller *ProxyController) setHeaders(c *gin.Context, acls *model.App) {
@@ -336,7 +336,7 @@ func (controller *ProxyController) handleError(c *gin.Context, proxyCtx ProxyCon
336336
return
337337
}
338338

339-
c.Redirect(http.StatusTemporaryRedirect, redirectURL)
339+
c.Redirect(http.StatusFound, redirectURL)
340340
}
341341

342342
func (controller *ProxyController) getHeader(c *gin.Context, header string) (string, bool) {

0 commit comments

Comments
 (0)