RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
fix(data_source): support custom base URL and HTTP for Azure DevOps c… (#19407)
ori-frenkel15c705a33367
diff --git a/common/data_source/azure_devops/connector.py b/common/data_source/azure_devops/connector.pyindex b20e2adf0f..b7c384bc75 100644--- a/common/data_source/azure_devops/connector.py+++ b/common/data_source/azure_devops/connector.py@@ -4,7 +4,8 @@ import copyimport loggingfrom collections.abc import Iteratorfrom datetime import datetime, timezone-from typing import Any, TYPE_CHECKING+from typing import TYPE_CHECKING, Any+from urllib.parse import urlparsefrom typing_extensions import override@@ -100,10 +101,12 @@ class AzureDevOpsConnector(Works against both Azure DevOps Services and self-hosted Azure DevOps Server:pass a bare organization name for the former, or the full collection URL for- the latter.+ the latter, or provide a custom base URL.Args:organization: Organization name, or base URL of a self-hosted collection.+ base_url: Optional custom base URL (e.g. https://dev.azure.com or+ http://tfs.corp.local:8080/tfs).index_mode: Scope selector — ``organization``, ``projects`` or ``repositories``.projects: Comma-separated team projects, used when ``index_mode`` is ``projects``.repositories: Comma-separated repositories, used when ``index_mode`` is@@ -114,14 +117,24 @@ class AzureDevOpsConnector(def __init__(self,- organization: str,+ organization: str | None = None,+ base_url: str | None = None,index_mode: str = INDEX_MODE_ORGANIZATION,projects: str | None = None,repositories: str | None = None,content_types: str = CONTENT_BOTH,batch_size: int = INDEX_BATCH_SIZE,) -> None:- self.organization = organization+ self.base_url = (base_url or "").strip() or None+ self.organization = (organization or "").strip()+ if not self.organization and self.base_url:+ try:+ parsed = urlparse(self.base_url)+ path_segments = [seg for seg in parsed.path.strip("/").split("/") if seg]+ if path_segments:+ self.organization = path_segments[-1]+ except Exception:+ passself.index_mode = index_mode or INDEX_MODE_ORGANIZATIONself._projects = self._split(projects)self._repositories = self._split(repositories)@@ -139,6 +152,7 @@ class AzureDevOpsConnector(credentials = config.get("credentials") or {}connector = cls(organization=config.get("organization"),+ base_url=config.get("base_url"),index_mode=config.get("index_mode") or INDEX_MODE_ORGANIZATION,projects=config.get("projects"),repositories=config.get("repositories"),@@ -156,7 +170,7 @@ class AzureDevOpsConnector(@propertydef _org_url(self) -> str:- return organization_url(self.organization)+ return organization_url(self.organization, self.base_url)def _client(self) -> "httpx.Client":if not self.personal_access_token:@@ -573,6 +587,30 @@ class AzureDevOpsConnector(An unknown selector would otherwise pass silently and the sync wouldcomplete without producing a single document."""+ if not self.organization:+ raise UnexpectedValidationError("Azure DevOps organization or collection must be provided.")+ if self.base_url:+ if not self.base_url.startswith(("http://", "https://")):+ raise UnexpectedValidationError("Azure DevOps base URL must use HTTP or HTTPS.")+ parsed_base = urlparse(self.base_url)+ if not parsed_base.hostname:+ raise UnexpectedValidationError("Azure DevOps base URL must include a valid host.")+ if parsed_base.username or parsed_base.password:+ raise UnexpectedValidationError("Azure DevOps base URL must not contain credentials; provide a personal access token instead.")+ if parsed_base.query or parsed_base.fragment:+ raise UnexpectedValidationError("Azure DevOps base URL must not contain query parameters or fragments.")+ if self.organization and "://" in self.organization:+ if not self.organization.startswith(("http://", "https://")):+ raise UnexpectedValidationError("Azure DevOps organization URL must use HTTP or HTTPS.")+ parsed_org = urlparse(self.organization)+ if not parsed_org.hostname:+ raise UnexpectedValidationError("Azure DevOps organization URL must include a valid host.")+ if parsed_org.username or parsed_org.password:+ raise UnexpectedValidationError("Azure DevOps organization URL must not contain credentials; provide a personal access token instead.")+ if parsed_org.query or parsed_org.fragment:+ raise UnexpectedValidationError("Azure DevOps organization URL must not contain query parameters or fragments.")+ elif self.organization and ("?" in self.organization or "#" in self.organization):+ raise UnexpectedValidationError("Azure DevOps organization must not contain query parameters or fragments.")if self.index_mode not in (INDEX_MODE_ORGANIZATION, INDEX_MODE_PROJECTS, INDEX_MODE_REPOSITORIES):raise UnexpectedValidationError(f"Unsupported index mode: {self.index_mode}")if self.content_types not in (CONTENT_CODE, CONTENT_PULL_REQUESTS, CONTENT_BOTH):@@ -603,7 +641,8 @@ class AzureDevOpsConnector()raise_for_auth(response)if response.status_code == 404:- raise UnexpectedValidationError(f"Azure DevOps organization not found: {self.organization}")+ target = self.organization or self.base_url or "organization"+ raise UnexpectedValidationError(f"Azure DevOps organization not found: {target}")if response.status_code < 200 or response.status_code >= 300:raise UnexpectedValidationError(f"Unexpected Azure DevOps error (status={response.status_code}).")diff --git a/common/data_source/azure_devops/utils.py b/common/data_source/azure_devops/utils.pyindex aaaa800f8d..c8bead4552 100644--- a/common/data_source/azure_devops/utils.py+++ b/common/data_source/azure_devops/utils.py@@ -5,7 +5,7 @@ import timefrom collections.abc import Iteratorfrom datetime import datetime, timezonefrom typing import Any-from urllib.parse import quote+from urllib.parse import quote, urlparseimport httpx@@ -101,18 +101,66 @@ def build_auth_client(personal_access_token: str) -> httpx.Client:return httpx.Client(auth=("", personal_access_token), timeout=REQUEST_TIMEOUT_SECONDS)-def organization_url(organization: str) -> str:+def organization_url(organization: str | None = None, base_url: str | None = None) -> str:"""Resolve the API root for a hosted organization or a self-hosted server.- ``organization`` may be a bare organization name (Azure DevOps Services) or a- full base URL such as ``https://tfs.contoso.com/DefaultCollection`` for- Azure DevOps Server.+ ``organization`` may be a bare organization name (Azure DevOps Services),+ a collection name, or a full base URL such as+ ``https://tfs.contoso.com/DefaultCollection`` for Azure DevOps Server.++ ``base_url`` is an optional custom base URL (e.g. ``https://dev.azure.com``,+ ``https://tfs.contoso.com/tfs``, or ``http://tfs.corp.local:8080/tfs``)."""- if organization.startswith("http://"):- raise UnexpectedValidationError("Azure DevOps collection URLs must use HTTPS; the personal access token is sent in the Authorization header.")- if organization.startswith("https://"):- return organization.rstrip("/")- return f"https://dev.azure.com/{quote(organization, safe='')}"+ clean_base = (base_url or "").strip().rstrip("/")+ clean_org = (organization or "").strip().rstrip("/")++ if clean_base:+ if not clean_base.startswith(("http://", "https://")):+ raise UnexpectedValidationError("Azure DevOps base URL must use HTTP or HTTPS.")+ parsed_base = urlparse(clean_base)+ if not parsed_base.hostname:+ raise UnexpectedValidationError("Azure DevOps base URL must include a valid host.")+ if parsed_base.username or parsed_base.password:+ raise UnexpectedValidationError("Azure DevOps base URL must not contain credentials; provide a personal access token instead.")+ if parsed_base.query or parsed_base.fragment:+ raise UnexpectedValidationError("Azure DevOps base URL must not contain query parameters or fragments.")+ if not clean_org:+ path_segments = [seg for seg in parsed_base.path.strip("/").split("/") if seg]+ if not path_segments:+ raise UnexpectedValidationError("Azure DevOps organization or collection must be provided.")+ return clean_base+ if clean_org.startswith(("http://", "https://")):+ parsed_org = urlparse(clean_org)+ if not parsed_org.hostname:+ raise UnexpectedValidationError("Azure DevOps organization URL must include a valid host.")+ if parsed_org.username or parsed_org.password:+ raise UnexpectedValidationError("Azure DevOps organization URL must not contain credentials; provide a personal access token instead.")+ if parsed_org.query or parsed_org.fragment:+ raise UnexpectedValidationError("Azure DevOps organization URL must not contain query parameters or fragments.")+ return clean_org+ if "?" in clean_org or "#" in clean_org:+ raise UnexpectedValidationError("Azure DevOps organization must not contain query parameters or fragments.")+ if clean_base.endswith((f"/{clean_org}", f"/{quote(clean_org, safe='')}")):+ return clean_base+ return f"{clean_base}/{quote(clean_org, safe='')}"++ if not clean_org:+ raise UnexpectedValidationError("Azure DevOps organization or base URL must be provided.")++ if clean_org.startswith(("http://", "https://")):+ parsed_org = urlparse(clean_org)+ if not parsed_org.hostname:+ raise UnexpectedValidationError("Azure DevOps organization URL must include a valid host.")+ if parsed_org.username or parsed_org.password:+ raise UnexpectedValidationError("Azure DevOps organization URL must not contain credentials; provide a personal access token instead.")+ if parsed_org.query or parsed_org.fragment:+ raise UnexpectedValidationError("Azure DevOps organization URL must not contain query parameters or fragments.")+ return clean_org+ if "://" in clean_org:+ raise UnexpectedValidationError("Azure DevOps collection URLs must use HTTP or HTTPS.")+ if "?" in clean_org or "#" in clean_org:+ raise UnexpectedValidationError("Azure DevOps organization must not contain query parameters or fragments.")+ return f"https://dev.azure.com/{quote(clean_org, safe='')}"def raise_for_auth(response: httpx.Response, expect_json: bool = True) -> None:diff --git a/internal/syncer/connector/azure_devops.go b/internal/syncer/connector/azure_devops.goindex a1976d3951..7bbcab9760 100644--- a/internal/syncer/connector/azure_devops.go+++ b/internal/syncer/connector/azure_devops.go@@ -95,15 +95,16 @@ func (e *azureDevOpsHTTPError) Error() string {// AzureDevOpsConnector reads Azure Repos source files and pull requests.type AzureDevOpsConnector struct {- organization string- indexMode string- projects []string- repositories []string- contentTypes string- pat string- batchSize int- baseURL string- httpClient *http.Client+ organization string+ customBaseURL string+ indexMode string+ projects []string+ repositories []string+ contentTypes string+ pat string+ batchSize int+ baseURL string+ httpClient *http.Client}// azureDevOpsRepository is one repository selected for indexing.@@ -158,36 +159,69 @@ type azureDevOpsPullRequest struct {func NewAzureDevOpsConnector(config map[string]any) (*AzureDevOpsConnector, error) {credentials, _ := config["credentials"].(map[string]any)organization := strings.TrimSpace(stringConfig(config["organization"]))+ customBaseURL := strings.TrimRight(strings.TrimSpace(stringConfig(config["base_url"])), "/")++ baseURL, effectiveOrg := azureDevOpsResolveURL(organization, customBaseURL)connector := &AzureDevOpsConnector{- organization: organization,- indexMode: firstNonEmpty(strings.TrimSpace(stringConfig(config["index_mode"])), azureDevOpsIndexModeOrganization),- projects: splitAzureDevOpsList(stringConfig(config["projects"])),- repositories: splitAzureDevOpsList(stringConfig(config["repositories"])),- contentTypes: firstNonEmpty(strings.TrimSpace(stringConfig(config["content_types"])), azureDevOpsContentBoth),- pat: strings.TrimSpace(stringConfig(credentials["azure_devops_pat"])),- batchSize: configInt(config["batch_size"], defaultAzureDevOpsBatchSize),- baseURL: azureDevOpsOrganizationURL(organization),- httpClient: &http.Client{Timeout: 60 * time.Second},+ organization: effectiveOrg,+ customBaseURL: customBaseURL,+ indexMode: firstNonEmpty(strings.TrimSpace(stringConfig(config["index_mode"])), azureDevOpsIndexModeOrganization),+ projects: splitAzureDevOpsList(stringConfig(config["projects"])),+ repositories: splitAzureDevOpsList(stringConfig(config["repositories"])),+ contentTypes: firstNonEmpty(strings.TrimSpace(stringConfig(config["content_types"])), azureDevOpsContentBoth),+ pat: strings.TrimSpace(stringConfig(credentials["azure_devops_pat"])),+ batchSize: configInt(config["batch_size"], defaultAzureDevOpsBatchSize),+ baseURL: baseURL,+ httpClient: &http.Client{Timeout: 60 * time.Second},}return connector, nil}-// azureDevOpsOrganizationURL resolves the API root of a hosted organization or-// a self-hosted Azure DevOps Server collection.-func azureDevOpsOrganizationURL(organization string) string {- if organization == "" {- return ""+func azureDevOpsResolveURL(organization, customBaseURL string) (string, string) {+ cleanBase := strings.TrimRight(strings.TrimSpace(customBaseURL), "/")+ cleanOrg := strings.TrimRight(strings.TrimSpace(organization), "/")++ if cleanBase != "" {+ if u, err := url.Parse(cleanBase); err == nil && u.Scheme != "" {+ u.RawQuery = ""+ u.Fragment = ""+ u.ForceQuery = false+ cleanBase = strings.TrimRight(u.String(), "/")+ }+ if cleanOrg == "" {+ if u, err := url.Parse(cleanBase); err == nil && u.Path != "" {+ trimmedPath := strings.Trim(u.Path, "/")+ if trimmedPath != "" {+ parts := strings.Split(trimmedPath, "/")+ cleanOrg = parts[len(parts)-1]+ }+ }+ return cleanBase, cleanOrg+ }+ if strings.HasPrefix(cleanOrg, "http://") || strings.HasPrefix(cleanOrg, "https://") {+ return cleanOrg, cleanOrg+ }+ if strings.HasSuffix(cleanBase, "/"+cleanOrg) || strings.HasSuffix(cleanBase, "/"+url.PathEscape(cleanOrg)) {+ return cleanBase, cleanOrg+ }+ return cleanBase + "/" + url.PathEscape(cleanOrg), cleanOrg}- if strings.HasPrefix(organization, "http://") {- // Rejected in checkSettings; never build a client that would send the- // personal access token in cleartext.- return ""++ if cleanOrg == "" {+ return "", ""}- if strings.HasPrefix(organization, "https://") {- return strings.TrimRight(organization, "/")+ if strings.HasPrefix(cleanOrg, "http://") || strings.HasPrefix(cleanOrg, "https://") {+ return cleanOrg, cleanOrg}- return azureDevOpsHostedBaseURL + "/" + url.PathEscape(organization)+ return azureDevOpsHostedBaseURL + "/" + url.PathEscape(cleanOrg), cleanOrg+}++// azureDevOpsOrganizationURL resolves the API root of a hosted organization or+// a self-hosted Azure DevOps Server collection.+func azureDevOpsOrganizationURL(organization string) string {+ baseURL, _ := azureDevOpsResolveURL(organization, "")+ return baseURL}func splitAzureDevOpsList(value string) []string {@@ -214,13 +248,42 @@ func (c *AzureDevOpsConnector) checkSettings() error {return fmt.Errorf("azure devops connector is nil")}if c.organization == "" {- return fmt.Errorf("Invalid connector settings: 'organization' must be provided")+ return fmt.Errorf("Invalid connector settings: Azure DevOps organization or collection must be provided")}if c.pat == "" {return fmt.Errorf("Missing azure_devops_pat in credentials")}- if strings.HasPrefix(c.organization, "http://") {- return fmt.Errorf("Invalid connector settings: Azure DevOps collection URLs must use HTTPS, the personal access token is sent in the Authorization header")+ if c.customBaseURL != "" {+ if !strings.HasPrefix(c.customBaseURL, "http://") && !strings.HasPrefix(c.customBaseURL, "https://") {+ return fmt.Errorf("Invalid connector settings: Azure DevOps base URL must use HTTP or HTTPS")+ }+ u, err := url.Parse(c.customBaseURL)+ if err != nil || u.Hostname() == "" {+ return fmt.Errorf("Invalid connector settings: Azure DevOps base URL must include a valid host")+ }+ if u.User != nil {+ return fmt.Errorf("Invalid connector settings: Azure DevOps base URL must not contain credentials")+ }+ if u.RawQuery != "" || u.Fragment != "" {+ return fmt.Errorf("Invalid connector settings: Azure DevOps base URL must not contain query parameters or fragments")+ }+ }+ if c.organization != "" && strings.Contains(c.organization, "://") {+ if !strings.HasPrefix(c.organization, "http://") && !strings.HasPrefix(c.organization, "https://") {+ return fmt.Errorf("Invalid connector settings: Azure DevOps collection URLs must use HTTP or HTTPS")+ }+ u, err := url.Parse(c.organization)+ if err != nil || u.Hostname() == "" {+ return fmt.Errorf("Invalid connector settings: Azure DevOps collection URL must include a valid host")+ }+ if u.User != nil {+ return fmt.Errorf("Invalid connector settings: Azure DevOps collection URL must not contain credentials")+ }+ if u.RawQuery != "" || u.Fragment != "" {+ return fmt.Errorf("Invalid connector settings: Azure DevOps collection URL must not contain query parameters or fragments")+ }+ } else if c.organization != "" && (strings.Contains(c.organization, "?") || strings.Contains(c.organization, "#")) {+ return fmt.Errorf("Invalid connector settings: Azure DevOps organization must not contain query parameters or fragments")}switch c.indexMode {case azureDevOpsIndexModeOrganization, azureDevOpsIndexModeProjects, azureDevOpsIndexModeRepositories:diff --git a/internal/syncer/connector/azure_devops_test.go b/internal/syncer/connector/azure_devops_test.goindex 4ca43b0669..56d865f9db 100644--- a/internal/syncer/connector/azure_devops_test.go+++ b/internal/syncer/connector/azure_devops_test.go@@ -89,6 +89,56 @@ func TestAzureDevOpsOrganizationURLSupportsSelfHostedCollection(t *testing.T) {if got := azureDevOpsOrganizationURL("https://tfs.contoso.com/DefaultCollection/"); got != "https://tfs.contoso.com/DefaultCollection" {t.Fatalf("unexpected self-hosted URL: %s", got)}+ if got := azureDevOpsOrganizationURL("http://tfs.contoso.local:8080/DefaultCollection/"); got != "http://tfs.contoso.local:8080/DefaultCollection" {+ t.Fatalf("unexpected HTTP self-hosted URL: %s", got)+ }+}++func TestAzureDevOpsSupportsCustomBaseURL(t *testing.T) {+ connector, err := NewAzureDevOpsConnector(map[string]any{+ "base_url": "http://tfs.corp.local:8080/tfs",+ "organization": "DefaultCollection",+ "credentials": map[string]any{"azure_devops_pat": "token"},+ })+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ if connector.baseURL != "http://tfs.corp.local:8080/tfs/DefaultCollection" {+ t.Fatalf("unexpected baseURL: %s", connector.baseURL)+ }+ if connector.organization != "DefaultCollection" {+ t.Fatalf("unexpected organization: %s", connector.organization)+ }+}++func TestAzureDevOpsCustomBaseURLWithCollectionIncluded(t *testing.T) {+ connector, err := NewAzureDevOpsConnector(map[string]any{+ "base_url": "https://tfs.corp.local/tfs/DefaultCollection",+ "organization": "DefaultCollection",+ "credentials": map[string]any{"azure_devops_pat": "token"},+ })+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ if connector.baseURL != "https://tfs.corp.local/tfs/DefaultCollection" {+ t.Fatalf("unexpected baseURL: %s", connector.baseURL)+ }+}++func TestAzureDevOpsCustomBaseURLWithEmptyOrganization(t *testing.T) {+ connector, err := NewAzureDevOpsConnector(map[string]any{+ "base_url": "http://tfs.corp.local:8080/tfs/DefaultCollection",+ "credentials": map[string]any{"azure_devops_pat": "token"},+ })+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ if connector.baseURL != "http://tfs.corp.local:8080/tfs/DefaultCollection" {+ t.Fatalf("unexpected baseURL: %s", connector.baseURL)+ }+ if connector.organization != "DefaultCollection" {+ t.Fatalf("unexpected organization: %s", connector.organization)+ }}func TestAzureDevOpsDefaultsIndexModeAndContentTypes(t *testing.T) {@@ -605,7 +655,7 @@ func TestAzureDevOpsLongPullRequestDescriptionIsRefetchedInFull(t *testing.T) {}}-func TestAzureDevOpsRejectsCleartextCollectionURL(t *testing.T) {+func TestAzureDevOpsAcceptsHTTPCollectionURLInClosedNetwork(t *testing.T) {connector, err := NewAzureDevOpsConnector(map[string]any{"organization": "http://tfs.contoso.com/DefaultCollection","credentials": map[string]any{"azure_devops_pat": "token"},@@ -613,8 +663,138 @@ func TestAzureDevOpsRejectsCleartextCollectionURL(t *testing.T) {if err != nil {t.Fatalf("unexpected error: %v", err)}- if err := connector.Validate(context.Background()); err == nil || !strings.Contains(err.Error(), "HTTPS") {- t.Fatalf("cleartext collection URLs must be rejected, got %v", err)+ if connector.baseURL != "http://tfs.contoso.com/DefaultCollection" {+ t.Fatalf("expected HTTP collection URL, got %s", connector.baseURL)+ }+}++func TestAzureDevOpsRejectsInvalidScheme(t *testing.T) {+ connector, err := NewAzureDevOpsConnector(map[string]any{+ "base_url": "ftp://tfs.contoso.com/tfs",+ "credentials": map[string]any{"azure_devops_pat": "token"},+ })+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ if err := connector.Validate(context.Background()); err == nil || !strings.Contains(err.Error(), "HTTP") {+ t.Fatalf("invalid scheme must be rejected, got %v", err)+ }+}++func TestAzureDevOpsRejectsRootBaseURLWithoutOrganization(t *testing.T) {+ connector, err := NewAzureDevOpsConnector(map[string]any{+ "base_url": "https://dev.azure.com",+ "credentials": map[string]any{"azure_devops_pat": "token"},+ })+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ if err := connector.Validate(context.Background()); err == nil || !strings.Contains(err.Error(), "organization or collection") {+ t.Fatalf("root base URL without organization must be rejected, got %v", err)+ }++ connectorHTTP, err := NewAzureDevOpsConnector(map[string]any{+ "base_url": "http://tfs.corp.local:8080",+ "credentials": map[string]any{"azure_devops_pat": "token"},+ })+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ if err := connectorHTTP.Validate(context.Background()); err == nil || !strings.Contains(err.Error(), "organization or collection") {+ t.Fatalf("root base URL without organization must be rejected, got %v", err)+ }+}++func TestAzureDevOpsRejectsURLWithCredentials(t *testing.T) {+ connectorBase, err := NewAzureDevOpsConnector(map[string]any{+ "base_url": "http://user:[email protected]:8080/tfs/DefaultCollection",+ "credentials": map[string]any{"azure_devops_pat": "token"},+ })+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ if err := connectorBase.Validate(context.Background()); err == nil || !strings.Contains(err.Error(), "credentials") {+ t.Fatalf("base URL with credentials must be rejected, got %v", err)+ }++ connectorOrg, err := NewAzureDevOpsConnector(map[string]any{+ "organization": "http://user:[email protected]:8080/tfs/DefaultCollection",+ "credentials": map[string]any{"azure_devops_pat": "token"},+ })+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ if err := connectorOrg.Validate(context.Background()); err == nil || !strings.Contains(err.Error(), "credentials") {+ t.Fatalf("organization URL with credentials must be rejected, got %v", err)+ }+}++func TestAzureDevOpsRejectsHostlessURL(t *testing.T) {+ connectorBase, err := NewAzureDevOpsConnector(map[string]any{+ "base_url": "https:///DefaultCollection",+ "credentials": map[string]any{"azure_devops_pat": "token"},+ })+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ if err := connectorBase.Validate(context.Background()); err == nil || !strings.Contains(err.Error(), "host") {+ t.Fatalf("base URL without host must be rejected, got %v", err)+ }++ connectorOrg, err := NewAzureDevOpsConnector(map[string]any{+ "organization": "https:///DefaultCollection",+ "credentials": map[string]any{"azure_devops_pat": "token"},+ })+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ if err := connectorOrg.Validate(context.Background()); err == nil || !strings.Contains(err.Error(), "host") {+ t.Fatalf("organization URL without host must be rejected, got %v", err)+ }+}++func TestAzureDevOpsRejectsQueryAndFragment(t *testing.T) {+ testCases := []map[string]any{+ {"base_url": "http://tfs.corp.local:8080/tfs?test=1", "organization": "DefaultCollection"},+ {"base_url": "http://tfs.corp.local:8080/tfs#frag", "organization": "DefaultCollection"},+ {"organization": "http://tfs.corp.local:8080/DefaultCollection?test=1"},+ {"organization": "http://tfs.corp.local:8080/DefaultCollection#frag"},+ {"organization": "DefaultCollection?test=1"},+ {"organization": "DefaultCollection#frag"},+ }++ for _, tc := range testCases {+ cfg := map[string]any{+ "credentials": map[string]any{"azure_devops_pat": "token"},+ }+ for k, v := range tc {+ cfg[k] = v+ }+ connector, err := NewAzureDevOpsConnector(cfg)+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }+ if err := connector.Validate(context.Background()); err == nil || (!strings.Contains(err.Error(), "query") && !strings.Contains(err.Error(), "fragment")) {+ t.Fatalf("expected query/fragment rejection for %+v, got %v", tc, err)+ }+ }+}++func TestAzureDevOpsResolveURLStripsQueryAndFragment(t *testing.T) {+ got, org := azureDevOpsResolveURL("DefaultCollection", "http://tfs.corp.local:8080/tfs?test=1#frag")+ if got != "http://tfs.corp.local:8080/tfs/DefaultCollection" {+ t.Fatalf("unexpected resolved URL: %s", got)+ }+ if org != "DefaultCollection" {+ t.Fatalf("unexpected org: %s", org)+ }++ gotWithoutOrg, orgExtracted := azureDevOpsResolveURL("", "http://tfs.corp.local:8080/tfs/DefaultCollection?test=1#frag")+ if gotWithoutOrg != "http://tfs.corp.local:8080/tfs/DefaultCollection" {+ t.Fatalf("unexpected resolved URL: %s", gotWithoutOrg)+ }+ if orgExtracted != "DefaultCollection" {+ t.Fatalf("unexpected org: %s", orgExtracted)}}diff --git a/rag/svr/sync_data_source.py b/rag/svr/sync_data_source.pyindex 3e59a450d6..5cddf26de6 100644--- a/rag/svr/sync_data_source.py+++ b/rag/svr/sync_data_source.py@@ -34,6 +34,7 @@ import threadingimport tracebackfrom datetime import UTC, datetime, timezonefrom typing import Any+from urllib.parse import urlparse, urlunparsefrom flask import json@@ -111,6 +112,20 @@ def _redact_mailbox(value: str) -> str:return f"{value[:4]}***" if len(value) > 4 else "***"+def _redact_url(value: str | None) -> str:+ """Sanitize URL before logging, stripping user credentials, query, and fragment."""+ if not value or "://" not in value:+ return value or ""+ try:+ parsed = urlparse(value)+ netloc = parsed.hostname or ""+ if parsed.port:+ netloc = f"{netloc}:{parsed.port}"+ return urlunparse((parsed.scheme, netloc, parsed.path, "", "", ""))+ except (ValueError, TypeError):+ return "<invalid URL>"++async def _iterate_document_batches(generator):"""Yield connector batches, advancing thread-bridged iterators off the event loop.@@ -2012,6 +2027,7 @@ class AzureDevOps(SyncBase):async def _generate(self, task: dict):self.connector = AzureDevOpsConnector(organization=self.conf.get("organization"),+ base_url=self.conf.get("base_url"),index_mode=self.conf.get("index_mode") or "organization",projects=self.conf.get("projects"),repositories=self.conf.get("repositories"),@@ -2066,7 +2082,8 @@ class AzureDevOps(SyncBase):for batch in document_batches():yield batch- self.log_connection("AzureDevOps", f"organization({self.conf.get('organization')})", task)+ target = _redact_url(self.conf.get("base_url")) or f"organization({self.conf.get('organization')})"+ self.log_connection("AzureDevOps", target, task)return wrapper()diff --git a/test/unit_test/data_source/test_azure_devops_connector_unit.py b/test/unit_test/data_source/test_azure_devops_connector_unit.pyindex f388dd54fa..91148568f4 100644--- a/test/unit_test/data_source/test_azure_devops_connector_unit.py+++ b/test/unit_test/data_source/test_azure_devops_connector_unit.py@@ -264,6 +264,31 @@ def test_organization_url_accepts_self_hosted_collection():assert azure_utils.organization_url("https://tfs.contoso.com/DefaultCollection/") == "https://tfs.contoso.com/DefaultCollection"+def test_organization_url_accepts_http_in_closed_network():+ """On-premises Azure DevOps Server inside a closed network often runs over HTTP."""+ assert azure_utils.organization_url("http://tfs.contoso.local:8080/DefaultCollection/") == "http://tfs.contoso.local:8080/DefaultCollection"+++def test_organization_url_supports_custom_base_url():+ """Custom base URL combined with organization name."""+ assert azure_utils.organization_url(organization="DefaultCollection", base_url="http://tfs.corp.local:8080/tfs") == "http://tfs.corp.local:8080/tfs/DefaultCollection"+ assert azure_utils.organization_url(organization="DefaultCollection", base_url="https://tfs.contoso.com/tfs") == "https://tfs.contoso.com/tfs/DefaultCollection"+++def test_organization_url_custom_base_url_already_includes_organization():+ """When base_url already contains the collection, it must not be appended twice."""+ assert azure_utils.organization_url(organization="DefaultCollection", base_url="http://tfs.corp.local:8080/tfs/DefaultCollection") == "http://tfs.corp.local:8080/tfs/DefaultCollection"+++def test_organization_url_custom_base_url_empty_organization():+ """Custom base URL without organization returns the base URL."""+ assert azure_utils.organization_url(base_url="http://tfs.corp.local:8080/tfs/DefaultCollection") == "http://tfs.corp.local:8080/tfs/DefaultCollection"++@pytest.mark.p2def test_invalid_token_returns_203_sign_in_page_not_401():"""Azure DevOps answers a bad PAT with 203 and an HTML sign-in page.@@ -385,11 +410,107 @@ def test_default_branch_strips_ref_prefix():@pytest.mark.p2-def test_cleartext_collection_url_is_rejected():- """The PAT travels in the Authorization header, so HTTP is refused."""+def test_invalid_scheme_url_is_rejected():+ """Non-HTTP/HTTPS URLs are refused."""+ with pytest.raises(UnexpectedValidationError) as excinfo:+ azure_utils.organization_url("ftp://tfs.contoso.com/DefaultCollection")+ assert "HTTP" in str(excinfo.value)++ with pytest.raises(UnexpectedValidationError) as excinfo:+ azure_utils.organization_url(base_url="ftp://tfs.contoso.com/tfs")+ assert "HTTP" in str(excinfo.value)+++def test_connector_supports_custom_base_url():+ connector = AzureDevOpsConnector(+ organization="DefaultCollection",+ base_url="http://tfs.corp.local:8080/tfs",+ )+ assert connector._org_url == "http://tfs.corp.local:8080/tfs/DefaultCollection"+ assert connector.base_url == "http://tfs.corp.local:8080/tfs"+++def test_connector_build_connector_with_base_url():+ connector = AzureDevOpsConnector.build_connector(+ {+ "organization": "DefaultCollection",+ "base_url": "http://tfs.corp.local:8080/tfs",+ "credentials": {"azure_devops_pat": "token"},+ }+ )+ assert connector._org_url == "http://tfs.corp.local:8080/tfs/DefaultCollection"+ assert connector.personal_access_token == "token"+++def test_connector_custom_base_url_extracts_organization():+ connector = AzureDevOpsConnector(+ base_url="http://tfs.corp.local:8080/tfs/DefaultCollection",+ )+ assert connector.organization == "DefaultCollection"+ assert connector._org_url == "http://tfs.corp.local:8080/tfs/DefaultCollection"+++def test_organization_url_rejects_root_only_base_url_without_organization():+ with pytest.raises(UnexpectedValidationError) as excinfo:+ azure_utils.organization_url(base_url="https://dev.azure.com")+ assert "organization or collection" in str(excinfo.value)++ with pytest.raises(UnexpectedValidationError) as excinfo:+ azure_utils.organization_url("", base_url="http://tfs.corp.local:8080")+ assert "organization or collection" in str(excinfo.value)+++def test_organization_url_rejects_credentials_in_urls():+ with pytest.raises(UnexpectedValidationError) as excinfo:+ azure_utils.organization_url(organization="DefaultCollection", base_url="http://user:[email protected]:8080/tfs")+ assert "credentials" in str(excinfo.value)++ with pytest.raises(UnexpectedValidationError) as excinfo:+ azure_utils.organization_url("http://user:[email protected]:8080/tfs/DefaultCollection")+ assert "credentials" in str(excinfo.value)+++def test_organization_url_rejects_hostless_urls():+ with pytest.raises(UnexpectedValidationError) as excinfo:+ azure_utils.organization_url(base_url="https:///DefaultCollection")+ assert "valid host" in str(excinfo.value)++ with pytest.raises(UnexpectedValidationError) as excinfo:+ azure_utils.organization_url("https:///DefaultCollection")+ assert "valid host" in str(excinfo.value)+++def test_organization_url_rejects_query_and_fragment():+ with pytest.raises(UnexpectedValidationError) as excinfo:+ azure_utils.organization_url(organization="DefaultCollection", base_url="http://tfs.corp.local:8080/tfs?test=1")+ assert "query parameters or fragments" in str(excinfo.value)++ with pytest.raises(UnexpectedValidationError) as excinfo:+ azure_utils.organization_url(organization="DefaultCollection", base_url="http://tfs.corp.local:8080/tfs#frag")+ assert "query parameters or fragments" in str(excinfo.value)++ with pytest.raises(UnexpectedValidationError) as excinfo:+ azure_utils.organization_url("http://tfs.corp.local:8080/DefaultCollection?test=1")+ assert "query parameters or fragments" in str(excinfo.value)++ with pytest.raises(UnexpectedValidationError) as excinfo:+ azure_utils.organization_url("http://tfs.corp.local:8080/DefaultCollection#frag")+ assert "query parameters or fragments" in str(excinfo.value)++ with pytest.raises(UnexpectedValidationError) as excinfo:+ azure_utils.organization_url("DefaultCollection?test=1")+ assert "query parameters or fragments" in str(excinfo.value)+with pytest.raises(UnexpectedValidationError) as excinfo:- azure_utils.organization_url("http://tfs.contoso.com/DefaultCollection")- assert "HTTPS" in str(excinfo.value)+ azure_utils.organization_url("DefaultCollection#frag")+ assert "query parameters or fragments" in str(excinfo.value)@pytest.mark.p2@@ -406,11 +527,26 @@ def test_html_body_is_not_an_auth_failure_for_raw_content():{"index_mode": "everything"},{"content_types": "everything"},{"index_mode": INDEX_MODE_REPOSITORIES},+ {"organization": "", "base_url": ""},+ {"organization": "", "base_url": "ftp://invalid"},+ {"organization": "ftp://invalid", "base_url": ""},+ {"organization": "", "base_url": "https://dev.azure.com"},+ {"organization": "", "base_url": "http://tfs.corp.local:8080"},+ {"organization": "DefaultCollection", "base_url": "http://user:[email protected]:8080/tfs"},+ {"organization": "http://user:[email protected]:8080/tfs/DefaultCollection", "base_url": ""},+ {"organization": "", "base_url": "https:///DefaultCollection"},+ {"organization": "https:///DefaultCollection", "base_url": ""},+ {"organization": "DefaultCollection", "base_url": "http://tfs.corp.local:8080/tfs?test=1"},+ {"organization": "DefaultCollection", "base_url": "http://tfs.corp.local:8080/tfs#frag"},+ {"organization": "http://tfs.corp.local:8080/DefaultCollection?test=1", "base_url": ""},+ {"organization": "http://tfs.corp.local:8080/DefaultCollection#frag", "base_url": ""},+ {"organization": "DefaultCollection?test=1", "base_url": ""},+ {"organization": "DefaultCollection#frag", "base_url": ""},],)def test_unusable_settings_are_rejected_before_any_request(overrides):connector = _build_connector(**overrides)- with pytest.raises(UnexpectedValidationError, match="(?i)unsupported|required"):+ with pytest.raises(UnexpectedValidationError):connector._validate_settings()diff --git a/test/unit_test/rag/test_sync_data_source.py b/test/unit_test/rag/test_sync_data_source.pyindex d4e7c89ef1..021c2c7c2d 100644--- a/test/unit_test/rag/test_sync_data_source.py+++ b/test/unit_test/rag/test_sync_data_source.py@@ -931,3 +931,14 @@ async def test_dropbox_generate_skips_snapshot_for_full_reindex(monkeypatch):assert [doc.id for doc in file_list] == ["dropbox:id-1", "dropbox:id-2"]assert connector.retrieve_all_slim_docs_perm_sync_called is Trueassert connector.poll_source_called is False+++def test_redact_url_strips_credentials_query_and_fragment():+ _redact_url = sync_data_source._redact_url++ assert _redact_url("https://user:[email protected]:8080/tfs/DefaultCollection?test=1#frag") == "https://tfs.corp.local:8080/tfs/DefaultCollection"+ assert _redact_url("http://user:pass@host/path") == "http://host/path"+ assert _redact_url(None) == ""+ assert _redact_url("") == ""+ assert _redact_url("organization(myorg)") == "organization(myorg)"+ assert _redact_url("http://[invalid") == "<invalid URL>"diff --git a/web/src/locales/en.ts b/web/src/locales/en.tsindex fc44bd4cb5..df922c0058 100644--- a/web/src/locales/en.ts+++ b/web/src/locales/en.ts@@ -1445,6 +1445,7 @@ This auto-tagging feature enhances retrieval by adding another layer of domain-sdataSourceFieldIsCloud: 'Is Cloud',dataSourceFieldIndexMode: 'Index Mode',dataSourceFieldAzureDevOpsPat: 'Azure DevOps personal access token',+ dataSourceFieldAzureDevOpsBaseUrl: 'Base URL',dataSourceFieldAzureDevOpsOrganization: 'Azure DevOps organization',dataSourceFieldAzureDevOpsRepositories: 'Repositories',dataSourceFieldAzureDevOpsContentTypes: 'Content types',@@ -1636,8 +1637,10 @@ Example: Virtual Hosted Style`,sharepointSiteUrlTip:'Full URL of the SharePoint site to index, e.g. https://contoso.sharepoint.com/sites/MySite. Requires an Azure AD app with Sites.Read.All and Files.Read.All application permissions (admin consent).',azureDevOpsPatTip: 'A personal access token with the Code (Read) scope.',+ azureDevOpsBaseUrlTip:+ 'The Base URL of your Azure DevOps instance (e.g. https://dev.azure.com, or http://tfs.corp.local:8080/tfs for Azure DevOps Server / closed network). Defaults to https://dev.azure.com if omitted.',azureDevOpsOrganizationTip:- 'Organization name (e.g. "contoso"), or the full collection URL of a self-hosted Azure DevOps Server (e.g. https://tfs.contoso.com/DefaultCollection).',+ 'Organization name (e.g. "contoso"), or project collection name (e.g. "DefaultCollection"), or the full collection URL of a self-hosted Azure DevOps Server.',azureDevOpsProjectsTip:'Comma separated team project names. E.g., Project1,Project2',azureDevOpsRepositoriesTip:diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.tsindex 0b63dbd520..49fcb9d01c 100644--- a/web/src/locales/zh.ts+++ b/web/src/locales/zh.ts@@ -1287,8 +1287,10 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 R'要索引的 SharePoint 站点完整 URL,例如 https://contoso.sharepoint.com/sites/MySite。需要具备 Sites.Read.All 与 Files.Read.All 应用权限(管理员同意)的 Azure AD 应用。',boxDescription: '连接你的 Box 云盘以同步文件和文件夹。',azureDevOpsPatTip: '需要具有 Code (Read) 权限的个人访问令牌。',+ azureDevOpsBaseUrlTip:+ 'Azure DevOps 实例的基础 URL(例如 https://dev.azure.com,或私有网络/本地部署的 Azure DevOps Server 例如 http://tfs.corp.local:8080/tfs)。留空默认使用 https://dev.azure.com。',azureDevOpsOrganizationTip:- '组织名称(例如 contoso),或自托管 Azure DevOps Server 的集合地址(例如 https://tfs.contoso.com/DefaultCollection)。',+ '组织名称(例如 contoso),或项目集合名称(例如 DefaultCollection),或自托管 Azure DevOps Server 的集合地址。',azureDevOpsProjectsTip:'以逗号分隔的团队项目名称。例如:Project1,Project2',azureDevOpsRepositoriesTip:@@ -1451,6 +1453,7 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 RdataSourceFieldIsCloud: '是否为云版本',dataSourceFieldIndexMode: '索引模式',dataSourceFieldAzureDevOpsPat: 'Azure DevOps 个人访问令牌',+ dataSourceFieldAzureDevOpsBaseUrl: '基础 URL',dataSourceFieldAzureDevOpsOrganization: 'Azure DevOps 组织',dataSourceFieldAzureDevOpsRepositories: '仓库',dataSourceFieldAzureDevOpsContentTypes: '内容类型',diff --git a/web/src/pages/user-setting/data-source/constant/azure-devops-constant.tsx b/web/src/pages/user-setting/data-source/constant/azure-devops-constant.tsxindex b06465a175..0a5cddfd79 100644--- a/web/src/pages/user-setting/data-source/constant/azure-devops-constant.tsx+++ b/web/src/pages/user-setting/data-source/constant/azure-devops-constant.tsx@@ -25,11 +25,89 @@ export const azureDevOpsConstant = (t: TFunction) => [required: true,tooltip: t('setting.azureDevOpsPatTip'),},+ {+ label: t('setting.dataSourceFieldAzureDevOpsBaseUrl'),+ name: 'config.base_url',+ type: FormFieldType.Text,+ required: false,+ placeholder: 'https://dev.azure.com',+ tooltip: t('setting.azureDevOpsBaseUrlTip'),+ customValidate: (val: string) => {+ const trimmed = val?.trim();+ if (!trimmed) {+ return true;+ }+ if (!/^https?:\/\//i.test(trimmed)) {+ return t('setting.azureDevOpsBaseUrlTip');+ }+ try {+ const parsed = new URL(trimmed);+ if (!parsed.hostname || parsed.search || parsed.hash) {+ return t('setting.azureDevOpsBaseUrlTip');+ }+ if (parsed.username || parsed.password) {+ return t('setting.azureDevOpsPatTip');+ }+ } catch {+ return t('setting.azureDevOpsBaseUrlTip');+ }+ return true;+ },+ },{label: t('setting.dataSourceFieldAzureDevOpsOrganization'),name: 'config.organization',type: FormFieldType.Text,- required: true,+ required: false,+ customValidate: (val: string, formValues: any) => {+ const org = val?.trim();+ if (org) {+ if (/^https?:\/\//i.test(org)) {+ try {+ const parsed = new URL(org);+ if (!parsed.hostname || parsed.search || parsed.hash) {+ return t('setting.azureDevOpsOrganizationTip');+ }+ if (parsed.username || parsed.password) {+ return t('setting.azureDevOpsPatTip');+ }+ } catch {+ return t('setting.azureDevOpsOrganizationTip');+ }+ } else if (+ org.includes('?') ||+ org.includes('#') ||+ org.includes('://')+ ) {+ return t('setting.azureDevOpsOrganizationTip');+ }+ return true;+ }+ const baseUrl = formValues?.config?.base_url?.trim();+ if (!baseUrl) {+ return t('setting.dataSourceValidationFieldRequired', {+ label: t('setting.dataSourceFieldAzureDevOpsOrganization'),+ });+ }+ try {+ const parsed = new URL(baseUrl);+ const pathSegments = parsed.pathname.split('/').filter(Boolean);+ if (pathSegments.length === 0) {+ return t('setting.dataSourceValidationFieldRequired', {+ label: t('setting.dataSourceFieldAzureDevOpsOrganization'),+ });+ }+ } catch {+ const withoutScheme = baseUrl.replace(/^[a-zA-Z]+:\/\//, '');+ const segments = withoutScheme.split('/').slice(1).filter(Boolean);+ if (segments.length === 0) {+ return t('setting.dataSourceValidationFieldRequired', {+ label: t('setting.dataSourceFieldAzureDevOpsOrganization'),+ });+ }+ }+ return true;+ },tooltip: t('setting.azureDevOpsOrganizationTip'),},{diff --git a/web/src/pages/user-setting/data-source/constant/index.test.tsx b/web/src/pages/user-setting/data-source/constant/index.test.tsxindex 76f2ea3c10..dc0ff8ccf3 100644--- a/web/src/pages/user-setting/data-source/constant/index.test.tsx+++ b/web/src/pages/user-setting/data-source/constant/index.test.tsx@@ -119,3 +119,143 @@ describe('Sitemap data source', () => {expect(batchSize?.validation?.min).toBe(1);});});++describe('Azure DevOps data source', () => {+ it('registers its catalog entry and defaults', () => {+ const info = generateDataSourceInfo(translate)[DataSourceKey.AZURE_DEVOPS];+ const defaults = DataSourceFormDefaultValues[DataSourceKey.AZURE_DEVOPS];++ expect(info.name).toBe('Azure DevOps');+ expect(info.description).toBe('setting.azureDevOpsDescription');+ expect(defaults).toMatchObject({+ name: '',+ source: DataSourceKey.AZURE_DEVOPS,+ config: {+ base_url: '',+ organization: '',+ index_mode: 'organization',+ projects: '',+ repositories: '',+ content_types: 'both',+ credentials: { azure_devops_pat: '' },+ },+ });+ });++ it('validates organization requires collection path when empty', () => {+ const fields = getDataSourceFieldsWithExtras(+ translate,+ DataSourceKey.AZURE_DEVOPS,+ ) as Array<{+ name: string;+ customValidate?: (val: string, formValues?: any) => boolean | string;+ }>;+ const orgField = fields.find((f) => f.name === 'config.organization');+ expect(orgField).toBeDefined();+ const validate = orgField!.customValidate!;++ // Valid when organization is explicitly provided+ expect(validate('contoso', { config: { base_url: '' } })).toBe(true);+ expect(+ validate('contoso', { config: { base_url: 'https://dev.azure.com' } }),+ ).toBe(true);++ // Valid when base_url includes collection path+ expect(+ validate('', {+ config: {+ base_url: 'http://tfs.corp.local:8080/tfs/DefaultCollection',+ },+ }),+ ).toBe(true);+ expect(+ validate('', {+ config: { base_url: 'https://dev.azure.com/myorg' },+ }),+ ).toBe(true);++ // Invalid when both are empty+ expect(validate('', { config: { base_url: '' } })).toBe(+ 'setting.dataSourceValidationFieldRequired',+ );++ // Invalid when base_url is root-only+ expect(+ validate('', { config: { base_url: 'https://dev.azure.com' } }),+ ).toBe('setting.dataSourceValidationFieldRequired');+ expect(+ validate('', { config: { base_url: 'https://dev.azure.com/' } }),+ ).toBe('setting.dataSourceValidationFieldRequired');+ expect(+ validate('', { config: { base_url: 'http://tfs.corp.local:8080' } }),+ ).toBe('setting.dataSourceValidationFieldRequired');+ });++ it('validates base_url rejects hostless URLs and URLs with query or fragment', () => {+ const fields = getDataSourceFieldsWithExtras(+ translate,+ DataSourceKey.AZURE_DEVOPS,+ ) as Array<{+ name: string;+ customValidate?: (val: string, formValues?: any) => boolean | string;+ }>;+ const baseUrlField = fields.find((f) => f.name === 'config.base_url');+ expect(baseUrlField).toBeDefined();+ const validate = baseUrlField!.customValidate!;++ expect(validate('')).toBe(true);+ expect(validate('https://dev.azure.com')).toBe(true);+ expect(validate('http://tfs.corp.local:8080/tfs')).toBe(true);++ // Invalid scheme+ expect(validate('ftp://dev.azure.com')).toBe(+ 'setting.azureDevOpsBaseUrlTip',+ );++ // Hostless+ expect(validate('https:///DefaultCollection')).toBe(+ 'setting.azureDevOpsBaseUrlTip',+ );++ // Query or fragment+ expect(validate('https://dev.azure.com/myorg?test=1')).toBe(+ 'setting.azureDevOpsBaseUrlTip',+ );+ expect(validate('https://dev.azure.com/myorg#frag')).toBe(+ 'setting.azureDevOpsBaseUrlTip',+ );++ // Credentials+ expect(validate('https://user:[email protected]')).toBe(+ 'setting.azureDevOpsPatTip',+ );+ });++ it('validates organization rejects query, fragment, and hostless URLs', () => {+ const fields = getDataSourceFieldsWithExtras(+ translate,+ DataSourceKey.AZURE_DEVOPS,+ ) as Array<{+ name: string;+ customValidate?: (val: string, formValues?: any) => boolean | string;+ }>;+ const orgField = fields.find((f) => f.name === 'config.organization');+ expect(orgField).toBeDefined();+ const validate = orgField!.customValidate!;++ expect(validate('myorg?test=1', { config: { base_url: '' } })).toBe(+ 'setting.azureDevOpsOrganizationTip',+ );+ expect(validate('myorg#frag', { config: { base_url: '' } })).toBe(+ 'setting.azureDevOpsOrganizationTip',+ );+ expect(+ validate('https:///DefaultCollection', { config: { base_url: '' } }),+ ).toBe('setting.azureDevOpsOrganizationTip');+ expect(+ validate('https://user:[email protected]/myorg', {+ config: { base_url: '' },+ }),+ ).toBe('setting.azureDevOpsPatTip');+ });+});diff --git a/web/src/pages/user-setting/data-source/constant/index.tsx b/web/src/pages/user-setting/data-source/constant/index.tsxindex 138aa6e425..5aa394cb64 100644--- a/web/src/pages/user-setting/data-source/constant/index.tsx+++ b/web/src/pages/user-setting/data-source/constant/index.tsx@@ -2443,6 +2443,7 @@ export const DataSourceFormDefaultValues = {name: '',source: DataSourceKey.AZURE_DEVOPS,config: {+ base_url: '',organization: '',index_mode: 'organization',projects: '',