mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 23:52:50 -05:00
Turn on file scoped namespaces (#2225)
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user