From bf7fe405cd923ea58e7a267eccbf2ee329ac077b Mon Sep 17 00:00:00 2001 From: Arnaud Boussaer Date: Fri, 22 Mar 2024 12:22:40 +0100 Subject: [PATCH] #551 Allows user passwords with accolade --- .../CodeGenerator.cs | 8 ++++++++ .../CodeGeneratorTests.cs | 16 ++++++++++++++-- ...ityFrameworkCore.Generator.Core.Tests.csproj | 3 ++- .../Scripts/Script003.Tracker.User.sql | 17 +++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 test/EntityFrameworkCore.Generator.Core.Tests/Scripts/Script003.Tracker.User.sql diff --git a/src/EntityFrameworkCore.Generator.Core/CodeGenerator.cs b/src/EntityFrameworkCore.Generator.Core/CodeGenerator.cs index 2d520e7d..682482bd 100644 --- a/src/EntityFrameworkCore.Generator.Core/CodeGenerator.cs +++ b/src/EntityFrameworkCore.Generator.Core/CodeGenerator.cs @@ -365,7 +365,15 @@ private DatabaseModel GetDatabaseModel(IDatabaseModelFactory factory) _logger.LogInformation("Loading database model ..."); var database = Options.Database; + + //do not evaluate connection string resolving (cfr. { or } in password => crash) + var shouldEvaluate = Options.Variables.ShouldEvaluate; + Options.Variables.ShouldEvaluate = false; + var connectionString = ResolveConnectionString(database); + + Options.Variables.ShouldEvaluate = shouldEvaluate; + var options = new DatabaseModelFactoryOptions(database.Tables, database.Schemas); return factory.Create(connectionString, options); diff --git a/test/EntityFrameworkCore.Generator.Core.Tests/CodeGeneratorTests.cs b/test/EntityFrameworkCore.Generator.Core.Tests/CodeGeneratorTests.cs index 74e1a4db..c87b0dcf 100644 --- a/test/EntityFrameworkCore.Generator.Core.Tests/CodeGeneratorTests.cs +++ b/test/EntityFrameworkCore.Generator.Core.Tests/CodeGeneratorTests.cs @@ -1,4 +1,4 @@ -using EntityFrameworkCore.Generator.Options; +using EntityFrameworkCore.Generator.Options; using FluentAssertions; using FluentCommand.SqlServer.Tests; using Microsoft.Extensions.Logging.Abstractions; @@ -26,4 +26,16 @@ public void Generate() result.Should().BeTrue(); } -} \ No newline at end of file + [Fact] + public void Generate_Should_Work_For_Password_With_CurlyBrace() + { + var generatorOptions = new GeneratorOptions(); + generatorOptions.Database.ConnectionString = Database.ConnectionString + .Replace("Integrated Security=True", @"User ID=testuser;Password=rglna{adQP123456");//This is the user specified in Script003.Tracker.User.sql + + var generator = new CodeGenerator(NullLoggerFactory.Instance); + var result = generator.Generate(generatorOptions); + + result.Should().BeTrue(); + } +} diff --git a/test/EntityFrameworkCore.Generator.Core.Tests/EntityFrameworkCore.Generator.Core.Tests.csproj b/test/EntityFrameworkCore.Generator.Core.Tests/EntityFrameworkCore.Generator.Core.Tests.csproj index 24ed62cc..26f0ac9c 100644 --- a/test/EntityFrameworkCore.Generator.Core.Tests/EntityFrameworkCore.Generator.Core.Tests.csproj +++ b/test/EntityFrameworkCore.Generator.Core.Tests/EntityFrameworkCore.Generator.Core.Tests.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -10,6 +10,7 @@ + diff --git a/test/EntityFrameworkCore.Generator.Core.Tests/Scripts/Script003.Tracker.User.sql b/test/EntityFrameworkCore.Generator.Core.Tests/Scripts/Script003.Tracker.User.sql new file mode 100644 index 00000000..1266f16a --- /dev/null +++ b/test/EntityFrameworkCore.Generator.Core.Tests/Scripts/Script003.Tracker.User.sql @@ -0,0 +1,17 @@ +IF NOT EXISTS + (SELECT name + FROM master.sys.sql_logins + WHERE name = 'testuser') +BEGIN + CREATE LOGIN [testuser] WITH PASSWORD = N'rglna{adQP123456'; +END +-- check our db +IF NOT EXISTS + (SELECT name + FROM sys.database_principals + WHERE name = 'testuser') +BEGIN + CREATE USER [testuser] FOR LOGIN [testuser] WITH DEFAULT_SCHEMA = dbo +END +exec sp_addrolemember db_datareader, 'testuser' +exec sp_addrolemember db_datawriter, 'testuser'