Skip to content

Commit

Permalink
fix(solr): updated solr config to allow filtering by external links
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherpickering committed Sep 14, 2023
1 parent 27782c3 commit 2569664
Show file tree
Hide file tree
Showing 311 changed files with 2,785 additions and 2,664 deletions.
107 changes: 55 additions & 52 deletions web.Tests/BrowserTests/Utilities/BrowserFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

namespace web.Tests.BrowserTests
{
public class BrowserFactory<TEntryPoint> : IDisposable
where TEntryPoint : Program
public class BrowserFactory<TEntryPoint> : IDisposable where TEntryPoint : Program
{
private readonly IHost _host;

Expand All @@ -23,73 +22,77 @@ public class BrowserFactory<TEntryPoint> : IDisposable
public BrowserFactory()
{
IHostBuilder builder = Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<TEntryPoint>();
// needs to be relative to actual project root
// so static resources are picked up.
// basically we are changing from /web.Tests to /web.
webBuilder.UseSolutionRelativeContentRoot("web");
webBuilder.UseUrls("http://127.0.0.1:0");
})
.ConfigureServices(services =>
{
var descriptor = services.SingleOrDefault(
d => d.ServiceType == typeof(DbContextOptions<Atlas_WebContext>)
);
if (descriptor != null)
.ConfigureWebHostDefaults(
webBuilder =>
{
services.Remove(descriptor);
}
webBuilder.UseStartup<TEntryPoint>();
services.AddDbContext<Atlas_WebContext>(options =>
// needs to be relative to actual project root
// so static resources are picked up.
// basically we are changing from /web.Tests to /web.
webBuilder.UseSolutionRelativeContentRoot("web");
webBuilder.UseUrls("http://127.0.0.1:0");
}
)
.ConfigureServices(
services =>
{
options.UseInMemoryDatabase("LiveServerTests");
});
var descriptor = services.SingleOrDefault(
d => d.ServiceType == typeof(DbContextOptions<Atlas_WebContext>)
);
var sp = services.BuildServiceProvider();
if (descriptor != null)
{
services.Remove(descriptor);
}
using (var scope = sp.CreateScope())
{
var scopedServices = scope.ServiceProvider;
var db = scopedServices.GetRequiredService<Atlas_WebContext>();
var logger = scopedServices.GetRequiredService<
ILogger<BrowserFactory<TEntryPoint>>
>();
services.AddDbContext<Atlas_WebContext>(
options =>
{
options.UseInMemoryDatabase("LiveServerTests");
}
);
db.Database.EnsureDeleted();
db.Database.EnsureCreated();
var sp = services.BuildServiceProvider();
try
{
// test data is loaded here.
Utilities.InitializeDbForTests(db);
logger.LogWarning("Test database initialized");
}
catch (Exception ex)
using (var scope = sp.CreateScope())
{
logger.LogError(
ex,
"An error occurred seeding the "
+ "database with test messages. Error: {Message}",
ex.Message
);
var scopedServices = scope.ServiceProvider;
var db = scopedServices.GetRequiredService<Atlas_WebContext>();
var logger = scopedServices.GetRequiredService<
ILogger<BrowserFactory<TEntryPoint>>
>();
db.Database.EnsureDeleted();
db.Database.EnsureCreated();
try
{
// test data is loaded here.
Utilities.InitializeDbForTests(db);
logger.LogWarning("Test database initialized");
}
catch (Exception ex)
{
logger.LogError(
ex,
"An error occurred seeding the "
+ "database with test messages. Error: {Message}",
ex.Message
);
}
}
}
});
);

// Start the host in the background.
// Shut it down in the Dispose method below.
_host = builder.Build();
_host.Start();

// Store base address so that tests can pass it to the browser.
var address = _host
?.Services?.GetRequiredService<IServer>()
?.Features.Get<IServerAddressesFeature>()
?.Addresses.First();
var address =
_host?.Services?.GetRequiredService<IServer>()?.Features.Get<IServerAddressesFeature>()?.Addresses.First();

