Skip to content

Commit

Permalink
Merge pull request #552 from ArnaudB88/bug/551-Connectionstring
Browse files Browse the repository at this point in the history
Fixes #551 Allows user passwords with accolade
  • Loading branch information
pwelter34 authored Mar 22, 2024
2 parents 23af8b9 + 1b981f6 commit 0e558a5
Show file tree
Hide file tree
Showing 4 changed files with 43 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 @@ -27,6 +27,19 @@ 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();
}
[Fact]
public void GenerateSpatial()
{
Expand Down Expand Up @@ -61,4 +74,5 @@ public void GenerateSpatial()

}

}
}

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 0e558a5

Please sign in to comment.