mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05:00
Revert filescoped (#2227)
* Revert "Add git blame entry (#2226)" This reverts commit239286737d
. * Revert "Turn on file scoped namespaces (#2225)" This reverts commit34fb4cca2a
.
This commit is contained in:
@ -1,22 +1,23 @@
|
||||
using Bit.Core.Models.Business;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.Models.Business;
|
||||
|
||||
public class BillingInfoTests
|
||||
namespace Bit.Core.Test.Models.Business
|
||||
{
|
||||
[Fact]
|
||||
public void BillingInvoice_Amount_ShouldComeFrom_InvoiceTotal()
|
||||
public class BillingInfoTests
|
||||
{
|
||||
var invoice = new Stripe.Invoice
|
||||
[Fact]
|
||||
public void BillingInvoice_Amount_ShouldComeFrom_InvoiceTotal()
|
||||
{
|
||||
AmountDue = 1000,
|
||||
Total = 2000,
|
||||
};
|
||||
var invoice = new Stripe.Invoice
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,114 +1,115 @@
|
||||
using Bit.Core.Models.Business;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.Models.Business;
|
||||
|
||||
public class TaxInfoTests
|
||||
namespace Bit.Core.Test.Models.Business
|
||||
{
|
||||
// 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)
|
||||
public class TaxInfoTests
|
||||
{
|
||||
var taxInfo = new TaxInfo
|
||||
// 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)
|
||||
{
|
||||
BillingAddressCountry = billingAddressCountry,
|
||||
TaxIdNumber = taxIdNumber,
|
||||
BillingAddressState = billingAddressState,
|
||||
};
|
||||
var taxInfo = new TaxInfo
|
||||
{
|
||||
BillingAddressCountry = billingAddressCountry,
|
||||
TaxIdNumber = taxIdNumber,
|
||||
BillingAddressState = billingAddressState,
|
||||
};
|
||||
|
||||
Assert.Equal(expectedTaxIdType, taxInfo.TaxIdType);
|
||||
}
|
||||
Assert.Equal(expectedTaxIdType, taxInfo.TaxIdType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetTaxIdType_CreateOnce_ReturnCacheSecondTime()
|
||||
{
|
||||
var taxInfo = new TaxInfo
|
||||
[Fact]
|
||||
public void GetTaxIdType_CreateOnce_ReturnCacheSecondTime()
|
||||
{
|
||||
BillingAddressCountry = "US",
|
||||
TaxIdNumber = "PH",
|
||||
BillingAddressState = null,
|
||||
};
|
||||
var taxInfo = new TaxInfo
|
||||
{
|
||||
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)
|
||||
{
|
||||
var taxInfo = new TaxInfo
|
||||
[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)
|
||||
{
|
||||
TaxIdNumber = taxIdNumber,
|
||||
BillingAddressCountry = billingAddressCountry,
|
||||
};
|
||||
var taxInfo = new TaxInfo
|
||||
{
|
||||
TaxIdNumber = taxIdNumber,
|
||||
BillingAddressCountry = billingAddressCountry,
|
||||
};
|
||||
|
||||
Assert.Equal(expected, taxInfo.HasTaxId);
|
||||
Assert.Equal(expected, taxInfo.HasTaxId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,29 +4,30 @@ using Bit.Core.Models.Business.Tokenables;
|
||||
using Bit.Core.Tokens;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.Models.Business.Tokenables;
|
||||
|
||||
public class EmergencyAccessInviteTokenableTests
|
||||
namespace Bit.Core.Test.Models.Business.Tokenables
|
||||
{
|
||||
[Theory, AutoData]
|
||||
public void SerializationSetsCorrectDateTime(EmergencyAccess emergencyAccess)
|
||||
public class EmergencyAccessInviteTokenableTests
|
||||
{
|
||||
var token = new EmergencyAccessInviteTokenable(emergencyAccess, 2);
|
||||
Assert.Equal(Tokenable.FromToken<EmergencyAccessInviteTokenable>(token.ToToken().ToString()).ExpirationDate,
|
||||
token.ExpirationDate,
|
||||
TimeSpan.FromMilliseconds(10));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsInvalidIfIdentifierIsWrong()
|
||||
{
|
||||
var token = new EmergencyAccessInviteTokenable(DateTime.MaxValue)
|
||||
[Theory, AutoData]
|
||||
public void SerializationSetsCorrectDateTime(EmergencyAccess emergencyAccess)
|
||||
{
|
||||
Email = "email",
|
||||
Id = Guid.NewGuid(),
|
||||
Identifier = "not correct"
|
||||
};
|
||||
var token = new EmergencyAccessInviteTokenable(emergencyAccess, 2);
|
||||
Assert.Equal(Tokenable.FromToken<EmergencyAccessInviteTokenable>(token.ToToken().ToString()).ExpirationDate,
|
||||
token.ExpirationDate,
|
||||
TimeSpan.FromMilliseconds(10));
|
||||
}
|
||||
|
||||
Assert.False(token.Valid);
|
||||
[Fact]
|
||||
public void IsInvalidIfIdentifierIsWrong()
|
||||
{
|
||||
var token = new EmergencyAccessInviteTokenable(DateTime.MaxValue)
|
||||
{
|
||||
Email = "email",
|
||||
Id = Guid.NewGuid(),
|
||||
Identifier = "not correct"
|
||||
};
|
||||
|
||||
Assert.False(token.Valid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,83 +5,84 @@ using Bit.Core.Tokens;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.Models.Business.Tokenables;
|
||||
|
||||
public class HCaptchaTokenableTests
|
||||
namespace Bit.Core.Test.Models.Business.Tokenables
|
||||
{
|
||||
[Fact]
|
||||
public void CanHandleNullUser()
|
||||
public class HCaptchaTokenableTests
|
||||
{
|
||||
var token = new HCaptchaTokenable(null);
|
||||
|
||||
Assert.Equal(default, token.Id);
|
||||
Assert.Equal(default, token.Email);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TokenWithNullUserIsInvalid()
|
||||
{
|
||||
var token = new HCaptchaTokenable(null)
|
||||
[Fact]
|
||||
public void CanHandleNullUser()
|
||||
{
|
||||
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
|
||||
};
|
||||
var token = new HCaptchaTokenable(null);
|
||||
|
||||
Assert.False(token.Valid);
|
||||
}
|
||||
Assert.Equal(default, token.Id);
|
||||
Assert.Equal(default, token.Email);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public void TokenValidityCheckNullUserIdIsInvalid(User user)
|
||||
{
|
||||
var token = new HCaptchaTokenable(user)
|
||||
[Fact]
|
||||
public void TokenWithNullUserIsInvalid()
|
||||
{
|
||||
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
|
||||
};
|
||||
var token = new HCaptchaTokenable(null)
|
||||
{
|
||||
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
|
||||
};
|
||||
|
||||
Assert.False(token.TokenIsValid(null));
|
||||
}
|
||||
Assert.False(token.Valid);
|
||||
}
|
||||
|
||||
[Theory, AutoData]
|
||||
public void CanUpdateExpirationToNonStandard(User user)
|
||||
{
|
||||
var token = new HCaptchaTokenable(user)
|
||||
[Theory, BitAutoData]
|
||||
public void TokenValidityCheckNullUserIdIsInvalid(User user)
|
||||
{
|
||||
ExpirationDate = DateTime.MinValue
|
||||
};
|
||||
var token = new HCaptchaTokenable(user)
|
||||
{
|
||||
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
|
||||
};
|
||||
|
||||
Assert.Equal(DateTime.MinValue, token.ExpirationDate, TimeSpan.FromMilliseconds(10));
|
||||
}
|
||||
Assert.False(token.TokenIsValid(null));
|
||||
}
|
||||
|
||||
[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)
|
||||
[Theory, AutoData]
|
||||
public void CanUpdateExpirationToNonStandard(User user)
|
||||
{
|
||||
ExpirationDate = expectedDateTime
|
||||
};
|
||||
var token = new HCaptchaTokenable(user)
|
||||
{
|
||||
ExpirationDate = DateTime.MinValue
|
||||
};
|
||||
|
||||
var result = Tokenable.FromToken<HCaptchaTokenable>(token.ToToken());
|
||||
Assert.Equal(DateTime.MinValue, token.ExpirationDate, TimeSpan.FromMilliseconds(10));
|
||||
}
|
||||
|
||||
Assert.Equal(expectedDateTime, result.ExpirationDate, TimeSpan.FromMilliseconds(10));
|
||||
}
|
||||
|
||||
[Theory, AutoData]
|
||||
public void IsInvalidIfIdentifierIsWrong(User user)
|
||||
{
|
||||
var token = new HCaptchaTokenable(user)
|
||||
[Theory, AutoData]
|
||||
public void SetsDataFromUser(User user)
|
||||
{
|
||||
Identifier = "not correct"
|
||||
};
|
||||
var token = new HCaptchaTokenable(user);
|
||||
|
||||
Assert.False(token.Valid);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,152 +4,153 @@ using Bit.Core.Models.Business.Tokenables;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.Models.Business.Tokenables;
|
||||
|
||||
public class OrganizationSponsorshipOfferTokenableTests
|
||||
namespace Bit.Core.Test.Models.Business.Tokenables
|
||||
{
|
||||
public static IEnumerable<object[]> PlanSponsorshipTypes() => Enum.GetValues<PlanSponsorshipType>().Select(x => new object[] { x });
|
||||
|
||||
[Fact]
|
||||
public void IsInvalidIfIdentifierIsWrong()
|
||||
public class OrganizationSponsorshipOfferTokenableTests
|
||||
{
|
||||
var token = new OrganizationSponsorshipOfferTokenable()
|
||||
public static IEnumerable<object[]> PlanSponsorshipTypes() => Enum.GetValues<PlanSponsorshipType>().Select(x => new object[] { x });
|
||||
|
||||
[Fact]
|
||||
public void IsInvalidIfIdentifierIsWrong()
|
||||
{
|
||||
Email = "email",
|
||||
Id = Guid.NewGuid(),
|
||||
Identifier = "not correct",
|
||||
SponsorshipType = PlanSponsorshipType.FamiliesForEnterprise,
|
||||
};
|
||||
var token = new OrganizationSponsorshipOfferTokenable()
|
||||
{
|
||||
Email = "email",
|
||||
Id = Guid.NewGuid(),
|
||||
Identifier = "not correct",
|
||||
SponsorshipType = PlanSponsorshipType.FamiliesForEnterprise,
|
||||
};
|
||||
|
||||
Assert.False(token.Valid);
|
||||
}
|
||||
Assert.False(token.Valid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsInvalidIfIdIsDefault()
|
||||
{
|
||||
var token = new OrganizationSponsorshipOfferTokenable()
|
||||
[Fact]
|
||||
public void IsInvalidIfIdIsDefault()
|
||||
{
|
||||
Email = "email",
|
||||
Id = default,
|
||||
SponsorshipType = PlanSponsorshipType.FamiliesForEnterprise,
|
||||
};
|
||||
var token = new OrganizationSponsorshipOfferTokenable()
|
||||
{
|
||||
Email = "email",
|
||||
Id = default,
|
||||
SponsorshipType = PlanSponsorshipType.FamiliesForEnterprise,
|
||||
};
|
||||
|
||||
Assert.False(token.Valid);
|
||||
}
|
||||
Assert.False(token.Valid);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void IsInvalidIfEmailIsEmpty()
|
||||
{
|
||||
var token = new OrganizationSponsorshipOfferTokenable()
|
||||
[Fact]
|
||||
public void IsInvalidIfEmailIsEmpty()
|
||||
{
|
||||
Email = "",
|
||||
Id = Guid.NewGuid(),
|
||||
SponsorshipType = PlanSponsorshipType.FamiliesForEnterprise,
|
||||
};
|
||||
var token = new OrganizationSponsorshipOfferTokenable()
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,84 +5,85 @@ using Bit.Core.Tokens;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.Models.Business.Tokenables;
|
||||
|
||||
public class SsoTokenableTests
|
||||
namespace Bit.Core.Test.Models.Business.Tokenables
|
||||
{
|
||||
[Fact]
|
||||
public void CanHandleNullOrganization()
|
||||
public class SsoTokenableTests
|
||||
{
|
||||
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)
|
||||
[Fact]
|
||||
public void CanHandleNullOrganization()
|
||||
{
|
||||
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
|
||||
};
|
||||
var token = new SsoTokenable(null, default);
|
||||
|
||||
Assert.False(token.Valid);
|
||||
}
|
||||
Assert.Equal(default, token.OrganizationId);
|
||||
Assert.Equal(default, token.DomainHint);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public void TokenValidityCheckNullOrganizationIsInvalid(Organization organization)
|
||||
{
|
||||
var token = new SsoTokenable(organization, 500)
|
||||
[Fact]
|
||||
public void TokenWithNullOrganizationIsInvalid()
|
||||
{
|
||||
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
|
||||
};
|
||||
var token = new SsoTokenable(null, 500)
|
||||
{
|
||||
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
|
||||
};
|
||||
|
||||
Assert.False(token.TokenIsValid(null));
|
||||
}
|
||||
Assert.False(token.Valid);
|
||||
}
|
||||
|
||||
[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)
|
||||
[Theory, BitAutoData]
|
||||
public void TokenValidityCheckNullOrganizationIsInvalid(Organization organization)
|
||||
{
|
||||
ExpirationDate = expectedDateTime
|
||||
};
|
||||
var token = new SsoTokenable(organization, 500)
|
||||
{
|
||||
ExpirationDate = DateTime.UtcNow + TimeSpan.FromDays(1)
|
||||
};
|
||||
|
||||
var result = Tokenable.FromToken<HCaptchaTokenable>(token.ToToken());
|
||||
Assert.False(token.TokenIsValid(null));
|
||||
}
|
||||
|
||||
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)
|
||||
[Theory, AutoData]
|
||||
public void SetsDataFromOrganization(Organization organization)
|
||||
{
|
||||
ExpirationDate = expectedDateTime
|
||||
};
|
||||
var token = new SsoTokenable(organization, default);
|
||||
|
||||
var result = token.TokenIsValid(organization);
|
||||
Assert.Equal(organization.Id, token.OrganizationId);
|
||||
Assert.Equal(organization.Identifier, token.DomainHint);
|
||||
}
|
||||
|
||||
Assert.False(result);
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user