Skip to content

Fixes the bug #1680 that necessitated adding the 'name' parameter to the @model directive, regardless of the name of the GraphQL object type's name #1713

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

Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion schemas/dab.draft.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
"mode": {
"description": "Set if running in Development or Production mode",
"type": "string",
"default": "production",
"default": "development",
"enum": [
"production",
"development"
Expand Down
73 changes: 73 additions & 0 deletions src/Cli.Tests/ConfigGeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text;

namespace Cli.Tests;

/// <summary>
Expand Down Expand Up @@ -119,6 +121,77 @@ public void TryGenerateConfig_UsingEnvironmentVariable(
}
}

/// <summary>
/// Test to verify creation of initial config with special characters
/// such as [!,@,#,$,%,^,&,*, ,(,)] in connection-string or graphql api
/// </summary>
[TestMethod]
public void TestSpecialCharactersInConnectionString()
{
HandleConfigFileCreationAndDeletion(TEST_RUNTIME_CONFIG_FILE, configFilePresent: false);
InitOptions options = new(
databaseType: DatabaseType.MSSQL,
connectionString: "A!string@with#some$special%characters^to&check*proper(serialization).'",
cosmosNoSqlDatabase: null,
cosmosNoSqlContainer: null,
graphQLSchemaPath: null,
graphQLPath: "/An_",
setSessionContext: false,
hostMode: HostMode.Production,
corsOrigin: null,
authenticationProvider: EasyAuthType.StaticWebApps.ToString(),
config: TEST_RUNTIME_CONFIG_FILE);

StringBuilder expectedRuntimeConfigJson = new(
@"{" +
@"""$schema"": """ + DAB_DRAFT_SCHEMA_TEST_PATH + @"""" + "," +
@"""data-source"": {
""database-type"": ""mssql"",
""connection-string"": ""A!string@with#some$special%characters^to&check*proper(serialization).'"",
""options"":{
""set-session-context"": false
}
},
""runtime"": {
""rest"": {
""enabled"": true,
""path"": ""/api""
},
""graphql"": {
""enabled"": true,
""path"": ""/An_"",
""allow-introspection"": true
},
""host"": {
""cors"": {
""origins"": [],
""allow-credentials"": false
},
""authentication"": {
""provider"": ""StaticWebApps""
},
""mode"": ""production""
}
},
""entities"": {}
}");

expectedRuntimeConfigJson = expectedRuntimeConfigJson.Replace(" ", string.Empty);
expectedRuntimeConfigJson = expectedRuntimeConfigJson.Replace("\n", string.Empty);
expectedRuntimeConfigJson = expectedRuntimeConfigJson.Replace("\r\n", string.Empty);

Assert.IsTrue(TryGenerateConfig(options, _runtimeConfigLoader!, _fileSystem!));

StringBuilder actualRuntimeConfigJson = new(_fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE, Encoding.Default));
actualRuntimeConfigJson = actualRuntimeConfigJson.Replace(" ", string.Empty);
actualRuntimeConfigJson = actualRuntimeConfigJson.Replace("\r\n", string.Empty);
actualRuntimeConfigJson = actualRuntimeConfigJson.Replace("\n", string.Empty);

// Comparing explicit strings here since parsing these into JSON would lose
// the test scenario of verifying escaped chars are not written to the file system.
Assert.AreEqual(expectedRuntimeConfigJson.ToString(), actualRuntimeConfigJson.ToString());
}

/// <summary>
/// This method handles the creation and deletion of a configuration file.
/// </summary>
Expand Down
16 changes: 12 additions & 4 deletions src/Cli.Tests/EndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public void TestInitialize()
_cliLogger = loggerFactory.CreateLogger<Program>();
SetLoggerForCliConfigGenerator(loggerFactory.CreateLogger<ConfigGenerator>());
SetCliUtilsLogger(loggerFactory.CreateLogger<Utils>());

Environment.SetEnvironmentVariable($"connection-string", TEST_CONNECTION_STRING);
}

