Пример #1
0
        public async Task ImportedJwt_Should_BeTheSameAsOrigin()
        {
            Func <TokenContext, Task <string> > obtainToken = async(TokenContext tokenContext) =>
            {
                var jwtFromServer = await IntegrationHelper.EmulateServerResponseToBuildTokenRequest(tokenContext);

                return(jwtFromServer);
            };
            var callBackProvider = new CallbackJwtProvider(obtainToken);
            var context          = new TokenContext(faker.Random.AlphaNumeric(20), "some_operation");
            var token            = await callBackProvider.GetTokenAsync(context);

            var importedJwt = new Jwt(token.ToString());

            Assert.AreEqual(importedJwt.ToString(), token.ToString());
            Assert.AreEqual(importedJwt.BodyContent.Identity, ((Jwt)token).BodyContent.Identity);
            Assert.AreEqual(importedJwt.BodyContent.AdditionalData, ((Jwt)token).BodyContent.AdditionalData);
            Assert.AreEqual(importedJwt.BodyContent.AppId, ((Jwt)token).BodyContent.AppId);
            Assert.AreEqual(importedJwt.BodyContent.ExpiresAt, ((Jwt)token).BodyContent.ExpiresAt);
            Assert.AreEqual(importedJwt.BodyContent.IssuedAt, ((Jwt)token).BodyContent.IssuedAt);
            Assert.AreEqual(importedJwt.BodyContent.Subject, ((Jwt)token).BodyContent.Subject);
            Assert.AreEqual(importedJwt.BodyContent.Issuer, ((Jwt)token).BodyContent.Issuer);


            Assert.AreEqual(importedJwt.HeaderContent.Algorithm, ((Jwt)token).HeaderContent.Algorithm);
            Assert.AreEqual(importedJwt.HeaderContent.KeyId, ((Jwt)token).HeaderContent.KeyId);
            Assert.AreEqual(importedJwt.HeaderContent.ContentType, ((Jwt)token).HeaderContent.ContentType);
            Assert.AreEqual(importedJwt.HeaderContent.Type, ((Jwt)token).HeaderContent.Type);

            Assert.IsTrue(importedJwt.SignatureData.SequenceEqual(((Jwt)token).SignatureData));
        }
Пример #2
0
        public void GetTokenAsync_Should_RaiseException_IfObtainTokenFuncReturnsInvalidString()
        {
            Func <TokenContext, Task <string> > obtainToken = async(TokenContext tokenContext) =>
            {
                var jwtFromServer = await Task <string> .Factory.StartNew(() =>
                {
                    return(faker.Random.AlphaNumeric(30));
                });;
                return(jwtFromServer);
            };
            var callBackProvider = new CallbackJwtProvider(obtainToken);
            var context          = new TokenContext(faker.Random.AlphaNumeric(20), "some_operation");

            Assert.ThrowsAsync <ArgumentException>(
                async() => await callBackProvider.GetTokenAsync(context));
        }
Пример #3
0
        public async Task GetTokenAsync_Should_ReturnNewTokenEachTime_IfUserHasNotImplementedCashInObtainTokenFuncAsync()
        {
            Func <TokenContext, Task <string> > obtainToken = async(TokenContext tokenContext) =>
            {
                var jwtFromServer = await IntegrationHelper.EmulateServerResponseToBuildTokenRequest(tokenContext);

                return(jwtFromServer);
            };
            var callBackProvider = new CallbackJwtProvider(obtainToken);
            var context          = new TokenContext(faker.Random.AlphaNumeric(20), "some_operation");
            var token1           = await callBackProvider.GetTokenAsync(context);

            var token2 = await callBackProvider.GetTokenAsync(context);

            Assert.AreNotEqual(token1, token2);
        }