Ejemplo n.º 1
0
        public void CanGetCardDetailWithValidJwt()
        {
            if (!Debugger.IsAttached)
            {
                return;
            }

            var service = new CardService();
            var results = service.GetMemberCardUrls("en", 11, 57020);

            var response = WebApiService.GetCardDetail(11, results.Results[0].SecurityToken);

            Assert.IsNotNull(response);
        }
Ejemplo n.º 2
0
        public async Task CannotGetCardDetailWithMismatchedEmployerId()
        {
            //This check can be removed after successfull deployment.
            if (!Debugger.IsAttached)
            {
                return;
            }

            var service   = new CardService();
            var cardToken = JwtService.EncryptPayload(JsonConvert.SerializeObject(new CardToken()
            {
                Expires    = DateTime.UtcNow.AddMinutes(15),
                EmployerId = 11
            }));

            var response = await WebApiService.GetCardDetail(12, cardToken);

            Assert.IsTrue(response.Invalid);
        }
Ejemplo n.º 3
0
        public async Task CannotGetCardDetailWithExpiredJwt()
        {
            if (!Debugger.IsAttached)
            {
                return;
            }

            var service   = new CardService();
            var cardToken = JwtService.EncryptPayload(JsonConvert.SerializeObject(new CardToken()
            {
                Expires    = DateTime.UtcNow.AddMinutes(-2),
                EmployerId = 11
            }));

            Debug.WriteLine(cardToken);
            var response = await WebApiService.GetCardDetail(11, cardToken);

            Assert.IsTrue(response.Expired);
        }
Ejemplo n.º 4
0
        // GET: Card
        public async Task <ActionResult> Index()
        {
            ViewBag.Message      = "Virtual ID Cards";
            Response.ContentType = "image/svg+xml";

            if (null == Request.QueryString["tkn"])
            {
                LogUtil.Log("Missing security token in CardController.",
                            new InvalidOperationException("Security Token is required."));

                return(View());
            }

            var tokenSegments = Request.QueryString["tkn"].Split('|');

            if (tokenSegments.Length != 2)
            {
                LogUtil.Log("Invalid arguments in CardController.",
                            new InvalidOperationException(
                                string.Format("QueryString token expected 2 segments but got {0}.",
                                              tokenSegments.Length)));

                return(View());
            }

            var employerId = int.Parse(tokenSegments[0]);
            var jwt        = tokenSegments[1];

            HandleCampaignSession(employerId);

            var cardDetail = await WebApiService.GetCardDetail(employerId, jwt);

            HelperService.LogAnonEvent(ExperienceEvents.Debug, FormatInfoMessage(cardDetail));

            if (cardDetail.CardTypeId < 1 || cardDetail.CardViewModeId < 1 || string.IsNullOrEmpty(cardDetail.CardTypeFileName))
            {
                cardDetail = await WebApiService.GetCardDetail(employerId, jwt);

                HelperService.LogAnonEvent(ExperienceEvents.Debug,
                                           string.Format("Retry - Card Type ID: {0}  View Mode ID: {1}  File Name: {2}",
                                                         cardDetail.CardTypeId, cardDetail.CardViewModeId, cardDetail.CardTypeFileName));
            }

            if (cardDetail.Expired)
            {
                return(View("Timeout"));
            }

            if (cardDetail.Invalid)
            {
                return(View("InvalidEmployerId"));
            }

            if (cardDetail.CardTypeId < 1 || cardDetail.CardViewModeId < 1 || string.IsNullOrEmpty(cardDetail.CardTypeFileName))
            {
                HelperService.LogAnonEvent(ExperienceEvents.Error, FormatInfoMessage(cardDetail));

                LogUtil.Log(string.Format("Unable to resolve card data for token {0} for employer {1}.",
                                          jwt, employerId),
                            new InvalidOperationException(FormatInfoMessage(cardDetail)));

                return(View());
            }
            ;

            MapViewBag(cardDetail);

            return(View(string.Format("{0}_{1}", cardDetail.CardTypeFileName, ResolveViewMode(cardDetail))));
        }