diff --git a/.idea/.idea.Testably.Server/.idea/.gitignore b/.idea/.idea.Testably.Server/.idea/.gitignore
new file mode 100644
index 0000000..882e90d
--- /dev/null
+++ b/.idea/.idea.Testably.Server/.idea/.gitignore
@@ -0,0 +1,13 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Rider ignored files
+/modules.xml
+/contentModel.xml
+/.idea.Testably.Server.iml
+/projectSettingsUpdater.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/.idea.Testably.Server/.idea/encodings.xml b/.idea/.idea.Testably.Server/.idea/encodings.xml
new file mode 100644
index 0000000..df87cf9
--- /dev/null
+++ b/.idea/.idea.Testably.Server/.idea/encodings.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.Testably.Server/.idea/vcs.xml b/.idea/.idea.Testably.Server/.idea/vcs.xml
new file mode 100644
index 0000000..d843f34
--- /dev/null
+++ b/.idea/.idea.Testably.Server/.idea/vcs.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/Source/Testably.Server/Controllers/PullRequestStatusCheckController.cs b/Source/Testably.Server/Controllers/PullRequestStatusCheckController.cs
index a6dd661..b4a6941 100644
--- a/Source/Testably.Server/Controllers/PullRequestStatusCheckController.cs
+++ b/Source/Testably.Server/Controllers/PullRequestStatusCheckController.cs
@@ -67,7 +67,20 @@ public async Task OnPullRequestChanged(
return BadRequest($"Only public repositories from '{string.Join(", ", RepositoryOwners)}' are supported!");
}
- var bearerToken = _configuration.GetValue("GithubBearerToken");
+ var bearerToken = pullRequestModel.Repository.Owner.Login switch
+ {
+ "Testably" => _configuration.GetValue("testablyToken"),
+ "aweXpect" => _configuration.GetValue("aweXpectToken"),
+ _ => ""
+ };
+ if (string.IsNullOrEmpty(bearerToken))
+ {
+ _logger.LogWarning("Could not find valid bearer token for {Organization}",
+ pullRequestModel.Repository.Owner.Login);
+ return StatusCode(StatusCodes.Status403Forbidden,
+ $"Could not find valid bearer token for {pullRequestModel.Repository.Owner.Login}");
+ }
+
using var client = _clientFactory.CreateClient("Proxied");
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Testably",
Assembly.GetExecutingAssembly().GetName().Version.ToString()));
@@ -85,6 +98,7 @@ public async Task OnPullRequestChanged(
if (!response.IsSuccessStatusCode)
{
var responseContent = await response.Content.ReadAsStringAsync();
+ _logger.LogWarning("GitHub API '{RequestUri}' not available: {ResponseContent}", requestUri, responseContent);
return StatusCode(StatusCodes.Status500InternalServerError,
$"GitHub API '{requestUri}' not available: {responseContent}");
}
@@ -96,6 +110,7 @@ await response.Content.ReadAsStreamAsync(cancellationToken),
if (!jsonDocument.RootElement.TryGetProperty("title", out var titleProperty) ||
titleProperty.GetString() == null)
{
+ _logger.LogWarning("GitHub API '{RequestUri}' returned an invalid response (missing title).", requestUri);
return StatusCode(StatusCodes.Status500InternalServerError,
$"GitHub API '{requestUri}' returned an invalid response (missing title).");
}
@@ -104,6 +119,7 @@ await response.Content.ReadAsStreamAsync(cancellationToken),
!headProperty.TryGetProperty("sha", out var shaProperty) ||
shaProperty.GetString() == null)
{
+ _logger.LogWarning("GitHub API '{RequestUri}' returned an invalid response (missing head.sha).", requestUri);
return StatusCode(StatusCodes.Status500InternalServerError,
$"GitHub API '{requestUri}' returned an invalid response (missing head.sha).");
}
diff --git a/Testably.Server.sln.DotSettings b/Testably.Server.sln.DotSettings
index d084548..fd38711 100644
--- a/Testably.Server.sln.DotSettings
+++ b/Testably.Server.sln.DotSettings
@@ -449,6 +449,7 @@
True
True
True
+ True
True
True
True
diff --git a/Tests/Testably.Server.Tests/TestFactory.cs b/Tests/Testably.Server.Tests/TestFactory.cs
index bbf0ebe..ee78766 100644
--- a/Tests/Testably.Server.Tests/TestFactory.cs
+++ b/Tests/Testably.Server.Tests/TestFactory.cs
@@ -1,17 +1,25 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
namespace Testably.Server.Tests;
public class TestFactory : WebApplicationFactory
{
+ private readonly IConfiguration _configuration;
private readonly IHttpClientFactory? _httpClientFactory;
- public TestFactory(IHttpClientFactory? httpClientFactory = null)
+ public TestFactory(IHttpClientFactory? httpClientFactory = null,
+ Action>? configuration = null)
{
_httpClientFactory = httpClientFactory;
+ var builder = new ConfigurationBuilder();
+ var inMemoryConfiguration = new Dictionary();
+ configuration?.Invoke(inMemoryConfiguration);
+ _configuration = builder.AddInMemoryCollection(inMemoryConfiguration!).Build();
}
///
@@ -22,8 +30,8 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
{
if (_httpClientFactory != null)
{
- var descriptor =
- services.SingleOrDefault(d => d.ServiceType == _httpClientFactory.GetType());
+ var descriptor = services
+ .SingleOrDefault(d => d.ServiceType == _httpClientFactory.GetType());
if (descriptor != null)
{
services.Remove(descriptor);
@@ -31,6 +39,17 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
services.AddSingleton(_httpClientFactory);
}
+
+ services.AddSingleton(_configuration);
});
}
+
+ ///
+ /// https://stackoverflow.com/a/69825605
+ ///
+ protected override IHost CreateHost(IHostBuilder builder)
+ {
+ builder.UseContentRoot(Directory.GetCurrentDirectory());
+ return base.CreateHost(builder);
+ }
}
\ No newline at end of file
diff --git a/Tests/Testably.Server.Tests/WebhookTests.cs b/Tests/Testably.Server.Tests/WebhookTests.cs
index 00c4a07..3ce7214 100644
--- a/Tests/Testably.Server.Tests/WebhookTests.cs
+++ b/Tests/Testably.Server.Tests/WebhookTests.cs
@@ -33,7 +33,8 @@ public async Task HappyCase_ShouldSucceed(string title, string status)
sentStatusCheck = c;
return "";
}));
- await using var factory = new TestFactory(httpClientFactoryMock.Object);
+ await using var factory = new TestFactory(httpClientFactoryMock.Object,
+ c => c.Add("testablyToken", "foo"));
using var client = factory.CreateClient();
client.DefaultRequestHeaders.Add("x-github-event", "pull_request");
using var content = new StringContent(webhookPayload, mediaType: "application/json",