1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 07:36:14 -05:00

Turn on file scoped namespaces (#2225)

This commit is contained in:
Justin Baur
2022-08-29 14:53:16 -04:00
committed by GitHub
parent 7c4521e0b4
commit 34fb4cca2a
1206 changed files with 73816 additions and 75022 deletions

View File

@ -1,23 +1,22 @@
using Bit.Core.Models.Business;
using Xunit;
namespace Bit.Core.Test.Models.Business
namespace Bit.Core.Test.Models.Business;
public class BillingInfoTests
{
public class BillingInfoTests
[Fact]
public void BillingInvoice_Amount_ShouldComeFrom_InvoiceTotal()
{
[Fact]
public void BillingInvoice_Amount_ShouldComeFrom_InvoiceTotal()
var invoice = new Stripe.Invoice
{
var invoice = new Stripe.Invoice
{
AmountDue = 1000,
Total = 2000,
};
AmountDue = 1000,
Total = 2000,
};
var billingInvoice = new BillingInfo.BillingInvoice(invoice);
var billingInvoice = new BillingInfo.BillingInvoice(invoice);
// Should have been set from Total
Assert.Equal(20M, billingInvoice.Amount);
}
// Should have been set from Total
Assert.Equal(20M, billingInvoice.Amount);
}
}

View File