if (address != null)
{
Expand Down
42 changes: 28 additions & 14 deletions web.Tests/BrowserTests/Utilities/BrowserFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public DriverOptions BuildBrowser()
OpenQA.Selenium.Safari.SafariOptions safariCapability =
new OpenQA.Selenium.Safari.SafariOptions();
safariCapability.BrowserVersion = Options.BrowserVersion;
Dictionary<string, object> browserstackSafariOptions =
new Dictionary<string, object>();
Dictionary<string, object> browserstackSafariOptions = new Dictionary<
string,
object
>();
browserstackSafariOptions.Add("osVersion", Options.OperatingSystemVersion);
browserstackSafariOptions.Add("os", Options.OperatingSystem);
browserstackSafariOptions.Add("projectName", Options.ProjectName);
Expand All @@ -46,8 +48,10 @@ public DriverOptions BuildBrowser()
OpenQA.Selenium.Chrome.ChromeOptions chromeCapability =
new OpenQA.Selenium.Chrome.ChromeOptions();
chromeCapability.BrowserVersion = Options.BrowserVersion;
Dictionary<string, object> browserstackChromeOptions =
new Dictionary<string, object>();
Dictionary<string, object> browserstackChromeOptions = new Dictionary<
string,
object
>();
browserstackChromeOptions.Add("os", Options.OperatingSystem);
browserstackChromeOptions.Add("osVersion", Options.OperatingSystemVersion);
browserstackChromeOptions.Add("local", "true");
Expand All @@ -67,8 +71,10 @@ public DriverOptions BuildBrowser()
OpenQA.Selenium.Firefox.FirefoxOptions firefoxCapability =
new OpenQA.Selenium.Firefox.FirefoxOptions();
firefoxCapability.BrowserVersion = Options.BrowserVersion;
Dictionary<string, object> browserstackFirefoxOptions =
new Dictionary<string, object>();
Dictionary<string, object> browserstackFirefoxOptions = new Dictionary<
string,
object
>();
browserstackFirefoxOptions.Add("osVersion", Options.OperatingSystemVersion);
browserstackFirefoxOptions.Add("os", Options.OperatingSystem);
browserstackFirefoxOptions.Add("projectName", Options.ProjectName);
Expand All @@ -91,8 +97,10 @@ public DriverOptions BuildBrowser()
OpenQA.Selenium.Edge.EdgeOptions edgeCapability =
new OpenQA.Selenium.Edge.EdgeOptions();
edgeCapability.BrowserVersion = Options.BrowserVersion;
Dictionary<string, object> browserstackEdgeOptions =
new Dictionary<string, object>();
Dictionary<string, object> browserstackEdgeOptions = new Dictionary<
string,
object
>();
browserstackEdgeOptions.Add("osVersion", Options.OperatingSystemVersion);
browserstackEdgeOptions.Add("os", Options.OperatingSystem);
browserstackEdgeOptions.Add("projectName", Options.ProjectName);
Expand Down Expand Up @@ -131,8 +139,10 @@ public DriverOptions BuildBrowser()
case "ios":
OpenQA.Selenium.Safari.SafariOptions iosCapability =
new OpenQA.Selenium.Safari.SafariOptions();
Dictionary<string, object> browserstackIosOptions =
new Dictionary<string, object>();
Dictionary<string, object> browserstackIosOptions = new Dictionary<
string,
object
>();

// for example, iPhone 12
browserstackIosOptions.Add("deviceName", Options.OperatingSystem);
Expand All @@ -154,8 +164,10 @@ public DriverOptions BuildBrowser()
OpenQA.Selenium.Chrome.ChromeOptions androidCapability =
new OpenQA.Selenium.Chrome.ChromeOptions();

Dictionary<string, object> browserstackAndroidOptions =
new Dictionary<string, object>();
Dictionary<string, object> browserstackAndroidOptions = new Dictionary<
string,
object
>();

// for example, Samsung Galaxy Tab S5e
browserstackAndroidOptions.Add("deviceName", Options.OperatingSystem);
Expand Down Expand Up @@ -185,8 +197,10 @@ public DriverOptions BuildBrowser()
OpenQA.Selenium.Chrome.ChromeOptions chromeCapabilityDefault =
new OpenQA.Selenium.Chrome.ChromeOptions();
chromeCapabilityDefault.BrowserVersion = Options.BrowserVersion;
Dictionary<string, object> browserstackChromeOptionsDefault =
new Dictionary<string, object>();
Dictionary<string, object> browserstackChromeOptionsDefault = new Dictionary<
string,
object
>();
browserstackChromeOptionsDefault.Add("os", Options.OperatingSystem);
browserstackChromeOptionsDefault.Add("osVersion", Options.OperatingSystemVersion);
browserstackChromeOptionsDefault.Add("local", "true");
Expand Down
6 changes: 3 additions & 3 deletions web.Tests/FunctionTests/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public TestDatabaseFixture()

public Atlas_WebContext CreateContext() =>
new Atlas_WebContext(
new DbContextOptionsBuilder<Atlas_WebContext>()
.UseSqlServer(ConnectionString)
.Options
new DbContextOptionsBuilder<Atlas_WebContext>().UseSqlServer(
ConnectionString
).Options
);

public IMemoryCache CreateCache() => new MemoryCache(new MemoryCacheOptions());
Expand Down
73 changes: 39 additions & 34 deletions web.Tests/IntegrationTests/Utilities/WebFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,56 @@

namespace web.Tests.IntegrationTests
{
public class WebFactory<TStartup> : WebApplicationFactory<TStartup>
where TStartup : class
public class WebFactory<TStartup> : WebApplicationFactory<TStartup> where TStartup : class
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureServices(services =>
{
var descriptor = services.SingleOrDefault(
d => d.ServiceType == typeof(DbContextOptions<Atlas_WebContext>)
);
if (descriptor != null)
services.Remove(descriptor);
services.AddDbContext<Atlas_WebContext>(options =>
builder.ConfigureServices(
services =>
{
options.UseInMemoryDatabase("AtlasIntegrationDb");
});
var descriptor = services.SingleOrDefault(
d => d.ServiceType == typeof(DbContextOptions<Atlas_WebContext>)
);
var sp = services.BuildServiceProvider();
if (descriptor != null)
services.Remove(descriptor);
using (var scope = sp.CreateScope())
{
var scopedServices = scope.ServiceProvider;
var db = scopedServices.GetRequiredService<Atlas_WebContext>();
var logger = scopedServices.GetRequiredService<ILogger<WebFactory<TStartup>>>();
services.AddDbContext<Atlas_WebContext>(
options =>
{
options.UseInMemoryDatabase("AtlasIntegrationDb");
}
);
db.Database.EnsureCreated();
var sp = services.BuildServiceProvider();
try
using (var scope = sp.CreateScope())
{
web.Tests.FunctionTests.Utilities.InitializeDbForTests(db);
logger.LogWarning("Test database initialized");
}
catch (Exception ex)
{
logger.LogError(
ex,
"An error occurred seeding the "
+ "database with test messages. Error: {Message}",
ex.Message
);
var scopedServices = scope.ServiceProvider;
var db = scopedServices.GetRequiredService<Atlas_WebContext>();
var logger = scopedServices.GetRequiredService<
ILogger<WebFactory<TStartup>>
>();
db.Database.EnsureCreated();
try
{
web.Tests.FunctionTests.Utilities.InitializeDbForTests(db);
logger.LogWarning("Test database initialized");
}
catch (Exception ex)
{
logger.LogError(
ex,
"An error occurred seeding the "
+ "database with test messages. Error: {Message}",
ex.Message
);
}
}
}
});
);
}
}
}
4 changes: 2 additions & 2 deletions web/Authorization/ClaimsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public static string GetUserName(this ClaimsPrincipal principal)
public static string HasAdminEnabled(this ClaimsPrincipal principal)
{
return string.IsNullOrEmpty(principal.FindFirstValue("AdminEnabled"))
? "Y"
: principal.FindFirstValue("AdminEnabled");
? "Y"
: principal.FindFirstValue("AdminEnabled");
}

