1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 08:32:50 -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:
Justin Baur
2022-05-20 15:24:59 -04:00
committed by GitHub
parent 98546a65ea
commit 719abc7e61
36 changed files with 8706 additions and 161 deletions

View File

@ -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

View File

@ -3546,26 +3546,26 @@
"type": "Project",
"dependencies": {
"Azure.Messaging.EventGrid": "4.7.0",
"CommCore": "1.47.1",
"Core": "1.47.1",
"CommCore": "1.48.1",
"Core": "1.48.1",
"Microsoft.AspNetCore.Mvc.NewtonsoftJson": "5.0.9",
"SharedWeb": "1.47.1",
"SharedWeb": "1.48.1",
"Swashbuckle.AspNetCore": "6.2.3"
}
},
"commcore": {
"type": "Project",
"dependencies": {
"Core": "1.47.1"
"Core": "1.48.1"
}
},
"common": {
"type": "Project",
"dependencies": {
"Api": "1.47.1",
"Api": "1.48.1",
"AutoFixture.AutoNSubstitute": "4.14.0",
"AutoFixture.Xunit2": "4.14.0",
"Core": "1.47.1",
"Core": "1.48.1",
"Kralizek.AutoFixture.Extensions.MockHttp": "1.2.0",
"Microsoft.NET.Test.Sdk": "16.6.1",
"NSubstitute": "4.2.2",
@ -3614,7 +3614,7 @@
"infrastructure.dapper": {
"type": "Project",
"dependencies": {
"Core": "1.47.1",
"Core": "1.48.1",
"Dapper": "2.0.123",
"System.Data.SqlClient": "4.8.3"
}
@ -3623,7 +3623,7 @@
"type": "Project",
"dependencies": {
"AutoMapper.Extensions.Microsoft.DependencyInjection": "8.0.1",
"Core": "1.47.1",
"Core": "1.48.1",
"Microsoft.EntityFrameworkCore.Relational": "5.0.12",
"Npgsql.EntityFrameworkCore.PostgreSQL": "5.0.2",
"Pomelo.EntityFrameworkCore.MySql": "5.0.3",
@ -3633,9 +3633,9 @@
"sharedweb": {
"type": "Project",
"dependencies": {
"Core": "1.47.1",
"Infrastructure.Dapper": "1.47.1",
"Infrastructure.EntityFramework": "1.47.1"
"Core": "1.48.1",
"Infrastructure.Dapper": "1.48.1",
"Infrastructure.EntityFramework": "1.48.1"
}
}
}