@ -1,115 +1,114 @@
using Bit.Core.Models.Business;
using Xunit;
namespace Bit.Core.Test.Models.Business
namespace Bit.Core.Test.Models.Business;
public class TaxInfoTests
{
public class TaxInfoTests
// PH = Placeholder
[Theory]
[InlineData(null, null, null, null)]
[InlineData("", "", null, null)]
[InlineData("PH", "", null, null)]
[InlineData("", "PH", null, null)]
[InlineData("AE", "PH", null, "ae_trn")]
[InlineData("AU", "PH", null, "au_abn")]
[InlineData("BR", "PH", null, "br_cnpj")]
[InlineData("CA", "PH", "bec", "ca_qst")]
[InlineData("CA", "PH", null, "ca_bn")]
[InlineData("CL", "PH", null, "cl_tin")]
[InlineData("AT", "PH", null, "eu_vat")]
[InlineData("BE", "PH", null, "eu_vat")]
[InlineData("BG", "PH", null, "eu_vat")]
[InlineData("CY", "PH", null, "eu_vat")]
[InlineData("CZ", "PH", null, "eu_vat")]
[InlineData("DE", "PH", null, "eu_vat")]
[InlineData("DK", "PH", null, "eu_vat")]
[InlineData("EE", "PH", null, "eu_vat")]
[InlineData("ES", "PH", null, "eu_vat")]
[InlineData("FI", "PH", null, "eu_vat")]
[InlineData("FR", "PH", null, "eu_vat")]
[InlineData("GB", "PH", null, "eu_vat")]
[InlineData("GR", "PH", null, "eu_vat")]
[InlineData("HR", "PH", null, "eu_vat")]
[InlineData("HU", "PH", null, "eu_vat")]
[InlineData("IE", "PH", null, "eu_vat")]
[InlineData("IT", "PH", null, "eu_vat")]
[InlineData("LT", "PH", null, "eu_vat")]
[InlineData("LU", "PH", null, "eu_vat")]
[InlineData("LV", "PH", null, "eu_vat")]
[InlineData("MT", "PH", null, "eu_vat")]
[InlineData("NL", "PH", null, "eu_vat")]
[InlineData("PL", "PH", null, "eu_vat")]
[InlineData("PT", "PH", null, "eu_vat")]
[InlineData("RO", "PH", null, "eu_vat")]
[InlineData("SE", "PH", null, "eu_vat")]
[InlineData("SI", "PH", null, "eu_vat")]
[InlineData("SK", "PH", null, "eu_vat")]
[InlineData("HK", "PH", null, "hk_br")]
[InlineData("IN", "PH", null, "in_gst")]
[InlineData("JP", "PH", null, "jp_cn")]
[InlineData("KR", "PH", null, "kr_brn")]
[InlineData("LI", "PH", null, "li_uid")]
[InlineData("MX", "PH", null, "mx_rfc")]
[InlineData("MY", "PH", null, "my_sst")]
[InlineData("NO", "PH", null, "no_vat")]
[InlineData("NZ", "PH", null, "nz_gst")]
[InlineData("RU", "PH", null, "ru_inn")]
[InlineData("SA", "PH", null, "sa_vat")]
[InlineData("SG", "PH", null, "sg_gst")]
[InlineData("TH", "PH", null, "th_vat")]
[InlineData("TW", "PH", null, "tw_vat")]
[InlineData("US", "PH", null, "us_ein")]
[InlineData("ZA", "PH", null, "za_vat")]
[InlineData("ABCDEF", "PH", null, null)]
public void GetTaxIdType_Success(string billingAddressCountry,
string taxIdNumber,
string billingAddressState,
string expectedTaxIdType)
{
// PH = Placeholder
[Theory]
[InlineData(null, null, null, null)]
[InlineData("", "", null, null)]
[InlineData("PH", "", null, null)]
[InlineData("", "PH", null, null)]
[InlineData("AE", "PH", null, "ae_trn")]
[InlineData("AU", "PH", null, "au_abn")]
[InlineData("BR", "PH", null, "br_cnpj")]
[InlineData("CA", "PH", "bec", "ca_qst")]
[InlineData("CA", "PH", null, "ca_bn")]
[InlineData("CL", "PH", null, "cl_tin")]
[InlineData("AT", "PH", null, "eu_vat")]
[InlineData("BE", "PH", null, "eu_vat")]
[InlineData("BG", "PH", null, "eu_vat")]
[InlineData("CY", "PH", null, "eu_vat")]
[InlineData("CZ", "PH", null, "eu_vat")]
[InlineData("DE", "PH", null, "eu_vat")]
[InlineData("DK", "PH", null, "eu_vat")]
[InlineData("EE", "PH", null, "eu_vat")]
[InlineData("ES", "PH", null, "eu_vat")]
[InlineData("FI", "PH", null, "eu_vat")]
[InlineData("FR", "PH", null, "eu_vat")]
[InlineData("GB", "PH", null, "eu_vat")]
[InlineData("GR", "PH", null, "eu_vat")]
[InlineData("HR", "PH", null, "eu_vat")]
[InlineData("HU", "PH", null, "eu_vat")]
[InlineData("IE", "PH", null, "eu_vat")]
[InlineData("IT", "PH", null, "eu_vat")]
[InlineData("LT", "PH", null, "eu_vat")]
[InlineData("LU", "PH", null, "eu_vat")]
[InlineData("LV", "PH", null, "eu_vat")]
[InlineData("MT", "PH", null, "eu_vat")]
[InlineData("NL", "PH", null, "eu_vat")]
[InlineData("PL", "PH", null, "eu_vat")]
[InlineData("PT", "PH", null, "eu_vat")]
[InlineData("RO", "PH", null, "eu_vat")]
[InlineData("SE", "PH", null, "eu_vat")]
[InlineData("SI", "PH", null, "eu_vat")]
[InlineData("SK", "PH", null, "eu_vat")]
[InlineData("HK", "PH", null, "hk_br")]
[InlineData("IN", "PH", null, "in_gst")]
[InlineData("JP", "PH", null, "jp_cn")]
[InlineData("KR", "PH", null, "kr_brn")]
[InlineData("LI", "PH", null, "li_uid")]
[InlineData("MX", "PH", null, "mx_rfc")]
[InlineData("MY", "PH", null, "my_sst")]
[InlineData("NO", "PH", null, "no_vat")]
[InlineData("NZ", "PH", null, "nz_gst")]
[InlineData("RU", "PH", null, "ru_inn")]
[InlineData("SA", "PH", null, "sa_vat")]
[InlineData("SG", "PH", null, "sg_gst")]
[InlineData("TH", "PH", null, "th_vat")]
[InlineData("TW", "PH", null, "tw_vat")]
[InlineData("US", "PH", null, "us_ein")]
[InlineData("ZA", "PH", null, "za_vat")]
[InlineData("ABCDEF", "PH", null, null)]
public void GetTaxIdType_Success(string billingAddressCountry,
string taxIdNumber,
string billingAddressState,
string expectedTaxIdType)
var taxInfo = new TaxInfo
{
var taxInfo = new TaxInfo
{
BillingAddressCountry = billingAddressCountry,
TaxIdNumber = taxIdNumber,
BillingAddressState = billingAddressState,
};
BillingAddressCountry = billingAddressCountry,
TaxIdNumber = taxIdNumber,
BillingAddressState = billingAddressState,
};
Assert.Equal(expectedTaxIdType, taxInfo.TaxIdType);
}
Assert.Equal(expectedTaxIdType, taxInfo.TaxIdType);
}
[Fact]
public void GetTaxIdType_CreateOnce_ReturnCacheSecondTime()
[Fact]
public void GetTaxIdType_CreateOnce_ReturnCacheSecondTime()
{
var taxInfo = new TaxInfo
{
var taxInfo = new TaxInfo
{
BillingAddressCountry = "US",
TaxIdNumber = "PH",
BillingAddressState = null,
};
BillingAddressCountry = "US",
TaxIdNumber = "PH",
BillingAddressState = null,
};
Assert.Equal("us_ein", taxInfo.TaxIdType);
Assert.Equal("us_ein", taxInfo.TaxIdType);
// Per the current spec even if the values change to something other than null it
// will return the cached version of TaxIdType.
taxInfo.BillingAddressCountry = "ZA";
// Per the current spec even if the values change to something other than null it
// will return the cached version of TaxIdType.
taxInfo.BillingAddressCountry = "ZA";
Assert.Equal("us_ein", taxInfo.TaxIdType);
}
Assert.Equal("us_ein", taxInfo.TaxIdType);
}
[Theory]
[InlineData(null, null, false)]
[InlineData("123", "US", true)]
[InlineData("123", "ZQ12", false)]
[InlineData(" ", "US", false)]
public void HasTaxId_ReturnsExpected(string taxIdNumber, string billingAddressCountry, bool expected)
[Theory]
[InlineData(null, null, false)]
[InlineData("123", "US", true)]
[InlineData("123", "ZQ12", false)]
[InlineData(" ", "US", false)]
public void HasTaxId_ReturnsExpected(string taxIdNumber, string billingAddressCountry, bool expected)
{
var taxInfo = new TaxInfo
{
var taxInfo = new TaxInfo
{
TaxIdNumber = taxIdNumber,
BillingAddressCountry = billingAddressCountry,
};
TaxIdNumber = taxIdNumber,
BillingAddressCountry = billingAddressCountry,
};
Assert.Equal(expected, taxInfo.HasTaxId);
}
Assert.Equal(expected, taxInfo.HasTaxId);
}
}

