public void CanRoundtripToken_TamperedTokenIsInvalid() { using (var keyMan = new KeyMan(TestConfig.ValidKey)) { var token = keyMan.Encode(new Dictionary <string, string> { { "username", "joe" } }); var tamperedToken = TamperSomehow(token); Console.WriteLine($@"Token: {token} TAMPERED token: {tamperedToken} "); var decodingResult = keyMan.Decode(tamperedToken); Assert.That(decodingResult.IsValid, Is.False); } }
public void CanDetermineWhetherTokenIsExpired() { var expirationTimeInThePast = DateTimeOffset.Now.AddMinutes(-2).ToString("O"); var properties = new Dictionary <string, string> { { KeyMan.Properties.ExpirationTime, expirationTimeInThePast } }; var token = _keyMan.Encode(properties); var result = _keyMan.Decode(token); Assert.That(result.IsValid, Is.False); Assert.That(result.Details.HasValidSignature, Is.True); Assert.That(result.Details.IsExpired, Is.True); }
void CheckSize(int numberOfProperties) { var properties = Enumerable.Range(0, numberOfProperties) .Select(i => $"key-{i}") .ToDictionary(a => a, a => "just a value"); var token = _keyMan.Encode(properties); Console.WriteLine($"{numberOfProperties.ToString().PadLeft(5)}: {token.Length} - {token}"); }
public void AutomaticallyAssignsIssuedAt() { var token = _keyMan.Encode(new Dictionary <string, string>()); var result = _keyMan.Decode(token); Assert.That(result.Properties.ContainsKey(KeyMan.Properties.IssuedAt)); var issuedAt = DateTimeOffset.Parse(result.Properties[KeyMan.Properties.IssuedAt]); Assert.That(issuedAt, Is.GreaterThan(DateTimeOffset.Now.AddSeconds(-2))); Assert.That(issuedAt, Is.LessThan(DateTimeOffset.Now.AddSeconds(2))); }
public void CanRoundtripToken() { using (var keyMan = new KeyMan(TestConfig.ValidKey)) { var token = keyMan.Encode(new Dictionary <string, string> { { "username", "joe" } }); var decodingResult = keyMan.Decode(token); Assert.That(decodingResult.IsValid, Is.True); var decodedProperties = decodingResult.Properties; Assert.That(decodedProperties.ContainsKey("username")); Assert.That(decodedProperties["username"], Is.EqualTo("joe")); } }