Skip to content

Commit

Permalink
fix: docker test and golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
yusing committed Jan 12, 2025
1 parent 9a12dab commit ef277ef
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions internal/api/v1/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) {
U.HandleErr(w, r, err, http.StatusUnauthorized)
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)
return
}
Expand All @@ -72,7 +72,7 @@ func AuthMethodHandler(w http.ResponseWriter, r *http.Request) {
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)
claim := &Claims{
Username: username,
Expand Down
10 changes: 5 additions & 5 deletions internal/api/v1/auth/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
oidcVerifier *oidc.IDTokenVerifier
)

// InitOIDC initializes the OIDC provider
// InitOIDC initializes the OIDC provider.
func InitOIDC(issuerURL, clientID, clientSecret, redirectURL string) error {
if issuerURL == "" {
return nil // OIDC not configured
Expand All @@ -47,7 +47,7 @@ func InitOIDC(issuerURL, clientID, clientSecret, redirectURL string) error {
return nil
}

// OIDCLoginHandler initiates the OIDC login flow
// OIDCLoginHandler initiates the OIDC login flow.
func OIDCLoginHandler(w http.ResponseWriter, r *http.Request) {
if oauthConfig == nil {
U.HandleErr(w, r, E.New("OIDC not configured"), http.StatusNotImplemented)
Expand All @@ -69,7 +69,7 @@ func OIDCLoginHandler(w http.ResponseWriter, r *http.Request) {
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) {
if oauthConfig == nil {
U.HandleErr(w, r, E.New("OIDC not configured"), http.StatusNotImplemented)
Expand Down Expand Up @@ -126,7 +126,7 @@ func OIDCCallbackHandler(w http.ResponseWriter, r *http.Request) {
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)
return
}
Expand All @@ -135,7 +135,7 @@ func OIDCCallbackHandler(w http.ResponseWriter, r *http.Request) {
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) {
state, err := r.Cookie("oauth_state")
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/api/v1/auth/oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"golang.org/x/oauth2"
)

// setupMockOIDC configures mock OIDC provider for testing
// setupMockOIDC configures mock OIDC provider for testing.
func setupMockOIDC(t *testing.T) {
t.Helper()

Expand Down Expand Up @@ -68,7 +68,7 @@ func TestOIDCLoginHandler(t *testing.T) {
oauthConfig = nil
}

req := httptest.NewRequest("GET", "/login/oidc", nil)
req := httptest.NewRequest(http.MethodGet, "/login/oidc", nil)
w := httptest.NewRecorder()

OIDCLoginHandler(w, req)
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestOIDCCallbackHandler(t *testing.T) {
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 != "" {
req.AddCookie(&http.Cookie{
Name: "oauth_state",
Expand Down
6 changes: 3 additions & 3 deletions internal/route/provider/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/yusing/go-proxy/internal/common"
D "github.com/yusing/go-proxy/internal/docker"
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/entry"
T "github.com/yusing/go-proxy/internal/route/types"
Expand Down Expand Up @@ -130,8 +129,9 @@ func TestApplyLabel(t *testing.T) {
ExpectEqual(t, b.Container.StopSignal, "SIGTERM")

ExpectEqual(t, a.Homepage.Show, true)
ExpectEqual(t, a.Homepage.Icon.Value, homepage.DashboardIconBaseURL+"png/example.png")
ExpectEqual(t, a.Homepage.Icon.IsRelative, false)
ExpectEqual(t, a.Homepage.Icon.Value, "png/example.png")
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.Interval, 10*time.Second)
Expand Down

0 comments on commit ef277ef

Please sign in to comment.