mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 13:02:33 +02:00
fix: docker test and golangci-lint
This commit is contained in:
parent
9a12dab600
commit
ef277ef57f
4 changed files with 13 additions and 13 deletions
|
@ -51,7 +51,7 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
U.HandleErr(w, r, err, http.StatusUnauthorized)
|
U.HandleErr(w, r, err, http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := setAuthenticatedCookie(w, r, creds.Username); err != nil {
|
if err := setAuthenticatedCookie(w, creds.Username); err != nil {
|
||||||
U.HandleErr(w, r, err, http.StatusInternalServerError)
|
U.HandleErr(w, r, err, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ func AuthMethodHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setAuthenticatedCookie(w http.ResponseWriter, r *http.Request, username string) error {
|
func setAuthenticatedCookie(w http.ResponseWriter, username string) error {
|
||||||
expiresAt := time.Now().Add(common.APIJWTTokenTTL)
|
expiresAt := time.Now().Add(common.APIJWTTokenTTL)
|
||||||
claim := &Claims{
|
claim := &Claims{
|
||||||
Username: username,
|
Username: username,
|
||||||
|
|
|
@ -20,7 +20,7 @@ var (
|
||||||
oidcVerifier *oidc.IDTokenVerifier
|
oidcVerifier *oidc.IDTokenVerifier
|
||||||
)
|
)
|
||||||
|
|
||||||
// InitOIDC initializes the OIDC provider
|
// InitOIDC initializes the OIDC provider.
|
||||||
func InitOIDC(issuerURL, clientID, clientSecret, redirectURL string) error {
|
func InitOIDC(issuerURL, clientID, clientSecret, redirectURL string) error {
|
||||||
if issuerURL == "" {
|
if issuerURL == "" {
|
||||||
return nil // OIDC not configured
|
return nil // OIDC not configured
|
||||||
|
@ -47,7 +47,7 @@ func InitOIDC(issuerURL, clientID, clientSecret, redirectURL string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// OIDCLoginHandler initiates the OIDC login flow
|
// OIDCLoginHandler initiates the OIDC login flow.
|
||||||
func OIDCLoginHandler(w http.ResponseWriter, r *http.Request) {
|
func OIDCLoginHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if oauthConfig == nil {
|
if oauthConfig == nil {
|
||||||
U.HandleErr(w, r, E.New("OIDC not configured"), http.StatusNotImplemented)
|
U.HandleErr(w, r, E.New("OIDC not configured"), http.StatusNotImplemented)
|
||||||
|
@ -69,7 +69,7 @@ func OIDCLoginHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
|
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OIDCCallbackHandler handles the OIDC callback
|
// OIDCCallbackHandler handles the OIDC callback.
|
||||||
func OIDCCallbackHandler(w http.ResponseWriter, r *http.Request) {
|
func OIDCCallbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if oauthConfig == nil {
|
if oauthConfig == nil {
|
||||||
U.HandleErr(w, r, E.New("OIDC not configured"), http.StatusNotImplemented)
|
U.HandleErr(w, r, E.New("OIDC not configured"), http.StatusNotImplemented)
|
||||||
|
@ -126,7 +126,7 @@ func OIDCCallbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := setAuthenticatedCookie(w, r, claims.Username); err != nil {
|
if err := setAuthenticatedCookie(w, claims.Username); err != nil {
|
||||||
U.HandleErr(w, r, err, http.StatusInternalServerError)
|
U.HandleErr(w, r, err, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ func OIDCCallbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleTestCallback handles OIDC callback in test environment
|
// handleTestCallback handles OIDC callback in test environment.
|
||||||
func handleTestCallback(w http.ResponseWriter, r *http.Request) {
|
func handleTestCallback(w http.ResponseWriter, r *http.Request) {
|
||||||
state, err := r.Cookie("oauth_state")
|
state, err := r.Cookie("oauth_state")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// setupMockOIDC configures mock OIDC provider for testing
|
// setupMockOIDC configures mock OIDC provider for testing.
|
||||||
func setupMockOIDC(t *testing.T) {
|
func setupMockOIDC(t *testing.T) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ func TestOIDCLoginHandler(t *testing.T) {
|
||||||
oauthConfig = nil
|
oauthConfig = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
req := httptest.NewRequest("GET", "/login/oidc", nil)
|
req := httptest.NewRequest(http.MethodGet, "/login/oidc", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
OIDCLoginHandler(w, req)
|
OIDCLoginHandler(w, req)
|
||||||
|
@ -143,7 +143,7 @@ func TestOIDCCallbackHandler(t *testing.T) {
|
||||||
oauthConfig = nil
|
oauthConfig = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
req := httptest.NewRequest("GET", "/auth/callback?code="+tt.code+"&state="+tt.state, nil)
|
req := httptest.NewRequest(http.MethodGet, "/auth/callback?code="+tt.code+"&state="+tt.state, nil)
|
||||||
if tt.state != "" {
|
if tt.state != "" {
|
||||||
req.AddCookie(&http.Cookie{
|
req.AddCookie(&http.Cookie{
|
||||||
Name: "oauth_state",
|
Name: "oauth_state",
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"github.com/yusing/go-proxy/internal/common"
|
"github.com/yusing/go-proxy/internal/common"
|
||||||
D "github.com/yusing/go-proxy/internal/docker"
|
D "github.com/yusing/go-proxy/internal/docker"
|
||||||
E "github.com/yusing/go-proxy/internal/error"
|
E "github.com/yusing/go-proxy/internal/error"
|
||||||
"github.com/yusing/go-proxy/internal/homepage"
|
|
||||||
"github.com/yusing/go-proxy/internal/route"
|
"github.com/yusing/go-proxy/internal/route"
|
||||||
"github.com/yusing/go-proxy/internal/route/entry"
|
"github.com/yusing/go-proxy/internal/route/entry"
|
||||||
T "github.com/yusing/go-proxy/internal/route/types"
|
T "github.com/yusing/go-proxy/internal/route/types"
|
||||||
|
@ -130,8 +129,9 @@ func TestApplyLabel(t *testing.T) {
|
||||||
ExpectEqual(t, b.Container.StopSignal, "SIGTERM")
|
ExpectEqual(t, b.Container.StopSignal, "SIGTERM")
|
||||||
|
|
||||||
ExpectEqual(t, a.Homepage.Show, true)
|
ExpectEqual(t, a.Homepage.Show, true)
|
||||||
ExpectEqual(t, a.Homepage.Icon.Value, homepage.DashboardIconBaseURL+"png/example.png")
|
ExpectEqual(t, a.Homepage.Icon.Value, "png/example.png")
|
||||||
ExpectEqual(t, a.Homepage.Icon.IsRelative, false)
|
ExpectEqual(t, a.Homepage.Icon.Extra.FileType, "png")
|
||||||
|
ExpectEqual(t, a.Homepage.Icon.Extra.Name, "example")
|
||||||
|
|
||||||
ExpectEqual(t, a.HealthCheck.Path, "/ping")
|
ExpectEqual(t, a.HealthCheck.Path, "/ping")
|
||||||
ExpectEqual(t, a.HealthCheck.Interval, 10*time.Second)
|
ExpectEqual(t, a.HealthCheck.Interval, 10*time.Second)
|
||||||
|
|
Loading…
Add table
Reference in a new issue