mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-24 09:35:39 -05:00
Added error message to validate connect params. (#1660)
* Added error message to validate connect params. * removed connectionParam == null as ConnnectionCompleteParams cannot be nulled. * Added ValidateConnectParams to other connection services * removed message from error * reverted change to connectionServiceCore * added updated message * restore null and added errormessage to GetConnectionCompleteParams * fix for sr.xlf * fix for tab * another fix to tabs * added message to connection complete error * small fix
This commit is contained in:
@@ -139,7 +139,7 @@ namespace Microsoft.Kusto.ServiceLayer.Connection
|
||||
return new ConnectionCompleteParams
|
||||
{
|
||||
OwnerUri = connectionParams.OwnerUri,
|
||||
Messages = paramValidationErrorMessage
|
||||
ErrorMessage = paramValidationErrorMessage,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -371,6 +371,7 @@ namespace Microsoft.Kusto.ServiceLayer.Connection
|
||||
catch (Exception ex)
|
||||
{
|
||||
response.Messages = ex.ToString();
|
||||
response.ErrorMessage = ex.Message;
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
@@ -319,20 +319,19 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
/// null upon validation success</returns>
|
||||
public ConnectionCompleteParams ValidateConnectParams(ConnectParams connectionParams)
|
||||
{
|
||||
string paramValidationErrorMessage;
|
||||
if (connectionParams == null)
|
||||
{
|
||||
return new ConnectionCompleteParams
|
||||
{
|
||||
Messages = SR.ConnectionServiceConnectErrorNullParams
|
||||
ErrorMessage = SR.ConnectionServiceConnectErrorNullParams
|
||||
};
|
||||
}
|
||||
if (!connectionParams.IsValid(out paramValidationErrorMessage))
|
||||
if (!connectionParams.IsValid(out string paramValidationErrorMessage))
|
||||
{
|
||||
return new ConnectionCompleteParams
|
||||
{
|
||||
OwnerUri = connectionParams.OwnerUri,
|
||||
Messages = paramValidationErrorMessage
|
||||
ErrorMessage = paramValidationErrorMessage
|
||||
};
|
||||
}
|
||||
|
||||
@@ -569,6 +568,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
catch (Exception ex)
|
||||
{
|
||||
response.Messages = ex.ToString();
|
||||
response.ErrorMessage = ex.Message;
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
@@ -247,6 +247,27 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
Assert.False(disconnectResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that we cannot connect to the default database when no username
|
||||
/// is provided and the authentication type is basic auth.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task CantConnectWithoutUsername()
|
||||
{
|
||||
// Connect
|
||||
var connectionDetails = TestObjects.GetTestConnectionDetails();
|
||||
connectionDetails.UserName = "";
|
||||
var connectionResult = await
|
||||
TestObjects.GetTestConnectionService()
|
||||
.Connect(new ConnectParams()
|
||||
{
|
||||
OwnerUri = "file:///my/test/file.sql",
|
||||
Connection = connectionDetails
|
||||
});
|
||||
|
||||
Assert.That(connectionResult.ErrorMessage, Is.EqualTo(SR.ConnectionParamsValidateNullSqlAuth("UserName")));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that we can connect to the default database when no database name is
|
||||
/// provided as a parameter.
|
||||
@@ -402,7 +423,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
Connection = invalidConnectionDetails
|
||||
});
|
||||
|
||||
Assert.That(connectionResult.Messages, Is.Not.Null.Or.Empty, "check that an error was caught");
|
||||
Assert.That(connectionResult.ErrorMessage, Is.Not.Null.Or.Empty, "check that an error was caught");
|
||||
}
|
||||
|
||||
static readonly object[] invalidParameters =
|
||||
@@ -419,7 +440,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
new object[] {"Integrated", "file://my/sample/file.sql", null, "test", "sa", "123456"},
|
||||
new object[] {"Integrated", "", "my-server", "test", "sa", "123456"},
|
||||
new object[] {"Integrated", "file://my/sample/file.sql", "", "test", "sa", "123456"}
|
||||
};
|
||||
};
|
||||
/// <summary>
|
||||
/// Verify that when connecting with invalid parameters, an error is thrown.
|
||||
/// </summary>
|
||||
@@ -442,7 +463,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
}
|
||||
});
|
||||
|
||||
Assert.That(connectionResult.Messages, Is.Not.Null.Or.Empty, "check that an error was caught");
|
||||
Assert.That(connectionResult.ErrorMessage, Is.Not.Null.Or.Empty, "check that an error was caught");
|
||||
}
|
||||
|
||||
static readonly object[] noUserNameOrPassword =
|
||||
@@ -492,7 +513,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
TestObjects.GetTestConnectionService()
|
||||
.Connect(null);
|
||||
|
||||
Assert.That(connectionResult.Messages, Is.Not.Null.Or.Empty, "check that an error was caught");
|
||||
Assert.That(connectionResult.ErrorMessage, Is.Not.Null.Or.Empty, "check that an error was caught");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user