API key protection
This commit is contained in:
parent
cd72b7b9aa
commit
38bb7e40ef
7 changed files with 143 additions and 19 deletions
|
|
@ -19,6 +19,9 @@ using System.Threading.Tasks;
|
|||
using NuGet.Protocol.Core.Types;
|
||||
using NuGet.Common;
|
||||
using Isn.Abstract;
|
||||
using isnd.Helpers;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace isnd.host.tests
|
||||
{
|
||||
|
|
@ -49,6 +52,17 @@ namespace isnd.host.tests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LegacyApiKeyProtectorCanUnprotectValuesFromOlderClients()
|
||||
{
|
||||
const string clearValue = "legacy-api-key";
|
||||
var legacyProtectedValue = new Isn.DefaultDataProtector().Protect(clearValue);
|
||||
|
||||
var unprotected = ApiKeyProtector.UnprotectWithFallback(new ThrowingProtector(), legacyProtectedValue);
|
||||
|
||||
Assert.Equal(clearValue, unprotected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
void TestDropUser()
|
||||
{
|
||||
|
|
@ -117,5 +131,14 @@ namespace isnd.host.tests
|
|||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private sealed class ThrowingProtector : IDataProtector
|
||||
{
|
||||
public byte[] Protect(byte[] plaintext) => throw new CryptographicException("unexpected protect call");
|
||||
|
||||
public byte[] Unprotect(byte[] protectedData) => throw new CryptographicException("unexpected unprotect call");
|
||||
|
||||
public IDataProtector CreateProtector(string purpose) => this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue