4
0

TokenCredentialsProviderTests.cs 1.2 KB

123456789101112131415161718192021222324252627282930
  1. using LibGit2Sharp;
  2. using RackPeek.Domain.Git;
  3. namespace Tests.Git;
  4. public sealed class TokenCredentialsProviderTests {
  5. [Fact]
  6. public void Produces_HTTP_Basic_Credentials_With_Configured_Username_And_Token() {
  7. // Doc: GIT_TOKEN is "used as the password for HTTP Basic auth";
  8. // GIT_USERNAME is the username the token belongs to. The handler must
  9. // wire those two into UsernamePasswordCredentials, which libgit2 sends
  10. // as HTTP Basic over HTTPS.
  11. var provider = new TokenCredentialsProvider("octocat", "ghp_secret");
  12. LibGit2Sharp.Handlers.CredentialsHandler handler = provider.GetHandler();
  13. var credentials = (UsernamePasswordCredentials)handler(
  14. "https://github.com/foo/bar.git", null!, SupportedCredentialTypes.UsernamePassword);
  15. Assert.Equal("octocat", credentials.Username);
  16. Assert.Equal("ghp_secret", credentials.Password);
  17. }
  18. [Fact]
  19. public void Rejects_Null_Username() =>
  20. Assert.Throws<ArgumentNullException>(() => new TokenCredentialsProvider(null!, "token"));
  21. [Fact]
  22. public void Rejects_Null_Token() =>
  23. Assert.Throws<ArgumentNullException>(() => new TokenCredentialsProvider("user", null!));
  24. }