View File

@ -4,30 +4,29 @@ using Bit.Core.Models.Business.Tokenables;
using Bit.Core.Tokens;
using Xunit;
namespace Bit.Core.Test.Models.Business.Tokenables
namespace Bit.Core.Test.Models.Business.Tokenables;
public class EmergencyAccessInviteTokenableTests
{
public class EmergencyAccessInviteTokenableTests
[Theory, AutoData]
public void SerializationSetsCorrectDateTime(EmergencyAccess emergencyAccess)
{
[Theory, AutoData]
public void SerializationSetsCorrectDateTime(EmergencyAccess emergencyAccess)
{
var token = new EmergencyAccessInviteTokenable(emergencyAccess, 2);
Assert.Equal(Tokenable.FromToken<EmergencyAccessInviteTokenable>(token.ToToken().ToString()).ExpirationDate,
token.ExpirationDate,
TimeSpan.FromMilliseconds(10));
}
var token = new EmergencyAccessInviteTokenable(emergencyAccess, 2);
Assert.Equal(Tokenable.FromToken<EmergencyAccessInviteTokenable>(token.ToToken().ToString()).ExpirationDate,
token.ExpirationDate,
TimeSpan.FromMilliseconds(10));
}
[Fact]
public void IsInvalidIfIdentifierIsWrong()
[Fact]
public void IsInvalidIfIdentifierIsWrong()
{
var token = new EmergencyAccessInviteTokenable(DateTime.MaxValue)
{
var token = new EmergencyAccessInviteTokenable(DateTime.MaxValue)
{
Email = "email",
Id = Guid.NewGuid(),
Identifier = "not correct"
};
Email = "email",
Id = Guid.NewGuid(),
Identifier = "not correct"
};
Assert.False(token.Valid);
}
Assert.False(token.Valid);
}
}

