- curl/REST 인증을 Basic(아이디:비밀번호 리터럴)에서 토큰 헤더로 전환 - 토큰이 없으면 빌드 전에 즉시 중단 - 결과를 쓰지 않던 git credential fill 프로세스 제거 - .env 를 .gitignore 에 추가 - ReleaseScriptSecretsTests: 스크립트에 자격증명이 다시 들어오지 않도록 고정
47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
using Xunit;
|
|
|
|
namespace Everything2Everything.Tests;
|
|
|
|
/// <summary>
|
|
/// 릴리즈 스크립트는 저장소에 커밋되므로 자격증명을 담지 않는다.
|
|
/// 토큰은 .gitignore 된 .env 의 FORGEJO_TOKEN 으로만 받는다.
|
|
/// </summary>
|
|
public class ReleaseScriptSecretsTests
|
|
{
|
|
private static readonly string Root = FindRoot();
|
|
private static readonly string Script = Path.Combine(Root, "tools", "Publish-Release.ps1");
|
|
|
|
private static string FindRoot()
|
|
{
|
|
var dir = Directory.GetCurrentDirectory();
|
|
while (dir != null && !File.Exists(Path.Combine(dir, "Everything2Everything.slnx")))
|
|
dir = Directory.GetParent(dir)?.FullName;
|
|
return dir ?? throw new DirectoryNotFoundException("솔루션 루트를 찾을 수 없습니다.");
|
|
}
|
|
|
|
[Fact]
|
|
public void PublishRelease_MustNotEmbedCredentials()
|
|
{
|
|
var text = File.ReadAllText(Script);
|
|
Assert.DoesNotMatch(@"-u\s+""[^""$]+:[^""]+""", text); // curl -u "user:pass"
|
|
Assert.DoesNotMatch(@"GetBytes\(\s*""[^""$]+:[^""]+""\s*\)", text); // Basic 인증 리터럴
|
|
Assert.DoesNotMatch(@"https://[^/\s:@]+:[^@\s]+@", text); // URL에 박힌 자격증명
|
|
}
|
|
|
|
[Fact]
|
|
public void PublishRelease_MustReadTokenFromEnvironment_AndFailFastWithoutIt()
|
|
{
|
|
var text = File.ReadAllText(Script);
|
|
Assert.Contains("$env:FORGEJO_TOKEN", text);
|
|
Assert.Matches(new Regex(@"if\s*\(\s*-not\s+\$env:FORGEJO_TOKEN"), text);
|
|
}
|
|
|
|
[Fact]
|
|
public void DotEnv_MustBeGitIgnored()
|
|
{
|
|
var ignore = File.ReadAllLines(Path.Combine(Root, ".gitignore"));
|
|
Assert.Contains(ignore, l => l.Trim() is ".env" or "/.env");
|
|
}
|
|
}
|