diff --git a/.gitignore b/.gitignore index fb843f96..a94475e3 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,15 @@ data/ appsettings.*.json appsettings-*.*.json +# Exception: the Testing-environment override for Yavsc.Org is a tracked +# configuration source, not a secrets file. TestWebApplicationFactory +# (Yavsc.Org.Tests) flips ASPNETCORE_ENVIRONMENT to "Testing" so +# AddConfiguration("org") in Program.Main loads this file as the +# last in the chain (it is optional). It overrides the connection +# string and SMTP section for the in-memory test host and contains +# no production secrets. +!src/Yavsc.Org/appsettings-org.Testing.json + generated/ *.tmp DataDir/ diff --git a/src/Yavsc.Org.Tests/TestWebApplicationFactory.cs b/src/Yavsc.Org.Tests/TestWebApplicationFactory.cs index c51f3f8e..dfd6edea 100644 --- a/src/Yavsc.Org.Tests/TestWebApplicationFactory.cs +++ b/src/Yavsc.Org.Tests/TestWebApplicationFactory.cs @@ -26,10 +26,15 @@ public class TestWebApplicationFactory : WebApplicationFactory { protected override void ConfigureWebHost(IWebHostBuilder builder) { - // UseDevelopmentEnvironment triggers the dev signing credential - // path in the production startup, so we don't need a real cert - // to satisfy IdentityServer at boot. - builder.UseEnvironment("Development"); + // UseEnvironment("Testing") puts the host in a dedicated + // configuration environment so AddConfiguration("org") in + // Program.Main loads the optional appsettings-org.Testing.json + // file (which overrides the connection string and SMTP section + // for the test host). See that file for the values. + // We don't use "Development" because that environment is also + // used by the dev launcher and would change the signing + // credential path in IdentityServer; "Testing" is unambiguous. + builder.UseEnvironment("Testing"); builder.ConfigureTestServices(services => { diff --git a/src/Yavsc.Org/appsettings-org.Testing.json b/src/Yavsc.Org/appsettings-org.Testing.json new file mode 100644 index 00000000..c640ffcd --- /dev/null +++ b/src/Yavsc.Org/appsettings-org.Testing.json @@ -0,0 +1,11 @@ +{ + "ConnectionStrings": { + "YavscConnection": "InMemory" + }, + "Smtp": { + "Host": "smtp.test.local", + "Port": 465, + "UserName": "test-user", + "Password": "test-pass" + } +}