Files
runner/src/Test/L0/Util/UrlUtilL0.cs
2022-09-15 12:14:10 +02:00

65 lines
2.3 KiB
C#

using System;
using GitHub.Runner.Sdk;
using Xunit;
namespace GitHub.Runner.Common.Tests.Util
{
public class UrlUtilL0
{
[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Common")]
public void GetCredentialEmbeddedUrl_NoUsernameAndPassword()
{
// Act.
Uri result = UrlUtil.GetCredentialEmbeddedUrl(new Uri("https://github.com/actions/runner.git"), string.Empty, string.Empty);
// Actual
Assert.Equal("https://github.com/actions/runner.git", result.AbsoluteUri);
}
[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Common")]
public void GetCredentialEmbeddedUrl_NoUsername()
{
// Act.
Uri result = UrlUtil.GetCredentialEmbeddedUrl(new Uri("https://github.com/actions/runner.git"), string.Empty, "password123");
// Actual
Assert.Equal("https://emptyusername:password123@github.com/actions/runner.git", result.AbsoluteUri);
}
[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Common")]
public void GetCredentialEmbeddedUrl_NoPassword()
{
// Act.
Uri result = UrlUtil.GetCredentialEmbeddedUrl(new Uri("https://github.com/actions/runner.git"), "user123", string.Empty);
// Actual
Assert.Equal("https://user123@github.com/actions/runner.git", result.AbsoluteUri);
}
[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Common")]
public void GetCredentialEmbeddedUrl_HasUsernameAndPassword()
{
// Act.
Uri result = UrlUtil.GetCredentialEmbeddedUrl(new Uri("https://github.com/actions/runner.git"), "user123", "password123");
// Actual
Assert.Equal("https://user123:password123@github.com/actions/runner.git", result.AbsoluteUri);
}
[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Common")]
public void GetCredentialEmbeddedUrl_UsernameAndPasswordEncoding()
{
// Act.
Uri result = UrlUtil.GetCredentialEmbeddedUrl(new Uri("https://github.com/actions/runner.git"), "user 123", "password 123");
// Actual
Assert.Equal("https://user%20123:password%20123@github.com/actions/runner.git", result.AbsoluteUri);
}
}
}