Fixed: #822
**fix(auth): normalize ID casing on Windows to prevent duplicate entries due to case-insensitive paths**
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -692,17 +693,20 @@ func (h *Handler) authIDForPath(path string) string {
|
|||||||
if path == "" {
|
if path == "" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
if h == nil || h.cfg == nil {
|
id := path
|
||||||
return path
|
if h != nil && h.cfg != nil {
|
||||||
|
authDir := strings.TrimSpace(h.cfg.AuthDir)
|
||||||
|
if authDir != "" {
|
||||||
|
if rel, errRel := filepath.Rel(authDir, path); errRel == nil && rel != "" {
|
||||||
|
id = rel
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
authDir := strings.TrimSpace(h.cfg.AuthDir)
|
// On Windows, normalize ID casing to avoid duplicate auth entries caused by case-insensitive paths.
|
||||||
if authDir == "" {
|
if runtime.GOOS == "windows" {
|
||||||
return path
|
id = strings.ToLower(id)
|
||||||
}
|
}
|
||||||
if rel, err := filepath.Rel(authDir, path); err == nil && rel != "" {
|
return id
|
||||||
return rel
|
|
||||||
}
|
|
||||||
return path
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) registerAuthFromFile(ctx context.Context, path string, data []byte) error {
|
func (h *Handler) registerAuthFromFile(ctx context.Context, path string, data []byte) error {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -72,6 +73,10 @@ func (s *FileSynthesizer) Synthesize(ctx *SynthesisContext) ([]*coreauth.Auth, e
|
|||||||
if rel, errRel := filepath.Rel(ctx.AuthDir, full); errRel == nil && rel != "" {
|
if rel, errRel := filepath.Rel(ctx.AuthDir, full); errRel == nil && rel != "" {
|
||||||
id = rel
|
id = rel
|
||||||
}
|
}
|
||||||
|
// On Windows, normalize ID casing to avoid duplicate auth entries caused by case-insensitive paths.
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
id = strings.ToLower(id)
|
||||||
|
}
|
||||||
|
|
||||||
proxyURL := ""
|
proxyURL := ""
|
||||||
if p, ok := metadata["proxy_url"].(string); ok {
|
if p, ok := metadata["proxy_url"].(string); ok {
|
||||||
|
|||||||
+10
-6
@@ -10,6 +10,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -257,14 +258,17 @@ func (s *FileTokenStore) readAuthFile(path, baseDir string) (*cliproxyauth.Auth,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *FileTokenStore) idFor(path, baseDir string) string {
|
func (s *FileTokenStore) idFor(path, baseDir string) string {
|
||||||
if baseDir == "" {
|
id := path
|
||||||
return path
|
if baseDir != "" {
|
||||||
|
if rel, errRel := filepath.Rel(baseDir, path); errRel == nil && rel != "" {
|
||||||
|
id = rel
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rel, err := filepath.Rel(baseDir, path)
|
// On Windows, normalize ID casing to avoid duplicate auth entries caused by case-insensitive paths.
|
||||||
if err != nil {
|
if runtime.GOOS == "windows" {
|
||||||
return path
|
id = strings.ToLower(id)
|
||||||
}
|
}
|
||||||
return rel
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FileTokenStore) resolveAuthPath(auth *cliproxyauth.Auth) (string, error) {
|
func (s *FileTokenStore) resolveAuthPath(auth *cliproxyauth.Auth) (string, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user