public static bool HasPermission(this ClaimsPrincipal principal, string claim)
Expand Down
26 changes: 13 additions & 13 deletions web/Authorization/CustomClaimsTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,19 @@ await _context.AddAsync(
await _context.AddAsync(
new UserRoleLink
{
UserId = _context.Users
.Where(
x =>
username.Contains("@")
? x.Email == username
: x.Username == username
)
.First()
.UserId,
UserRolesId = _context.UserRoles
.Where(x => x.Name == "Administrator")
.First()
.UserRolesId
UserId =
_context.Users
.Where(
x =>
username.Contains("@")
? x.Email == username
: x.Username == username
)
.First().UserId,
UserRolesId =
_context.UserRoles
.Where(x => x.Name == "Administrator")
.First().UserRolesId
}
);
await _context.SaveChangesAsync();
Expand Down
3 changes: 1 addition & 2 deletions web/Authorization/DemoAuthHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public DemoAuthHandler(
ILoggerFactory logger,
UrlEncoder encoder,
ISystemClock clock
)
: base(options, logger, encoder, clock) { }
) : base(options, logger, encoder, clock) { }

protected override Task<AuthenticateResult> HandleAuthenticateAsync()
{
Expand Down
4 changes: 2 additions & 2 deletions web/Controllers/Asc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public async Task<IActionResult> OnPostAsync()
var saml2AuthnResponse = new Saml2AuthnResponse(config);
var relayStateQuery = binding.GetRelayStateQuery();
var returnUrl = relayStateQuery.ContainsKey(relayStateReturnUrl)
? relayStateQuery[relayStateReturnUrl]
: Url.Content("~/");
? relayStateQuery[relayStateReturnUrl]
: Url.Content("~/");

// if a login existed.. use it
if (User.Identity.IsAuthenticated)
Expand Down
Loading

0 comments on commit 2569664

Please sign in to comment.