[TestCleanup]
Expand All @@ -50,7 +52,7 @@ public void TestCleanup()
public Task TestInitForCosmosDBNoSql()
{
string[] args = { "init", "-c", TEST_RUNTIME_CONFIG_FILE, "--database-type", "cosmosdb_nosql",
"--connection-string", "localhost:5000", "--cosmosdb_nosql-database",
"--connection-string", TEST_ENV_CONN_STRING, "--cosmosdb_nosql-database",
"graphqldb", "--cosmosdb_nosql-container", "planet", "--graphql-schema", TEST_SCHEMA_FILE, "--cors-origin", "localhost:3000,www.nolocalhost.com:80" };
Program.Execute(args, _cliLogger!, _fileSystem!, _runtimeConfigLoader!);

Expand Down Expand Up @@ -107,7 +109,10 @@ public void TestInitializingRestAndGraphQLGlobalSettings()
string[] args = { "init", "-c", TEST_RUNTIME_CONFIG_FILE, "--database-type", "mssql", "--rest.path", "/rest-api", "--rest.disabled", "--graphql.path", "/graphql-api" };
Program.Execute(args, _cliLogger!, _fileSystem!, _runtimeConfigLoader!);

Assert.IsTrue(_runtimeConfigLoader!.TryLoadConfig(TEST_RUNTIME_CONFIG_FILE, out RuntimeConfig? runtimeConfig));
Assert.IsTrue(_runtimeConfigLoader!.TryLoadConfig(
TEST_RUNTIME_CONFIG_FILE,
out RuntimeConfig? runtimeConfig,
replaceEnvVar: true));

Assert.IsNotNull(runtimeConfig);
Assert.AreEqual(DatabaseType.MSSQL, runtimeConfig.DataSource.DatabaseType);
Expand All @@ -124,7 +129,8 @@ public void TestInitializingRestAndGraphQLGlobalSettings()
[TestMethod]
public void TestAddEntity()
{
string[] initArgs = { "init", "-c", TEST_RUNTIME_CONFIG_FILE, "--host-mode", "development", "--database-type", "mssql", "--connection-string", "localhost:5000", "--auth.provider", "StaticWebApps" };
string[] initArgs = { "init", "-c", TEST_RUNTIME_CONFIG_FILE, "--host-mode", "development", "--database-type",
"mssql", "--connection-string", TEST_ENV_CONN_STRING, "--auth.provider", "StaticWebApps" };
Program.Execute(initArgs, _cliLogger!, _fileSystem!, _runtimeConfigLoader!);

Assert.IsTrue(_runtimeConfigLoader!.TryLoadConfig(TEST_RUNTIME_CONFIG_FILE, out RuntimeConfig? runtimeConfig));
Expand All @@ -140,6 +146,7 @@ public void TestAddEntity()

Assert.IsTrue(_runtimeConfigLoader!.TryLoadConfig(TEST_RUNTIME_CONFIG_FILE, out RuntimeConfig? addRuntimeConfig));
Assert.IsNotNull(addRuntimeConfig);
Assert.AreEqual(TEST_ENV_CONN_STRING, addRuntimeConfig.DataSource.ConnectionString);
Assert.AreEqual(1, addRuntimeConfig.Entities.Count()); // 1 new entity added
Assert.IsTrue(addRuntimeConfig.Entities.ContainsKey("todo"));
Entity entity = addRuntimeConfig.Entities["todo"];
Expand Down Expand Up @@ -374,7 +381,7 @@ public Task TestConfigGeneratedAfterAddingEntityWithSourceWithDefaultType()
public void TestUpdateEntity()
{
string[] initArgs = { "init", "-c", TEST_RUNTIME_CONFIG_FILE, "--database-type",
"mssql", "--connection-string", "localhost:5000" };
"mssql", "--connection-string", TEST_ENV_CONN_STRING };
Program.Execute(initArgs, _cliLogger!, _fileSystem!, _runtimeConfigLoader!);

Assert.IsTrue(_runtimeConfigLoader!.TryLoadConfig(TEST_RUNTIME_CONFIG_FILE, out RuntimeConfig? runtimeConfig));
Expand Down Expand Up @@ -416,6 +423,7 @@ public void TestUpdateEntity()

Assert.IsTrue(_runtimeConfigLoader!.TryLoadConfig(TEST_RUNTIME_CONFIG_FILE, out RuntimeConfig? updateRuntimeConfig));
Assert.IsNotNull(updateRuntimeConfig);
Assert.AreEqual(TEST_ENV_CONN_STRING, updateRuntimeConfig.DataSource.ConnectionString);
Assert.AreEqual(2, updateRuntimeConfig.Entities.Count()); // No new entity added

Assert.IsTrue(updateRuntimeConfig.Entities.ContainsKey("todo"));
Expand Down
16 changes: 10 additions & 6 deletions src/Cli.Tests/EnvironmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public void TestSystemEnvironmentVariableIsUsedInAbsenceOfEnvironmentFile()
[TestMethod]
public void TestStartWithEnvFileIsSuccessful()
{
BootstrapTestEnvironment("CONN_STRING=test_connection_string");
string expectedEnvVarName = "CONN_STRING";
BootstrapTestEnvironment(expectedEnvVarName + "=test_connection_string", expectedEnvVarName);

// Trying to start the runtime engine
using Process process = ExecuteDabCommand(
Expand All @@ -148,10 +149,11 @@ public void TestStartWithEnvFileIsSuccessful()
/// I feel confident that the overarching scenario is covered through other testing
/// so disabling temporarily while we investigate should be acceptable.
/// </summary>
[TestMethod, Ignore]
[TestMethod]
public async Task FailureToStartEngineWhenEnvVarNamedWrong()
{
BootstrapTestEnvironment("COMM_STRINX=test_connection_string");
string expectedEnvVarName = "WRONG_CONN_STRING";
BootstrapTestEnvironment("COMM_STRINX=test_connection_string", expectedEnvVarName);

// Trying to start the runtime engine
using Process process = ExecuteDabCommand(
Expand All @@ -160,11 +162,12 @@ public async Task FailureToStartEngineWhenEnvVarNamedWrong()
);

string? output = await process.StandardError.ReadLineAsync();
StringAssert.Contains(output, "Environmental Variable, CONN_STRING, not found.", StringComparison.Ordinal);
StringAssert.Contains(output, "Environmental Variable, "
+ expectedEnvVarName + ", not found.", StringComparison.Ordinal);
process.Kill();
}

private static void BootstrapTestEnvironment(string envFileContents)
private static void BootstrapTestEnvironment(string envFileContents, string connStringEnvName)
{
// Creating environment variable file
File.Create(".env").Close();
Expand All @@ -174,7 +177,8 @@ private static void BootstrapTestEnvironment(string envFileContents)
File.Delete(TEST_RUNTIME_CONFIG_FILE);
}

string[] initArgs = { "init", "-c", TEST_RUNTIME_CONFIG_FILE, "--database-type", "mssql", "--connection-string", "@env('CONN_STRING')" };
string[] initArgs = { "init", "-c", TEST_RUNTIME_CONFIG_FILE, "--database-type", "mssql",
"--connection-string", "@env('" + connStringEnvName + "')" };
Program.Main(initArgs);
}

Expand Down
22 changes: 0 additions & 22 deletions src/Cli.Tests/InitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,28 +223,6 @@ public void EnsureFailureWhenBothRestAndGraphQLAreDisabled(
Assert.AreEqual(expectedResult, TryCreateRuntimeConfig(options, _runtimeConfigLoader!, _fileSystem!, out RuntimeConfig? _));
}

/// <summary>
/// Test to verify creation of initial config with special characters
/// such as [!,@,#,$,%,^,&,*, ,(,)] in connection-string.
/// </summary>
[TestMethod]
public Task TestSpecialCharactersInConnectionString()
{
InitOptions options = new(
databaseType: DatabaseType.MSSQL,
connectionString: "A!string@with#some$special%characters^to&check*proper(serialization)including space.",
cosmosNoSqlDatabase: null,
cosmosNoSqlContainer: null,
graphQLSchemaPath: null,
setSessionContext: false,
hostMode: HostMode.Production,
corsOrigin: null,
authenticationProvider: EasyAuthType.StaticWebApps.ToString(),
config: TEST_RUNTIME_CONFIG_FILE);

return ExecuteVerifyTest(options);
}

/// <summary>
/// Test to verify that an error is thrown when user tries to
/// initialize a config with a file name that already exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@
Enabled: true
},
Rest: {
Methods: [
Get,
Post,
Put,
Patch,
Delete
],
Enabled: true
},
Permissions: [
Expand Down Expand Up @@ -70,13 +63,6 @@
Enabled: true
},
Rest: {
Methods: [
Get,
Post,
Put,
Patch,
Delete
],
Enabled: true
},
Permissions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@
Enabled: true
},
Rest: {
Methods: [
Get,
Post,
Put,
Patch,
Delete
],
Enabled: true
},
Permissions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@
Enabled: true
},
Rest: {
Methods: [
Get,
Post,
Put,
Patch,
Delete
],
Enabled: true
},
Permissions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@
Enabled: true
},
Rest: {
Methods: [
Get,
Post,
Put,
Patch,
Delete
],
Enabled: true
},
Permissions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@
Enabled: true
},
Rest: {
Methods: [
Get,
Post,
Put,
Patch,
Delete
],
Enabled: true
},
Permissions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@
Enabled: true
},
Rest: {
Methods: [
Get,
Post,
Put,
Patch,
Delete
],
Enabled: true
},
Permissions: [
Expand Down Expand Up @@ -70,13 +63,6 @@
Enabled: true
},
Rest: {
Methods: [
Get,
Post,
Put,
Patch,
Delete
],
Enabled: true
},
Permissions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@
Enabled: true
},
Rest: {
Methods: [
Get,
Post,
Put,
Patch,
Delete
],
Enabled: true
},
Permissions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@
Enabled: true
},
Rest: {
Methods: [
Get,
Post,
Put,
Patch,
Delete
],
Enabled: true
},
Permissions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@
},
Rest: {
Methods: [
Get,
Post,
Put,
Patch,
Delete
Post
],
Enabled: true
},
Expand Down
Loading