Skip to content

Commit

Permalink
#551 Allows user passwords with accolade
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Boussaer authored and Arnaud Boussaer committed Mar 22, 2024
1 parent ceaa6a5 commit bf7fe40
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/EntityFrameworkCore.Generator.Core/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using EntityFrameworkCore.Generator.Options;
using EntityFrameworkCore.Generator.Options;
using FluentAssertions;
using FluentCommand.SqlServer.Tests;
using Microsoft.Extensions.Logging.Abstractions;
Expand Down Expand Up @@ -26,4 +26,16 @@ public void Generate()
result.Should().BeTrue();
}

}
[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();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

Expand All @@ -10,6 +10,7 @@
<None Remove="Options\full.yaml" />
<None Remove="Scripts\Script001.Tracker.Schema.sql" />
<None Remove="Scripts\Script002.Tracker.Data.sql" />
<None Remove="Scripts\Script003.Tracker.User.sql" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit bf7fe40

Please sign in to comment.