Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

78 lines (65 sloc) 2.421 kb
using System.Collections.Specialized;
using Xunit;
using Xunit.Extensions;
namespace NuGet.Server.Infrastructure.Test
{
public class PackageAuthenticationServiceTests
{
[Theory]
[InlineData("")]
[InlineData("foo")]
[InlineData("not-true")]
public void AuthenticationServiceReturnsFalseIfRequireApiKeyValueIsMalformed(string requireApiKey)
{
// Arrange
var collection = new NameValueCollection();
collection.Add("requireApiKey", requireApiKey);
// Act
bool result = PackageAuthenticationService.IsAuthenticatedInternal("test-apikey", collection);
// Assert
Assert.False(result);
}
[Theory]
[InlineData("false")]
[InlineData("FaLse")]
public void AuthenticationServiceReturnsTrueIfRequireApiKeyValueIsSetToFalse(string keyValue)
{
// Arrange
var collection = new NameValueCollection();
collection.Add("requireApiKey", keyValue);
collection.Add("apiKey", "test-key");
// Act
bool result = PackageAuthenticationService.IsAuthenticatedInternal("incorrect-key", collection);
// Assert
Assert.True(result);
}
[Theory]
[InlineData(null)]
[InlineData("incorrect-key")]
public void AuthenticationServiceReturnsFalseIfKeyDoesNotMatchConfigurationKey(string key)
{
// Arrange
var collection = new NameValueCollection();
collection.Add("requireApiKey", "true");
collection.Add("apiKey", "test-key");
// Act
bool result = PackageAuthenticationService.IsAuthenticatedInternal(key, collection);
// Assert
Assert.False(result);
}
[Theory]
[InlineData("test-key")]
[InlineData("tEst-Key")]
public void AuthenticationServiceReturnsTrueIfKeyMatchesConfigurationKey(string key)
{
// Arrange
var collection = new NameValueCollection();
collection.Add("requireApiKey", "true");
collection.Add("apiKey", "test-key");
// Act
bool result = PackageAuthenticationService.IsAuthenticatedInternal(key, collection);
// Assert
Assert.True(result);
}
}
}
Jump to Line
Something went wrong with that request. Please try again.