Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 72a392e652 | |||
| 7e02e86cd6 |
@@ -6,7 +6,7 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
env:
|
env:
|
||||||
VERSION: 2.8.0
|
VERSION: 2.8.1
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# ЧАСТЬ 1: Собираем образы и кладем в Gitea (чтобы делиться с ребятами)
|
# ЧАСТЬ 1: Собираем образы и кладем в Gitea (чтобы делиться с ребятами)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>2.8.0</Version>
|
<Version>2.8.1</Version>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<LangVersion>preview</LangVersion>
|
<LangVersion>preview</LangVersion>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|||||||
+3
-3
@@ -49,7 +49,7 @@ services:
|
|||||||
crond -f
|
crond -f
|
||||||
|
|
||||||
bot:
|
bot:
|
||||||
image: git.codeanddice.ru/toutsu/gmrelay-bot:2.8.0
|
image: git.codeanddice.ru/toutsu/gmrelay-bot:2.8.1
|
||||||
restart: always
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
@@ -67,7 +67,7 @@ services:
|
|||||||
retries: 3
|
retries: 3
|
||||||
|
|
||||||
discord:
|
discord:
|
||||||
image: git.codeanddice.ru/toutsu/gmrelay-discord-bot:2.8.0
|
image: git.codeanddice.ru/toutsu/gmrelay-discord-bot:2.8.1
|
||||||
restart: always
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
@@ -84,7 +84,7 @@ services:
|
|||||||
retries: 3
|
retries: 3
|
||||||
|
|
||||||
web:
|
web:
|
||||||
image: git.codeanddice.ru/toutsu/gmrelay-web:2.8.0
|
image: git.codeanddice.ru/toutsu/gmrelay-web:2.8.1
|
||||||
restart: always
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
|
|||||||
@@ -66,7 +66,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div class="nav-version">v2.8.0</div>
|
<div class="nav-version">v2.8.1</div>
|
||||||
</div>
|
</div>
|
||||||
</Authorized>
|
</Authorized>
|
||||||
<NotAuthorized>
|
<NotAuthorized>
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ app.MapGet("/auth/discord", (HttpContext context, DiscordAuthService discordAuth
|
|||||||
{
|
{
|
||||||
HttpOnly = true,
|
HttpOnly = true,
|
||||||
Secure = true,
|
Secure = true,
|
||||||
SameSite = SameSiteMode.Strict,
|
SameSite = SameSiteMode.None,
|
||||||
MaxAge = TimeSpan.FromMinutes(5)
|
MaxAge = TimeSpan.FromMinutes(5)
|
||||||
});
|
});
|
||||||
var url = discordAuth.BuildAuthorizeUrl(state);
|
var url = discordAuth.BuildAuthorizeUrl(state);
|
||||||
@@ -202,7 +202,8 @@ app.MapGet("/auth/discord", (HttpContext context, DiscordAuthService discordAuth
|
|||||||
app.MapGet("/auth/discord/callback", async (
|
app.MapGet("/auth/discord/callback", async (
|
||||||
HttpContext context,
|
HttpContext context,
|
||||||
DiscordAuthService discordAuth,
|
DiscordAuthService discordAuth,
|
||||||
ISessionStore sessionStore) =>
|
ISessionStore sessionStore,
|
||||||
|
ILogger<Program> logger) =>
|
||||||
{
|
{
|
||||||
var code = context.Request.Query["code"].ToString();
|
var code = context.Request.Query["code"].ToString();
|
||||||
var state = context.Request.Query["state"].ToString();
|
var state = context.Request.Query["state"].ToString();
|
||||||
@@ -216,6 +217,8 @@ app.MapGet("/auth/discord/callback", async (
|
|||||||
System.Text.Encoding.UTF8.GetBytes(state),
|
System.Text.Encoding.UTF8.GetBytes(state),
|
||||||
System.Text.Encoding.UTF8.GetBytes(storedState ?? string.Empty)))
|
System.Text.Encoding.UTF8.GetBytes(storedState ?? string.Empty)))
|
||||||
{
|
{
|
||||||
|
logger.LogWarning("Discord OAuth CSRF validation failed. code_present={CodePresent}, state_present={StatePresent}, stored_state_present={StoredStatePresent}",
|
||||||
|
!string.IsNullOrWhiteSpace(code), !string.IsNullOrWhiteSpace(state), !string.IsNullOrWhiteSpace(storedState));
|
||||||
return Results.Redirect("/login?error=auth_failed");
|
return Results.Redirect("/login?error=auth_failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using System.Text.Json.Serialization;
|
|||||||
|
|
||||||
namespace GmRelay.Web.Services;
|
namespace GmRelay.Web.Services;
|
||||||
|
|
||||||
public sealed class DiscordAuthService(IHttpClientFactory httpClientFactory, IConfiguration configuration)
|
public sealed class DiscordAuthService(IHttpClientFactory httpClientFactory, IConfiguration configuration, ILogger<DiscordAuthService> logger)
|
||||||
{
|
{
|
||||||
private readonly DiscordOAuthOptions _options = configuration.GetSection("Discord").Get<DiscordOAuthOptions>() ?? new DiscordOAuthOptions();
|
private readonly DiscordOAuthOptions _options = configuration.GetSection("Discord").Get<DiscordOAuthOptions>() ?? new DiscordOAuthOptions();
|
||||||
|
|
||||||
@@ -40,10 +40,14 @@ public sealed class DiscordAuthService(IHttpClientFactory httpClientFactory, ICo
|
|||||||
});
|
});
|
||||||
|
|
||||||
var response = await client.PostAsync("https://discord.com/api/oauth2/token", content);
|
var response = await client.PostAsync("https://discord.com/api/oauth2/token", content);
|
||||||
if (!response.IsSuccessStatusCode)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var json = await response.Content.ReadAsStringAsync();
|
var json = await response.Content.ReadAsStringAsync();
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
logger.LogError("Discord token exchange failed: {StatusCode} {Body}. client_id={ClientId}, redirect_uri={RedirectUri}",
|
||||||
|
(int)response.StatusCode, json, _options.ClientId, _options.RedirectUri);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return JsonSerializer.Deserialize<DiscordTokenResponse>(json);
|
return JsonSerializer.Deserialize<DiscordTokenResponse>(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public sealed class DiscordProjectStructureTests
|
|||||||
var prChecks = File.ReadAllText(Path.Combine(repoRoot, ".gitea", "workflows", "pr-checks.yml"));
|
var prChecks = File.ReadAllText(Path.Combine(repoRoot, ".gitea", "workflows", "pr-checks.yml"));
|
||||||
var deploy = File.ReadAllText(Path.Combine(repoRoot, ".gitea", "workflows", "deploy.yml"));
|
var deploy = File.ReadAllText(Path.Combine(repoRoot, ".gitea", "workflows", "deploy.yml"));
|
||||||
|
|
||||||
Assert.Contains("gmrelay-discord-bot:2.8.0", compose);
|
Assert.Contains("gmrelay-discord-bot:2.8.1", compose);
|
||||||
Assert.Contains("Discord__Token=${DISCORD_BOT_TOKEN:?Set DISCORD_BOT_TOKEN in .env}", compose);
|
Assert.Contains("Discord__Token=${DISCORD_BOT_TOKEN:?Set DISCORD_BOT_TOKEN in .env}", compose);
|
||||||
Assert.Contains("src/GmRelay.DiscordBot/Dockerfile", deploy);
|
Assert.Contains("src/GmRelay.DiscordBot/Dockerfile", deploy);
|
||||||
Assert.Contains("DISCORD_BOT_TOKEN", deploy);
|
Assert.Contains("DISCORD_BOT_TOKEN", deploy);
|
||||||
@@ -75,13 +75,13 @@ public sealed class DiscordProjectStructureTests
|
|||||||
{
|
{
|
||||||
var repoRoot = GetRepoRoot();
|
var repoRoot = GetRepoRoot();
|
||||||
|
|
||||||
Assert.Contains("<Version>2.8.0</Version>", File.ReadAllText(Path.Combine(repoRoot, "Directory.Build.props")));
|
Assert.Contains("<Version>2.8.1</Version>", File.ReadAllText(Path.Combine(repoRoot, "Directory.Build.props")));
|
||||||
Assert.Contains("VERSION: 2.8.0", File.ReadAllText(Path.Combine(repoRoot, ".gitea", "workflows", "deploy.yml")));
|
Assert.Contains("VERSION: 2.8.1", File.ReadAllText(Path.Combine(repoRoot, ".gitea", "workflows", "deploy.yml")));
|
||||||
Assert.Contains("gmrelay-bot:2.8.0", File.ReadAllText(Path.Combine(repoRoot, "compose.yaml")));
|
Assert.Contains("gmrelay-bot:2.8.1", File.ReadAllText(Path.Combine(repoRoot, "compose.yaml")));
|
||||||
Assert.Contains("gmrelay-web:2.8.0", File.ReadAllText(Path.Combine(repoRoot, "compose.yaml")));
|
Assert.Contains("gmrelay-web:2.8.1", File.ReadAllText(Path.Combine(repoRoot, "compose.yaml")));
|
||||||
Assert.Contains("gmrelay-discord-bot:2.8.0", File.ReadAllText(Path.Combine(repoRoot, "compose.yaml")));
|
Assert.Contains("gmrelay-discord-bot:2.8.1", File.ReadAllText(Path.Combine(repoRoot, "compose.yaml")));
|
||||||
Assert.Contains(
|
Assert.Contains(
|
||||||
"v2.8.0",
|
"v2.8.1",
|
||||||
File.ReadAllText(Path.Combine(repoRoot, "src", "GmRelay.Web", "Components", "Layout", "NavMenu.razor")));
|
File.ReadAllText(Path.Combine(repoRoot, "src", "GmRelay.Web", "Components", "Layout", "NavMenu.razor")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Text.Json;
|
|||||||
using GmRelay.Web;
|
using GmRelay.Web;
|
||||||
using GmRelay.Web.Services;
|
using GmRelay.Web.Services;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
||||||
namespace GmRelay.Bot.Tests.Web;
|
namespace GmRelay.Bot.Tests.Web;
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ public class DiscordAuthServiceTests
|
|||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var service = new DiscordAuthService(new TestHttpClientFactory(), config);
|
var service = new DiscordAuthService(new TestHttpClientFactory(), config, NullLogger<DiscordAuthService>.Instance);
|
||||||
var url = service.BuildAuthorizeUrl("state123");
|
var url = service.BuildAuthorizeUrl("state123");
|
||||||
|
|
||||||
Assert.Contains("client_id=12345", url);
|
Assert.Contains("client_id=12345", url);
|
||||||
@@ -33,7 +34,7 @@ public class DiscordAuthServiceTests
|
|||||||
public void BuildAuthorizeUrl_WithMissingConfig_ThrowsInvalidOperationException()
|
public void BuildAuthorizeUrl_WithMissingConfig_ThrowsInvalidOperationException()
|
||||||
{
|
{
|
||||||
var config = new ConfigurationBuilder().Build();
|
var config = new ConfigurationBuilder().Build();
|
||||||
var service = new DiscordAuthService(new TestHttpClientFactory(), config);
|
var service = new DiscordAuthService(new TestHttpClientFactory(), config, NullLogger<DiscordAuthService>.Instance);
|
||||||
|
|
||||||
Assert.Throws<InvalidOperationException>(() => service.BuildAuthorizeUrl("state"));
|
Assert.Throws<InvalidOperationException>(() => service.BuildAuthorizeUrl("state"));
|
||||||
}
|
}
|
||||||
@@ -74,7 +75,7 @@ public class DiscordAuthServiceTests
|
|||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var factory = new TestHttpClientFactory(handler);
|
var factory = new TestHttpClientFactory(handler);
|
||||||
var service = new DiscordAuthService(factory, config);
|
var service = new DiscordAuthService(factory, config, NullLogger<DiscordAuthService>.Instance);
|
||||||
|
|
||||||
var result = await service.ExchangeCodeAsync("valid_code");
|
var result = await service.ExchangeCodeAsync("valid_code");
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@ public class DiscordAuthServiceTests
|
|||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var factory = new TestHttpClientFactory(handler);
|
var factory = new TestHttpClientFactory(handler);
|
||||||
var service = new DiscordAuthService(factory, config);
|
var service = new DiscordAuthService(factory, config, NullLogger<DiscordAuthService>.Instance);
|
||||||
|
|
||||||
var result = await service.ExchangeCodeAsync("invalid_code");
|
var result = await service.ExchangeCodeAsync("invalid_code");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user