public void VerifyFailsForIllegalInput(string hashedApiKey) { // Arrange var apiKey = ApiKeyV4.Create(); // Act & Assert Assert.False(apiKey.Verify(hashedApiKey)); }
public void VerifyFailsOnIncorrectHashedKey() { // Arrange var apiKey = ApiKeyV4.Create(); var hashedApiKey = "oy2iuvoucviouojnrbzaAEAAAAABAAACOEAAAAABAMHUIIUXSFAIOTEAFWF3K2E7L6YRUDOZDPHKSRX3YEOFUWPCID325EZH5JXBBGBMYBECT4KCGMWOQQ======"; // Act & Assert Assert.False(apiKey.Verify(hashedApiKey)); }
public void VerifySucceedsOnKeysCreatedByCreate() { // Arrange var apiKey = ApiKeyV4.Create(); ApiKeyV4.TryParse(apiKey.PlaintextApiKey, out var parsedApiKey); // Act & Assert Assert.True(parsedApiKey.Verify(apiKey.HashedApiKey)); }
public Credential CreateApiKey(TimeSpan?expiration, out string plaintextApiKey) { var apiKey = ApiKeyV4.Create(); plaintextApiKey = apiKey.PlaintextApiKey; return(new Credential( CredentialTypes.ApiKey.V4, apiKey.HashedApiKey, expiration: expiration)); }
public void CreatesAValidApiKey() { // Act var apiKey = ApiKeyV4.Create(); // Assert Assert.NotNull(apiKey); Assert.NotNull(apiKey.HashedApiKey); Assert.Equal(ApiKeyV4.IdAndPasswordHashedLength, apiKey.HashedApiKey.Length); Assert.NotNull(apiKey.PlaintextApiKey); Assert.Equal(ApiKeyV4.IdAndPasswordLength, apiKey.PlaintextApiKey.Length); Assert.Equal(apiKey.PlaintextApiKey.ToLower(), apiKey.PlaintextApiKey); Assert.NotNull(apiKey.IdPart); Assert.Equal(ApiKeyV4.IdPartBase32Length, apiKey.IdPart.Length); Assert.NotNull(apiKey.PasswordPart); Assert.Equal(ApiKeyV4.IdAndPasswordLength - ApiKeyV4.IdPartBase32Length, apiKey.PasswordPart.Length); }