View File

@ -5,84 +5,83 @@ using Bit.Core.Tokens;
using Bit.Test.Common.AutoFixture.Attributes;
using Xunit;
namespace Bit.Core.Test.Models.Business.Tokenables
namespace Bit.Core.Test.Models.Business.Tokenables;
public class HCaptchaTokenableTests
{
public class HCaptchaTokenableTests
[Fact]
public void CanHandleNullUser()
{
[Fact]
public void CanHandleNullUser()
var token = new HCaptchaTokenable(null);
Assert.Equal(default, token.Id);
Assert.Equal(default, token.Email);
}
[Fact]
public void TokenWithNullUserIsInvalid()
{
var token = new HCaptchaTokenable(null)
{
var token = new HCaptchaTokenable(null);
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
};
Assert.Equal(default, token.Id);
Assert.Equal(default, token.Email);
}
Assert.False(token.Valid);
}
[Fact]
public void TokenWithNullUserIsInvalid()
[Theory, BitAutoData]
public void TokenValidityCheckNullUserIdIsInvalid(User user)
{
var token = new HCaptchaTokenable(user)
{
var token = new HCaptchaTokenable(null)
{
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
};
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
};
Assert.False(token.Valid);
}
Assert.False(token.TokenIsValid(null));
}
[Theory, BitAutoData]
public void TokenValidityCheckNullUserIdIsInvalid(User user)
[Theory, AutoData]
public void CanUpdateExpirationToNonStandard(User user)
{
var token = new HCaptchaTokenable(user)
{
var token = new HCaptchaTokenable(user)
{
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
};
ExpirationDate = DateTime.MinValue
};
Assert.False(token.TokenIsValid(null));
}
Assert.Equal(DateTime.MinValue, token.ExpirationDate, TimeSpan.FromMilliseconds(10));
}
[Theory, AutoData]
public void CanUpdateExpirationToNonStandard(User user)
[Theory, AutoData]
public void SetsDataFromUser(User user)
{
var token = new HCaptchaTokenable(user);
Assert.Equal(user.Id, token.Id);
Assert.Equal(user.Email, token.Email);
}
[Theory, AutoData]
public void SerializationSetsCorrectDateTime(User user)
{
var expectedDateTime = DateTime.UtcNow.AddHours(-5);
var token = new HCaptchaTokenable(user)
{
var token = new HCaptchaTokenable(user)
{
ExpirationDate = DateTime.MinValue
};
ExpirationDate = expectedDateTime
};
Assert.Equal(DateTime.MinValue, token.ExpirationDate, TimeSpan.FromMilliseconds(10));
}
var result = Tokenable.FromToken<HCaptchaTokenable>(token.ToToken());
[Theory, AutoData]
public void SetsDataFromUser(User user)
Assert.Equal(expectedDateTime, result.ExpirationDate, TimeSpan.FromMilliseconds(10));
}
[Theory, AutoData]
public void IsInvalidIfIdentifierIsWrong(User user)
{
var token = new HCaptchaTokenable(user)
{
var token = new HCaptchaTokenable(user);
Identifier = "not correct"
};
Assert.Equal(user.Id, token.Id);
Assert.Equal(user.Email, token.Email);
}
[Theory, AutoData]
public void SerializationSetsCorrectDateTime(User user)
{
var expectedDateTime = DateTime.UtcNow.AddHours(-5);
var token = new HCaptchaTokenable(user)
{
ExpirationDate = expectedDateTime
};
var result = Tokenable.FromToken<HCaptchaTokenable>(token.ToToken());
Assert.Equal(expectedDateTime, result.ExpirationDate, TimeSpan.FromMilliseconds(10));
}
[Theory, AutoData]
public void IsInvalidIfIdentifierIsWrong(User user)
{
var token = new HCaptchaTokenable(user)
{
Identifier = "not correct"
};
Assert.False(token.Valid);
}
Assert.False(token.Valid);
}
}

