mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05:00
[BEEEP] Integration tests (#1945)
* Add api integration tests * Add some stuff * Make program mockable * Work on IntegrationTests for Identity * Formatting * Update packages.lock.json * Update more packages.lock.json * Update all packages.lock.json * Fix InMemory configuration * Actually fix test configuration * Fix tests for CI * Fix event service * Force EF EventRepository * Add client_credentials test * Remove Api.IntegrationTest * Remove Api Program changes * Cleanup * Add more Auth-Email tests * Run formatting * Address some PR feedback * Move integration stuff to it's own common project * Ran linter * Add shared project to test solution * Remove sln changes * Clean usings * Add more coverage * Address PR feedback
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using AutoFixture;
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Entities;
|
||||
@ -13,6 +14,9 @@ using Bit.Infrastructure.Dapper;
|
||||
using Bit.Test.Common.AutoFixture;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
using IdentityModel;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.Utilities
|
||||
@ -390,6 +394,47 @@ namespace Bit.Core.Test.Utilities
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> TokenIsValidData()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
new object[]
|
||||
{
|
||||
"first_part 476669d4-9642-4af8-9b29-9366efad4ed3 test@email.com {0}", // unprotectedTokenTemplate
|
||||
"first_part", // firstPart
|
||||
"test@email.com", // email
|
||||
Guid.Parse("476669d4-9642-4af8-9b29-9366efad4ed3"), // id
|
||||
DateTime.UtcNow.AddHours(-1), // creationTime
|
||||
12, // expirationInHours
|
||||
true, // isValid
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(TokenIsValidData))]
|
||||
public void TokenIsValid_Success(string unprotectedTokenTemplate, string firstPart, string userEmail, Guid id, DateTime creationTime, double expirationInHours, bool isValid)
|
||||
{
|
||||
var protector = new TestDataProtector(string.Format(unprotectedTokenTemplate, CoreHelpers.ToEpocMilliseconds(creationTime)));
|
||||
|
||||
Assert.Equal(isValid, CoreHelpers.TokenIsValid(firstPart, protector, "protected_token", userEmail, id, expirationInHours));
|
||||
}
|
||||
|
||||
private class TestDataProtector : IDataProtector
|
||||
{
|
||||
private readonly string _token;
|
||||
public TestDataProtector(string token)
|
||||
{
|
||||
_token = token;
|
||||
}
|
||||
public IDataProtector CreateProtector(string purpose) => throw new NotImplementedException();
|
||||
public byte[] Protect(byte[] plaintext) => throw new NotImplementedException();
|
||||
public byte[] Unprotect(byte[] protectedData)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(_token);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("hi@email.com", "hi@email.com")] // Short email with no room to obfuscate
|
||||
[InlineData("name@email.com", "na**@email.com")] // Can obfuscate
|
||||
|
Reference in New Issue
Block a user