Example #1
0
        public void EmptyOriginalUrl()
        {
            var linkShortenerValidator = _serviceProvider.GetService <ILinkShortenerValidator>();

            var(statusCode, errorResult) = linkShortenerValidator.PayloadValidator(accessToken, string.Empty);
            Assert.True(statusCode != StatusCodes.Status200OK);
        }
        public void GenerateShortUrl()
        {
            var linkShortenService = _serviceProvider.GetService <ILinkShortenService>();
            var token = linkShortenService.GenerateShortUrl();

            Assert.NotEmpty(token);
        }
Example #3
0
        public void GenerateAccessToekn()
        {
            var    jwtTokenHandler = _serviceProvider.GetService <IJwtTokenHandler>();
            string token           = jwtTokenHandler.GenerateJwtSecurityToken("Hasan");

            Assert.NotEmpty(token);
        }
        public void UnauthorizeLinkShortener()
        {
            ViewResult result = new ViewResult();

            try
            {
                var linkShortenerValidator = _serviceProvider.GetService <ILinkShortenerValidator>();
                var linkShortenManager     = _serviceProvider.GetService <ILinkShortenManager>();
                var logger = _serviceProvider.GetService <ILogger <LinkShortenerController> >();

                var             controller = new LinkShortenerController(linkShortenerValidator, linkShortenManager, logger);
                ShortUrlRequest model      = new ShortUrlRequest
                {
                    OriginalUrl = "https://eatigo.com/th/bangkok/en"
                };

                var request = new HttpRequestMessage();
                request.Headers.Add("Authorization", "");
                result = (ViewResult)controller.LinkShortener(model);
                Assert.NotNull(result);
            }
            catch
            {
                Assert.True(result.StatusCode == null);
            }
        }
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            var authToken             = actionContext.ControllerContext.Request.GetCurrentBearerAuthrorizationToken();
            var authenticationService = DependencyResolverHelper.GetService <IAuthenticationService>();
            var token = authenticationService.GetByAccessToken(authToken);

            if (token != null)
            {
                if (actionContext.ControllerContext.Controller.GetType().IsSubclassOf(typeof(BaseApiController)))
                {
                    if (((BaseApiController)actionContext.ControllerContext.Controller).Token == null && actionContext.ActionDescriptor.ActionName != "Logout")
                    {
                        authenticationService.RefreshToken(token);
                    }
                    ((BaseApiController)actionContext.ControllerContext.Controller).Token = token.Access_token;
                }
                else
                {
                    authenticationService.RefreshToken(token);
                }
            }

            if (SkipAuthorization(actionContext))
            {
                return;
            }

            if (token == null || token.User == null)
            {
                actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized)
                {
                    Content = new StringContent("Unauthorized")
                };
            }
        }
        public void Shorten()
        {
            var linkShortenManager = _serviceProvider.GetService <ILinkShortenManager>();

            ShortUrlRequest model = new ShortUrlRequest()
            {
                OriginalUrl = "https://eatigo.com/th/bangkok/en"
            };
            var response = linkShortenManager.Shorten(model);

            Assert.True(response != null);
        }