View File

@ -4,153 +4,152 @@ using Bit.Core.Models.Business.Tokenables;
using Bit.Test.Common.AutoFixture.Attributes;
using Xunit;
namespace Bit.Core.Test.Models.Business.Tokenables
namespace Bit.Core.Test.Models.Business.Tokenables;
public class OrganizationSponsorshipOfferTokenableTests
{
public class OrganizationSponsorshipOfferTokenableTests
public static IEnumerable<object[]> PlanSponsorshipTypes() => Enum.GetValues<PlanSponsorshipType>().Select(x => new object[] { x });
[Fact]
public void IsInvalidIfIdentifierIsWrong()
{
public static IEnumerable<object[]> PlanSponsorshipTypes() => Enum.GetValues<PlanSponsorshipType>().Select(x => new object[] { x });
[Fact]
public void IsInvalidIfIdentifierIsWrong()
var token = new OrganizationSponsorshipOfferTokenable()
{
var token = new OrganizationSponsorshipOfferTokenable()
{
Email = "email",
Id = Guid.NewGuid(),
Identifier = "not correct",
SponsorshipType = PlanSponsorshipType.FamiliesForEnterprise,
};
Email = "email",
Id = Guid.NewGuid(),
Identifier = "not correct",
SponsorshipType = PlanSponsorshipType.FamiliesForEnterprise,
};
Assert.False(token.Valid);
}
Assert.False(token.Valid);
}
[Fact]
public void IsInvalidIfIdIsDefault()
[Fact]
public void IsInvalidIfIdIsDefault()
{
var token = new OrganizationSponsorshipOfferTokenable()
{
var token = new OrganizationSponsorshipOfferTokenable()
{
Email = "email",
Id = default,
SponsorshipType = PlanSponsorshipType.FamiliesForEnterprise,
};
Email = "email",
Id = default,
SponsorshipType = PlanSponsorshipType.FamiliesForEnterprise,
};
Assert.False(token.Valid);
}
Assert.False(token.Valid);
}
[Fact]
public void IsInvalidIfEmailIsEmpty()
[Fact]
public void IsInvalidIfEmailIsEmpty()
{
var token = new OrganizationSponsorshipOfferTokenable()
{
var token = new OrganizationSponsorshipOfferTokenable()
{
Email = "",
Id = Guid.NewGuid(),
SponsorshipType = PlanSponsorshipType.FamiliesForEnterprise,
};
Email = "",
Id = Guid.NewGuid(),
SponsorshipType = PlanSponsorshipType.FamiliesForEnterprise,
};
Assert.False(token.Valid);
}
Assert.False(token.Valid);
}
[Theory, BitAutoData]
public void IsValid_Success(OrganizationSponsorship sponsorship)
{
var token = new OrganizationSponsorshipOfferTokenable(sponsorship);
[Theory, BitAutoData]
public void IsValid_Success(OrganizationSponsorship sponsorship)
{
var token = new OrganizationSponsorshipOfferTokenable(sponsorship);
Assert.True(token.IsValid(sponsorship, sponsorship.OfferedToEmail));
}
Assert.True(token.IsValid(sponsorship, sponsorship.OfferedToEmail));
}
[Theory, BitAutoData]
public void IsValid_RequiresNonNullSponsorship(OrganizationSponsorship sponsorship)
{
var token = new OrganizationSponsorshipOfferTokenable(sponsorship);
[Theory, BitAutoData]
public void IsValid_RequiresNonNullSponsorship(OrganizationSponsorship sponsorship)
{
var token = new OrganizationSponsorshipOfferTokenable(sponsorship);
Assert.False(token.IsValid(null, sponsorship.OfferedToEmail));
}
Assert.False(token.IsValid(null, sponsorship.OfferedToEmail));
}
[Theory, BitAutoData]
public void IsValid_RequiresCurrentEmailToBeSameAsOfferedToEmail(OrganizationSponsorship sponsorship, string currentEmail)
{
var token = new OrganizationSponsorshipOfferTokenable(sponsorship);
[Theory, BitAutoData]
public void IsValid_RequiresCurrentEmailToBeSameAsOfferedToEmail(OrganizationSponsorship sponsorship, string currentEmail)
{
var token = new OrganizationSponsorshipOfferTokenable(sponsorship);
Assert.False(token.IsValid(sponsorship, currentEmail));
}
Assert.False(token.IsValid(sponsorship, currentEmail));
}
[Theory, BitAutoData]
public void IsValid_RequiresSameSponsorshipId(OrganizationSponsorship sponsorship1, OrganizationSponsorship sponsorship2)
{
sponsorship1.Id = sponsorship2.Id;
[Theory, BitAutoData]
public void IsValid_RequiresSameSponsorshipId(OrganizationSponsorship sponsorship1, OrganizationSponsorship sponsorship2)
{
sponsorship1.Id = sponsorship2.Id;
var token = new OrganizationSponsorshipOfferTokenable(sponsorship1);
var token = new OrganizationSponsorshipOfferTokenable(sponsorship1);
Assert.False(token.IsValid(sponsorship2, sponsorship1.OfferedToEmail));
}
Assert.False(token.IsValid(sponsorship2, sponsorship1.OfferedToEmail));
}
[Theory, BitAutoData]
public void IsValid_RequiresSameEmail(OrganizationSponsorship sponsorship1, OrganizationSponsorship sponsorship2)
{
sponsorship1.OfferedToEmail = sponsorship2.OfferedToEmail;
[Theory, BitAutoData]
public void IsValid_RequiresSameEmail(OrganizationSponsorship sponsorship1, OrganizationSponsorship sponsorship2)
{
sponsorship1.OfferedToEmail = sponsorship2.OfferedToEmail;
var token = new OrganizationSponsorshipOfferTokenable(sponsorship1);
var token = new OrganizationSponsorshipOfferTokenable(sponsorship1);
Assert.False(token.IsValid(sponsorship2, sponsorship1.OfferedToEmail));
}
Assert.False(token.IsValid(sponsorship2, sponsorship1.OfferedToEmail));
}
[Theory, BitAutoData]
public void Constructor_GrabsIdFromSponsorship(OrganizationSponsorship sponsorship)
{
var token = new OrganizationSponsorshipOfferTokenable(sponsorship);
[Theory, BitAutoData]
public void Constructor_GrabsIdFromSponsorship(OrganizationSponsorship sponsorship)
{
var token = new OrganizationSponsorshipOfferTokenable(sponsorship);
Assert.Equal(sponsorship.Id, token.Id);
}
Assert.Equal(sponsorship.Id, token.Id);
}
[Theory, BitAutoData]
public void Constructor_GrabsEmailFromSponsorshipOfferedToEmail(OrganizationSponsorship sponsorship)
{
var token = new OrganizationSponsorshipOfferTokenable(sponsorship);
[Theory, BitAutoData]
public void Constructor_GrabsEmailFromSponsorshipOfferedToEmail(OrganizationSponsorship sponsorship)
{
var token = new OrganizationSponsorshipOfferTokenable(sponsorship);
Assert.Equal(sponsorship.OfferedToEmail, token.Email);
}
Assert.Equal(sponsorship.OfferedToEmail, token.Email);
}
[Theory, BitMemberAutoData(nameof(PlanSponsorshipTypes))]
public void Constructor_GrabsSponsorshipType(PlanSponsorshipType planSponsorshipType,
OrganizationSponsorship sponsorship)
{
sponsorship.PlanSponsorshipType = planSponsorshipType;
var token = new OrganizationSponsorshipOfferTokenable(sponsorship);
[Theory, BitMemberAutoData(nameof(PlanSponsorshipTypes))]
public void Constructor_GrabsSponsorshipType(PlanSponsorshipType planSponsorshipType,
OrganizationSponsorship sponsorship)
{
sponsorship.PlanSponsorshipType = planSponsorshipType;
var token = new OrganizationSponsorshipOfferTokenable(sponsorship);
Assert.Equal(sponsorship.PlanSponsorshipType, token.SponsorshipType);
}
Assert.Equal(sponsorship.PlanSponsorshipType, token.SponsorshipType);
}
[Theory, BitAutoData]
public void Constructor_DefaultId_Throws(OrganizationSponsorship sponsorship)
{
sponsorship.Id = default;
[Theory, BitAutoData]
public void Constructor_DefaultId_Throws(OrganizationSponsorship sponsorship)
{
sponsorship.Id = default;
Assert.Throws<ArgumentException>(() => new OrganizationSponsorshipOfferTokenable(sponsorship));
}
Assert.Throws<ArgumentException>(() => new OrganizationSponsorshipOfferTokenable(sponsorship));
}
[Theory, BitAutoData]
public void Constructor_NoOfferedToEmail_Throws(OrganizationSponsorship sponsorship)
{
sponsorship.OfferedToEmail = null;
[Theory, BitAutoData]
public void Constructor_NoOfferedToEmail_Throws(OrganizationSponsorship sponsorship)
{
sponsorship.OfferedToEmail = null;
Assert.Throws<ArgumentException>(() => new OrganizationSponsorshipOfferTokenable(sponsorship));
}
Assert.Throws<ArgumentException>(() => new OrganizationSponsorshipOfferTokenable(sponsorship));
}
[Theory, BitAutoData]
public void Constructor_EmptyOfferedToEmail_Throws(OrganizationSponsorship sponsorship)
{
sponsorship.OfferedToEmail = "";
[Theory, BitAutoData]
public void Constructor_EmptyOfferedToEmail_Throws(OrganizationSponsorship sponsorship)
{
sponsorship.OfferedToEmail = "";
Assert.Throws<ArgumentException>(() => new OrganizationSponsorshipOfferTokenable(sponsorship));
}
Assert.Throws<ArgumentException>(() => new OrganizationSponsorshipOfferTokenable(sponsorship));
}
[Theory, BitAutoData]
public void Constructor_NoPlanSponsorshipType_Throws(OrganizationSponsorship sponsorship)
{
sponsorship.PlanSponsorshipType = null;
[Theory, BitAutoData]
public void Constructor_NoPlanSponsorshipType_Throws(OrganizationSponsorship sponsorship)
{
sponsorship.PlanSponsorshipType = null;
Assert.Throws<ArgumentException>(() => new OrganizationSponsorshipOfferTokenable(sponsorship));
}
Assert.Throws<ArgumentException>(() => new OrganizationSponsorshipOfferTokenable(sponsorship));
}
}

