feat(router): add ping route for health probes

This commit is contained in:
Trong Huu Nguyen
2023-03-01 09:26:58 +01:00
parent 27bc5aee60
commit a375ac774d
3 changed files with 16 additions and 0 deletions

View File

@@ -419,6 +419,17 @@ func TestSession_WithRefresh(t *testing.T) {
assert.Equal(t, int64(-1), data.Session.TimeoutInSeconds)
}
func TestPing(t *testing.T) {
cfg := mock.Config()
idp := mock.NewIdentityProvider(cfg)
defer idp.Close()
rpClient := idp.RelyingPartyClient()
resp := get(t, rpClient, idp.RelyingPartyServer.URL+"/oauth2/ping")
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, "pong", resp.Body)
}
func localLogin(t *testing.T, rpClient *http.Client, idp *mock.IdentityProvider) response {
// First, run /oauth2/login to set cookies
loginURL, err := url.Parse(idp.RelyingPartyServer.URL + "/oauth2/login")

View File

@@ -8,5 +8,6 @@ const (
LogoutCallback = "/logout/callback"
LogoutFrontChannel = "/logout/frontchannel"
LogoutLocal = "/logout/local"
Ping = "/ping"
Session = "/session"
)

View File

@@ -68,6 +68,10 @@ func New(src Source, cfg *config.Config) chi.Router {
r.Get(paths.LogoutCallback, src.LogoutCallback)
r.Get(paths.LogoutFrontChannel, src.LogoutFrontChannel)
r.Get(paths.LogoutLocal, src.LogoutLocal)
r.Get(paths.Ping, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("pong"))
})
r.Route(paths.Session, func(r chi.Router) {
if cfg.SSO.Enabled && cfg.SSO.Mode == config.SSOModeServer {