Exemplo n.º 1
0
        public void Read_Success()
        {
            var tokenString = GenerateRS256Token();

            var mockSettings = new Mock <IOptions <SecuritySettings> >();

            mockSettings.Setup(m => m.Value).Returns(() => new SecuritySettings());

            var service = new JwtTokenService(new List <ISecurityService>(), mockSettings.Object);
            var result  = service.Read(tokenString);

            var token = result;

            Assert.IsNotNull(token);
            Assert.AreEqual(token.SignatureAlgorithm, "RS256");
            Assert.AreEqual(token.Audiences.FirstOrDefault(), _audience);
            Assert.AreEqual(token.Issuer, _issuer);
            Assert.AreEqual(token.Subject, _email);
            Assert.IsTrue(token.Claims.Any(c => c.Type == "email" && c.Value == _email));
        }
Exemplo n.º 2
0
        public void Read_TokenWithoutAudience_ReturnsError()
        {
            var settings = GetRS256TestSettings();

            settings.Audience = null;
            var tokenString = GenerateRS256Token(settings);

            var mockSettings = new Mock <IOptions <SecuritySettings> >();

            mockSettings.Setup(m => m.Value).Returns(() => new SecuritySettings());

            try
            {
                var service = new JwtTokenService(new List <ISecurityService> {
                    new Rs256SecurityService(mockSettings.Object)
                }, mockSettings.Object);
                var result = service.Read(tokenString);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.AreEqual(ex.Message, "Token does not contain audience");
            }
        }