View File

@ -5,85 +5,84 @@ using Bit.Core.Tokens;
using Bit.Test.Common.AutoFixture.Attributes;
using Xunit;
namespace Bit.Core.Test.Models.Business.Tokenables
namespace Bit.Core.Test.Models.Business.Tokenables;
public class SsoTokenableTests
{
public class SsoTokenableTests
[Fact]
public void CanHandleNullOrganization()
{
[Fact]
public void CanHandleNullOrganization()
var token = new SsoTokenable(null, default);
Assert.Equal(default, token.OrganizationId);
Assert.Equal(default, token.DomainHint);
}
[Fact]
public void TokenWithNullOrganizationIsInvalid()
{
var token = new SsoTokenable(null, 500)
{
var token = new SsoTokenable(null, default);
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
};
Assert.Equal(default, token.OrganizationId);
Assert.Equal(default, token.DomainHint);
}
Assert.False(token.Valid);
}
[Fact]
public void TokenWithNullOrganizationIsInvalid()
[Theory, BitAutoData]
public void TokenValidityCheckNullOrganizationIsInvalid(Organization organization)
{
var token = new SsoTokenable(organization, 500)
{
var token = new SsoTokenable(null, 500)
{
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
};
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
};
Assert.False(token.Valid);
}
Assert.False(token.TokenIsValid(null));
}
[Theory, BitAutoData]
public void TokenValidityCheckNullOrganizationIsInvalid(Organization organization)
[Theory, AutoData]
public void SetsDataFromOrganization(Organization organization)
{
var token = new SsoTokenable(organization, default);
Assert.Equal(organization.Id, token.OrganizationId);
Assert.Equal(organization.Identifier, token.DomainHint);
}
[Fact]
public void SetsExpirationFromConstructor()
{
var expectedDateTime = DateTime.UtcNow.AddSeconds(500);
var token = new SsoTokenable(null, 500);
Assert.Equal(expectedDateTime, token.ExpirationDate, TimeSpan.FromMilliseconds(10));
}
[Theory, AutoData]
public void SerializationSetsCorrectDateTime(Organization organization)
{
var expectedDateTime = DateTime.UtcNow.AddHours(-5);
var token = new SsoTokenable(organization, default)
{
var token = new SsoTokenable(organization, 500)
{
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
};
ExpirationDate = expectedDateTime
};
Assert.False(token.TokenIsValid(null));
}
var result = Tokenable.FromToken<HCaptchaTokenable>(token.ToToken());
[Theory, AutoData]
public void SetsDataFromOrganization(Organization organization)
Assert.Equal(expectedDateTime, result.ExpirationDate, TimeSpan.FromMilliseconds(10));
}
[Theory, AutoData]
public void TokenIsValidFailsWhenExpired(Organization organization)
{
var expectedDateTime = DateTime.UtcNow.AddHours(-5);
var token = new SsoTokenable(organization, default)
{
var token = new SsoTokenable(organization, default);
ExpirationDate = expectedDateTime
};
Assert.Equal(organization.Id, token.OrganizationId);
Assert.Equal(organization.Identifier, token.DomainHint);
}
var result = token.TokenIsValid(organization);
[Fact]
public void SetsExpirationFromConstructor()
{
var expectedDateTime = DateTime.UtcNow.AddSeconds(500);
var token = new SsoTokenable(null, 500);
Assert.Equal(expectedDateTime, token.ExpirationDate, TimeSpan.FromMilliseconds(10));
}
[Theory, AutoData]
public void SerializationSetsCorrectDateTime(Organization organization)
{
var expectedDateTime = DateTime.UtcNow.AddHours(-5);
var token = new SsoTokenable(organization, default)
{
ExpirationDate = expectedDateTime
};
var result = Tokenable.FromToken<HCaptchaTokenable>(token.ToToken());
Assert.Equal(expectedDateTime, result.ExpirationDate, TimeSpan.FromMilliseconds(10));
}
[Theory, AutoData]
public void TokenIsValidFailsWhenExpired(Organization organization)
{
var expectedDateTime = DateTime.UtcNow.AddHours(-5);
var token = new SsoTokenable(organization, default)
{
ExpirationDate = expectedDateTime
};
var result = token.TokenIsValid(organization);
Assert.False(result);
}
Assert.False(result);
}
}