Skip to content

Add comprehensive validation for DTS connection strings including empty Authentication values #4624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,44 @@ export class DTSConnectionCustomPromptStep<T extends IDTSConnectionWizardContext
return !context.newDTSConnectionSetting && context.dtsConnectionType === ConnectionType.Custom;
}

private validateInput(name: string | undefined): string | undefined {
name = name ? name.trim() : '';
if (!validationUtils.hasValidCharLength(name)) {
private validateInput(connectionString: string | undefined): string | undefined {
connectionString = connectionString ? connectionString.trim() : '';

// Check for basic character length validation
if (!validationUtils.hasValidCharLength(connectionString)) {
return validationUtils.getInvalidCharLengthMessage();
}

// Check if the connection string contains the required "Endpoint=" pattern
const endpointMatch = connectionString.match(/Endpoint=([^;]+)/);
if (!endpointMatch) {
return localize('invalidDTSConnectionStringFormat', 'DTS connection string must contain an "Endpoint=" parameter. Expected format: "Endpoint=<URL>;Authentication=<AuthType>"');
}

// Validate that the endpoint URL is properly formatted
const endpoint = endpointMatch[1];
try {
const url = new URL(endpoint);
// Ensure it's using a valid protocol
if (!['http:', 'https:'].includes(url.protocol)) {
return localize('invalidDTSEndpointProtocol', 'DTS endpoint must use HTTP or HTTPS protocol. Found: {0}', url.protocol);
}
} catch (error) {
return localize('invalidDTSEndpointURL', 'DTS endpoint is not a valid URL: {0}', endpoint);
}

// Check if the connection string contains an Authentication parameter with a non-empty value
const authMatch = connectionString.match(/Authentication=([^;]*)/);
if (!authMatch) {
return localize('missingDTSAuthentication', 'DTS connection string must contain an "Authentication=" parameter. Expected format: "Endpoint=<URL>;Authentication=<AuthType>"');
}

// Validate that the Authentication parameter has a non-empty value
const authValue = authMatch[1];
if (!authValue || authValue.trim() === '') {
return localize('emptyDTSAuthentication', 'DTS Authentication parameter cannot be empty. Expected format: "Endpoint=<URL>;Authentication=<AuthType>"');
}

return undefined;
}
}